有一种方法可以判断有线耳机是否已连接到电话

问题描述

| 是否可以通过编程的方式判断有线耳机(不是蓝牙)是否已连接到电话? 谢谢。     

解决方法

您可以判断AudioManager.isWiredHeadsetOn()是否正在使用有线耳机。 您还可以收听广播操作ACTION_HEADSET_PLUG 希望这可以帮助, 菲尔·莱洛     ,尝试使用BroadcastReceiver,让它侦听“ 0”意图动作。     ,您可以使用以下代码进行操作:
Intent intent = registerReceiver(myHandler,new IntentFilter(Intent.ACTION_HEADSET_PLUG)); 
if (intent != null) 
            myHandler.onReceive(this,intent); 
我希望这有帮助