Why does the audio routing change after I switch to another app on an Android device?
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.
Reason
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.
Solution
Perform the following steps in onResume
(an Android API):
- Retrieve the current audio routing of the SDK.
- Call
setEnableSpeakerphone
to reset the audio routing of the SDK.
See the following code sample:
Relevant links
Why can't I answer calls through a Bluetooth device after connecting it to an iOS or Android device