How can I determine whether a headset is plugged into an Android device or not?
相关问题
- How can I create this custom Bottom Navigation on
- Can we recover audio from MFCC coefficients?
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Is there a way to play audio on a mobile browser w
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
AudioManager.isWiredHeadsetOn()
always returnfalse
because it requires user-permissionMODIFY_AUDIO_SETTINGS
.I spent several days while found answer. There are no info about this in official documentation. And this
bug
already registered inBugTracker
.This should help you : http://developer.android.com/reference/android/content/Intent.html#ACTION_HEADSET_PLUG
When you say "headset", do you mean "wired headset"? If so, there's an intent to detect whether or not one is being plugged or unplugged:
ACTION_HEADSET_PLUG
.To check the status, you can use
AudioManager.isWiredHeadsetOn()
, although that may return false if there is also a bluetooth headset, and audio is routed to that instead.You can use the broadcast receiver.
So, You might write this code in "AndroidManifest.xml"
But, This doesn't work. When OS send this "HEADSET_PLUG" intent, OS set the flag "Intent.FLAG_RECEIVER_REGISTERED_ONLY" So, You should write the code like below in Activity or Service class instead of "AndroidManifest" things.
I hope this article help you. Bye!
This is the part of "HeadsetObserver.java", Android SDK Source.