Audiomanager Speaker not working

ε祈祈猫儿з 提交于 2019-12-07 11:52:56

问题


I'm trying to enable the speaker while I am in a 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 asking 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, I already tried this, and android.permission.MODIFY_AUDIO_SETTINGS is granted.


回答1:


Hi read android developer article

https://developer.android.com/reference/android/media/AudioManager.html

explain it clearly

you need to set Permission: MODIFY_AUDIO_SETTINGS in manifest

add this line in manifest

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />



回答2:


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

AudioManager audioManager = (AudioManager)getApplicationContext().getSystemService(Context.AUDIO_SERVICE); 
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);



回答3:


1.setSpeakerphoneOn() is only working on setMode(AudioManager.MDOE_IN_CALL);



来源:https://stackoverflow.com/questions/43212297/audiomanager-speaker-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!