What is the android api for getting the list of connected audio devices?

前端 未结 1 871
醉话见心
醉话见心 2021-01-01 15:16

I used the below added code to get the connected audio devices for android device. Used AudioManager api method getDevices() and got the result with connected d

相关标签:
1条回答
  • 2021-01-01 16:06

    It seems there was no such API before API level 23, but one could use boolean methods to check, if some audio device was on:

    • isWiredHeadsetOn() - added in API level 5, deprecated in API level 15
    • isSpeakerphoneOn() - added in API level 1
    • isBluetoothScoOn() - added in API level 1
    • isBluetoothA2dpOn() - added in API level 3, deprecated in API level 26

    If you always get false when add MODIFY_AUDIO_SETTINGS permission to AndroidManifest.xml

    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 
    

    After the check you may set the devices on or off by passing true or false to methods:

    • setWiredHeadsetOn() - added in API level 5, deprecated in API level 5
    • setSpeakerphoneOn() - added in API level 1
    • setBluetoothScoOn() - added in API level 1
    • setBluetoothA2dpOn() - added in API level 3, deprecated in API level 5
    0 讨论(0)
提交回复
热议问题