检查耳机是否插好耳机

由网友(失望吧)分享简介:我似乎无法找到一个办法知道在Android上,如果插入耳机,我发现不同的解决方案,但他们似乎总是返回false。这似乎正常工作的唯一事情是一个的BroadcastReceiver ,但是这不是我所需要的:I can't seem to find a way to know on android if the hea...

我似乎无法找到一个办法知道在Android上,如果插入耳机,我发现不同的解决方案,但他们似乎总是返回false。 这似乎正常工作的唯一事情是一个的BroadcastReceiver ,但是这不是我所需要的:

I can't seem to find a way to know on android if the headphones are plugged in. I found various solutions but they always seem to return false. The only thing that seems to work properly is a BroadcastReceiver, but that's not what I need:

我只需要像这样

if(headphones plugged in) {
}

有没有这样的功能?是否需要一些特殊的权限?

Is there such a function? Does it require some special permissions?

推荐答案

您可以使用 AudioManager.isWiredHeadsetOn()因为如果耳机插在检查

You can use AudioManager.isWiredHeadsetOn() for checking if the headset are plugged in.

而你需要 <使用-权限的Andr​​oid:名称=android.permission.MODIFY_AUDIO_SETTINGS/>

可在安卓2.0 +

阅读全文

相关推荐

最新文章