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

梦想与她 提交于 2019-11-30 11:13:50

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 14
  • 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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!