什么是用于获取已连接音频设备列表的android api? [英] What is the android api for getting the list of connected audio devices?

本文介绍了什么是用于获取已连接音频设备列表的android api?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下添加的代码来获取用于android设备的已连接音频设备。使用AudioManager api方法 getDevices()并通过连接的设备(如耳机,扬声器,耳机)获得结果。但是此 getDevices()方法仅在android api级别23(棉花糖)起可用。

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 devices like earphones, speaker, headphones. But this getDevices() method is available since android api level 23 (Marshmallow) only.

但是我的应用程序应该api级别21(Lollipop)的支持。请有人让我知道替代的api,以获取可用于android设备的音频设备。

But my application should support from api level 21 (Lollipop). Please can anybody let me know the alternative api to get the available audio device for the android device.

api级别23使用的代码。

Code used with api level 23.

AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
    AudioDeviceInfo[] adi = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
}

请提供一种获取设备连接音频设备的方法来帮助我

Please help me by providing a way to get the connected audio devices for the devices running with Android OS version below Marshmallow(api level 23).

推荐答案

似乎没有在API级别23之前存在此类API,但是可以使用布尔方法来检查是否有音频设备:

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()-在API级别5中添加,在API级别15中已弃用

  • isSpeakerphoneOn()-在API级别1中添加

  • isBluetoothScoOn()-已添加到API级别1

  • isBluetoothA2dpOn ()-在API级别3中添加,在API级别26中不推荐使用

  • 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

如果向AndroidManifest.xml添加 MODIFY_AUDIO_SETTINGS 权限

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

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

检查后,您可以将设备打开关闭,方法是将 true false 传递给方法:

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


  • setWiredHeadsetOn()-在API级别5中添加,在API级别5中弃用

  • setSpeakerphoneOn()-已添加到API级别1

  • setBluetoothScoOn()-已添加在API级别1中

  • setBluetoothA2dpOn()-在API级别3中添加,在API级别5中已弃用

  • 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

这篇关于什么是用于获取已连接音频设备列表的android api?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆