motis10 motis10 - 3 years ago 245
Android Question

Audiomanager Speaker not working

I'm trying to enable the speaker while im in call:

final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setSpeakerphoneOn(true);


I tried to check after the
setSpeakerphoneOn()
the audiomanager and get that the speaker is still not on by ask
isSpeakerphoneOn()


audioManager.isSpeakerphoneOn();


In my log i can see some errors that i can't understand:

E/AudioManager: Don't setBluetoothScoOn-PackageName: com.myapp.app on = false
E/AudioManager: Don't setSpeakerphoneOn-PackageName: com.myapp.app on = true


I can't find anything about this error in the forum.
Didn't work on devices: ZTE Z981, Huawei p9,

P.S:
Tried: Android : Force audio routing

And
android.permission.MODIFY_AUDIO_SETTINGS
is granted

Answer Source

I found that setMode() (the current mode) before setSpeakerphoneOn() fix the error on the logcat:

AudioManager audioManager = (AudioManager)getApplicationContext().getSystemService(Context.AUDIO_SERVICE); 
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download