Alternative to the deprecated AudioManager.isWiredHeadsetOn?

后端 未结 6 1494
暗喜
暗喜 2021-02-13 20:47

The method AudioManager.isWiredHeadsetOn() is deprecated from api level 14, how do we now detect if a wired headset is connected?

6条回答
  •  余生分开走
    2021-02-13 21:20

    Try this solution. It's working in my case. May be this helps you!

    IntentFilter iFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    Intent iStatus = context.registerReceiver(null, iFilter);
    boolean isConnected = iStatus.getIntExtra("state", 0) == 1;
    

提交回复
热议问题