Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
7f7d0f88cd
3 changed files with 50 additions and 2 deletions
|
@ -23,6 +23,7 @@
|
|||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="com.android.vending.BILLING" />
|
||||
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
|
||||
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||
|
|
|
@ -1224,7 +1224,7 @@
|
|||
<string name="auto_zoom_map">Auto zoom map</string>
|
||||
<string name="snap_to_road_descr">Snap position to roads during navigation</string>
|
||||
<string name="snap_to_road">Snap to road</string>
|
||||
<string name="interrupt_music_descr">Interrupt music when making announcement</string>
|
||||
<string name="interrupt_music_descr">Interrupt music when making announcement (also as simulated phone calls to car BT stereos)</string>
|
||||
<string name="interrupt_music">Interrupt music</string>
|
||||
<string name="osmand_play_title_30_chars">OsmAnd Maps & Navigation</string>
|
||||
<string name="osmand_short_description_80_chars">Global Mobile Map Viewing & Navigation for Offline and Online OSM Maps</string>
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.content.Context;
|
|||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
|
||||
import android.media.AudioManager;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.StateChangedListener;
|
||||
|
@ -279,6 +281,13 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
|
|||
if (mAudioFocusHelper != null) {
|
||||
mAudioFocusHelper.requestFocus(ctx, streamType);
|
||||
}
|
||||
if (ctx.getSettings().INTERRUPT_MUSIC.get()) {
|
||||
// TODO: Delay the prompts a bit until connection is established
|
||||
startBtSco(ctx);
|
||||
//if (btScoStatus == false) {
|
||||
// Toast.makeText(this, R.string."BT connection error: ", Toast.LENGTH_SHORT).show();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
private AudioFocusHelper getAudioFocus() {
|
||||
|
@ -292,10 +301,48 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
|
|||
|
||||
protected void abandonAudioFocus() {
|
||||
log.debug("abandonAudioFocus");
|
||||
if (ctx.getSettings().INTERRUPT_MUSIC.get()) {
|
||||
stopBtSco(ctx);
|
||||
}
|
||||
if (mAudioFocusHelper != null) {
|
||||
mAudioFocusHelper.abandonFocus(ctx, streamType);
|
||||
mAudioFocusHelper = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean btScoStatus = false;
|
||||
|
||||
private boolean startBtSco(Context context) {
|
||||
// Establish a low quality Synchronous Connection-Oriented link to BT to e.g. interrupt a car stereo
|
||||
// http://stackoverflow.com/questions/2144694/routing-audio-to-bluetooth-headset-non-a2dp-on-android
|
||||
try {
|
||||
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
if (mAudioManager == null) {
|
||||
return false;
|
||||
}
|
||||
mAudioManager.setMode(0);
|
||||
mAudioManager.setBluetoothScoOn(true);
|
||||
mAudioManager.startBluetoothSco();
|
||||
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
||||
btScoStatus = true;
|
||||
} catch (Exception e) {
|
||||
System.out.println("Exception starting BT SCO " + e.getMessage() );
|
||||
btScoStatus = false;
|
||||
return false;
|
||||
}
|
||||
return btScoStatus;
|
||||
}
|
||||
|
||||
private boolean stopBtSco(Context context) {
|
||||
btScoStatus = false;
|
||||
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
if (mAudioManager == null) {
|
||||
return false;
|
||||
}
|
||||
mAudioManager.setBluetoothScoOn(false);
|
||||
mAudioManager.stopBluetoothSco();
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue