So, I'm working on this app where a phone call is made using the TelecomManager and I want to turn on the speakerphone programmatically when an event is triggered in the app.
The app is primarily not made for making phone calls etc, but there's a function that makes phone calls in certain events.
This works fine on android versions below android 10 using the following code:
AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_IN_CALL);
am.setSpeakerphoneOn(true);
am.setStreamVolume(AudioManager.STREAM_VOICE_CALL, am.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL), 0);
But this code doesn't seem to work on android 10 and above. One solution is to have the speaker on by default when making the phone call, but I want to be able to toggle the speaker via events in the app.
Does anyone have a solution for this?
Edit: The application is only making a call to a specific number in case of an emergency and is not a phone app. And I'd like to be able to start the speaker without having to make the app into the "Default Phone App".