I need to force audio through speakers because there's a headphone jack tip stuck in my connector which is most likely not coming out. On android 8.0 I used an app called Audio Router to route the audio to speakers and it worked fine but after I upgraded to pie it doesn't work anymore. I also tried all kinds of different apps one of which made the headphones connected indicator disappear but the audio didn't play through speakers. I tried finding some code to do this and I've found this:
public void speaker(View v){
AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setSpeakerphoneOn(true);
}
Nothing happens after calling the function. I gave the app this permission:
<uses-permission android:name="android.permission.MODIFY_AUDIO"/>
Anybody has any idea what could possibly work ? Thanks for the answer in advance.