When using an app integrated with an Agora SDK (an "SDK app") for real-time communication on an Android device, if you switch to another app that has audio input and/or output and return to the SDK app, the audio routing of the SDK changes.
For example, during a video call in the SDK app through the speaker, you answer a voice call with the earpiece in another app. When you end the voice call and return to the SDK app, the video call's audio is now routed to the earpiece.
When switching from the SDK app to another app on Android devices, the latter may change the original audio routing of the SDK. The SDK does not have permission to detect such changes and cannot determine whether you have switched back to using the SDK app. Therefore, when the you return to the SDK app, the audio routing set by the other app remains in use.
Perform the following steps in onResume
(an Android API):
setEnableSpeakerphone
to reset the audio routing of the SDK.See the following code sample:
@Override
protected void onResume() {
super.onResume();
AudioManager am = getAudioManager();
if (am.isSpeakerphoneOn()) {
Log.d("LOG:", "AUDIO_ROUTE_SPEAKERPHONE");
} else if (am.isBluetoothScoOn() || am.isBluetoothA2dpOn()) {
Log.d("LOG:", "AUDIO_ROUTE_HEADSETBLUETOOTH");
} else if (am.isWiredHeadsetOn()) {
Log.d("LOG:", "AUDIO_ROUTE_HEADSET");
} else {
Log.d("LOG:", "AUDIO_ROUTE_EARPIECE");
// Call setEnableSpeakerphone here to route the audio output to the speaker or earpiece
}
}
public AudioManager getAudioManager() {
Context context = this.getApplicationContext();
if (context == null) {
return null;
}
return (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}
Why can't I answer calls through a Bluetooth device after connecting it to an iOS or Android device