Open KolissnikBogdan opened 6 months ago
my current solution:
I made a patch that works for me.
Remove this:
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);
}
}
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.