Alternative to the deprecated AudioManager.isWiredHeadsetOn?

后端 未结 6 1490
暗喜
暗喜 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:00

    It works for me correctly:

    if(context.registerReceiver(null, new IntentFilter(Intent.ACTION_HEADSET_PLUG)).getIntExtra("state", 0)==1){
    //if(audioManager.isWiredHeadsetOn()){
        System.out.println("Headset is wiredOn");
    }
    else{
        System.out.println("Headset is not wiredOn");
    }
    

提交回复
热议问题