本文介绍了什么代码可以禁用android(4.4)设备的耳机插孔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试构建一个可以在我的Android 4.4设备上启用或禁用耳机插孔的应用程序.一旦禁用,任何人都将无法控制或激活它,甚至无法进行呼叫.我可以为此安装设备.
Im trying to build an app that can enable or disable the headphone jack on my Android 4.4 device . Once disabled nothing should be able to take control or activate it, even calling. I can root the device for this.
任何帮助将不胜感激.
推荐答案
如此处所述:
AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_IN_CALL);
am.setSpeakerphoneOn(false);
然后通过AudioManager.STREAM_SYSTEM流播放声音.
And then play the sound through the AudioManager.STREAM_SYSTEM stream.
当声音播放完毕后,请确保将音频管理器恢复到之前的状态,否则它将留在扬声器上.
When the sound's finished playing be sure to return the audio manager to its previous state or it'll stay on loudspeaker.
这篇关于什么代码可以禁用android(4.4)设备的耳机插孔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!