setSpeakerphoneOn does not work on android 14
Hello everyone, after updating my phone to android 14, this function stopped working: setSpeakerphoneOn(..) I will be very grateful for any information regarding this problem.
- "react-native": "0.71.12",
- "react-native-incall-manager": "^4.2.0",
- "react-native-callkeep": "^4.3.12",
- "react-native-webrtc": "111.0.1",
my current solution:
I made a patch that works for me.
Remove this:
https://github.com/react-native-webrtc/react-native-incall-manager/blob/626813946eb2a3abc2a2bdfca44085c999861327/android/src/main/java/com/zxcpoiu/incallmanager/InCallManagerModule.java#L862-L869
Add this:
@ReactMethod
public void setSpeakerphoneOn(final boolean enable) {
// Request audio focus to ensure the app can control audio output
requestAudioFocus();
// Set the appropriate audio mode based on whether the speakerphone is being enabled or disabled
audioManager.setMode(enable ? AudioManager.MODE_IN_COMMUNICATION : AudioManager.MODE_NORMAL);
// Check if the device is running Android 12 (API level 31) or higher
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { // Android 12 and above
if (enable) {
// Retrieve a list of all available output audio devices
AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
// Iterate through the list to find the built-in speaker
for (AudioDeviceInfo device : devices) {
if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
// Set the communication device to the built-in speaker
audioManager.setCommunicationDevice(device);
break; // Exit the loop once the speaker is set
}
}
} else {
// Clear the communication device to revert to the default audio routing
audioManager.clearCommunicationDevice();
}
} else {
// For Android versions below API level 31, use the traditional method to toggle the speakerphone
audioManager.setSpeakerphoneOn(enable);
}
}
@xKRUTOIx Could you submit a PR please
@santhoshvai I'm not confident about this patch, so I'd rather not to submit a PR and just leave it here as it is
issue is still present in and the patch worked fine.
android 15 expo: 52 react native: 0.76
I am using a Samsung S24 Ultra with the latest Android version. While talking, the screen shuts off after 30 seconds. This is a standard screen saver setting. When the screen shuts off, the speaker stops playing the audio from the call. I thought the call got disconnected, so I switched on the screen again, and then the audio was back.