AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
if(isOn){
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setMode(AudioManager.MODE_NORMAL);
}else{
//Seems that this back and forth somehow resets the audio channel
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setMode(AudioManager.MODE_IN_CALL);
}
audioManager.setSpeakerphoneOn(isOn);
P.S:我在清单中给了这个许可:
android.permission.MODIFY_AUDIO_SETTINGS
本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/ruhezaiandroid-4-0zhongyibianchengfangshidakai-guanbiyangsheng.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:9 月 19, 2019 at 02:08 上午