Droid Incredible Headphones Detection

こ雲淡風輕ζ 提交于 2019-12-13 03:51:04

问题


I'm developing an Android application for the Droid Incredible. When I plug in my headphones, an icon appears on the status bar, so I presume the phone must know headphones are present.

My code produces beeps in response to various user inputs, but I discovered today that's a REALLY BAD idea when the user is wearing headphones. Ow.

Does anybody have suggestions for how I can detect the presence of headphones programmatically, in Android??

Thanks, R.


回答1:


I found the AudioManager class on the developer site, it looks to have a helpful method for this, but I have not tested it:

AudioManager am = getSystemService(Context.AUDIO_SERVICE);
bool headsetEnabled = am.isWiredHeadsetOn();



回答2:


You find out when it changes with http://developer.android.com/reference/android/content/Intent.html#ACTION_HEADSET_PLUG

I'm not sure if it's possible to find out if your app is started after the headphones are plugged in/plugged out.



来源:https://stackoverflow.com/questions/4186615/droid-incredible-headphones-detection

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