Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setSpeakerphoneOn does not work on android 14 #242

Open
KolissnikBogdan opened this issue Apr 16, 2024 · 4 comments
Open

setSpeakerphoneOn does not work on android 14 #242

KolissnikBogdan opened this issue Apr 16, 2024 · 4 comments

Comments

@KolissnikBogdan
Copy link

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
Copy link
Author

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

@xKRUTOIx
Copy link

I made a patch that works for me.

Remove this:

@ReactMethod
public void setSpeakerphoneOn(final boolean enable) {
if (enable != audioManager.isSpeakerphoneOn()) {
Log.d(TAG, "setSpeakerphoneOn(): " + enable);
audioManager.setMode(defaultAudioMode);
audioManager.setSpeakerphoneOn(enable);
}
}

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

@santhoshvai
Copy link
Contributor

@xKRUTOIx Could you submit a PR please

@xKRUTOIx
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants