react-native-incall-manager icon indicating copy to clipboard operation
react-native-incall-manager copied to clipboard

setSpeakerphoneOn does not work on android 14

Open KolissnikBogdan opened this issue 1 year ago • 6 comments

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",

KolissnikBogdan avatar Apr 16 '24 14:04 KolissnikBogdan

my current solution: Снимок экрана 2024-06-26 в 17 02 21

KolissnikBogdan avatar Jun 26 '24 14:06 KolissnikBogdan

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);
        }
    }

abikbulatov avatar Sep 13 '24 09:09 abikbulatov

@xKRUTOIx Could you submit a PR please

santhoshvai avatar Nov 18 '24 14:11 santhoshvai

@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

abikbulatov avatar Nov 18 '24 15:11 abikbulatov

issue is still present in and the patch worked fine.

android 15 expo: 52 react native: 0.76

saivasudatta avatar Apr 22 '25 13:04 saivasudatta

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.

HirenAVyas avatar May 23 '25 12:05 HirenAVyas