检查耳机是否插好 [英] Check whether headphones are plugged in

查看:143
本文介绍了检查耳机是否插好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找到一个办法知道在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 +

这篇关于检查耳机是否插好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆