Activate BT SCO only for STREAM_VOICE_CALL as per Android documentation

This commit is contained in:
sonora 2016-07-02 19:09:16 +02:00
parent ec62e6c670
commit 0d9609f198
2 changed files with 12 additions and 14 deletions

View file

@ -1226,7 +1226,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 (also as simulated phone calls to car BT stereos)</string>
<string name="interrupt_music_descr">Interrupt music when making announcement</string>
<string name="interrupt_music">Interrupt music</string>
<string name="osmand_play_title_30_chars">OsmAnd Maps &amp; Navigation</string>
<string name="osmand_short_description_80_chars">Global Mobile Map Viewing &amp; Navigation for Offline and Online OSM Maps</string>
@ -1817,7 +1817,7 @@ If you need help with OsmAnd application, please contact our support team: suppo
<string name="switch_to_vector_map_to_see">Offline vector map present for this location. \n\t\n\tTo use activate \'Menu\' → \'Configure map\' → \'Map Source…\' → \'Offline vector maps\'.</string>
<string name="choose_audio_stream">Voice guidance output</string>
<string name="choose_audio_stream_descr">Choose speaker to play voice guidance (system-dependent)</string>
<string name="voice_stream_voice_call">Phone call audio</string>
<string name="voice_stream_voice_call">Phone call audio (also tries to interrupt car BT stereos)</string>
<string name="voice_stream_notification">Notification audio</string>
<string name="voice_stream_music">Media/music audio</string>
<string name="warning_tile_layer_not_downloadable">Application cannot download map layer %1$s, please try to reinstall it.</string>

View file

@ -281,12 +281,10 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
if (mAudioFocusHelper != null) {
mAudioFocusHelper.requestFocus(ctx, streamType);
}
if (ctx.getSettings().INTERRUPT_MUSIC.get()) {
// If AudioManager.STREAM_VOICE_CALL try using BT SCO:
if (ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) {
// 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();
//}
startBtSco();
}
}
@ -301,8 +299,8 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
protected void abandonAudioFocus() {
log.debug("abandonAudioFocus");
if (ctx.getSettings().INTERRUPT_MUSIC.get() || (btScoStatus == true)) {
stopBtSco(ctx);
if ((ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) || (btScoStatus == true)) {
stopBtSco();
}
if (mAudioFocusHelper != null) {
mAudioFocusHelper.abandonFocus(ctx, streamType);
@ -312,12 +310,12 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
private static boolean btScoStatus = false;
private boolean startBtSco(Context context) {
private boolean startBtSco() {
// 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) {
AudioManager mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
if (mAudioManager == null || !mAudioManager.isBluetoothScoAvailableOffCall()) {
return false;
}
mAudioManager.setMode(0);
@ -333,9 +331,9 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
return btScoStatus;
}
private boolean stopBtSco(Context context) {
private boolean stopBtSco() {
btScoStatus = false;
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
AudioManager mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
if (mAudioManager == null) {
return false;
}