安卓。检测耳机以及耳麦?[英] Android: Detect headphones as well as headset?

本文是小编为大家收集整理的关于安卓。检测耳机以及耳麦?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我已经在audiomanager中使用了isWiredHeadsetOn()方法,只要我使用手机附带的耳机,就会使用audiomanager.如果我在没有内置麦克风的情况下使用一对耳机,isWiredHeadsetOn()返回false,我认为足够公平,但不是我想要的!有没有办法检测耳机和耳机?

推荐答案

最好的方法是使用广播接收器for action_headet_plug.然后在耳机连接或断开连接时获取事件.

我认为它应该为蓝牙设备工作,但我不100%肯定是诚实的.

本文地址:https://www.itbaoku.cn/post/102405.html

问题描述

I've got my code working using the isWiredHeadsetOn() method in AudioManager as long as I use the headset that came with my phone. If I use a pair of headphones without an inbuilt microphone, isWiredHeadsetOn() returns false, which I suppose is fair enough, but isn't what I want! Is there a way to detect both headsets and headphones?

推荐答案

The best way is to use a broadcast receiver for ACTION_HEADSET_PLUG. Then you get events when the headset is connected or disconnected.

I think it should work for bluetooth devices but am not 100% sure to be honest.