android 获取蓝牙设备id_在Android中,如何获取连接的蓝牙设备的配置...

在Android中,获取连接的蓝牙设备ID和配置文件并非直接操作。可以通过实现`BluetoothProfile.ServiceListener`并使用`getDevicesMatchingConnectionStates`方法来获取支持特定配置文件(如A2DP)的设备列表,这将包括连接和断开状态的设备。
摘要由CSDN通过智能技术生成

我遇到了同样的问题.您似乎无法从BluetoothDevice类获取可用的配置文件.

但是,通过BluetoothProfile类中的getDevicesMatchingConnectionStates方法获取BluetoothDevices列表还有很长的路要走.

例如,如果要查找哪个BluetoothDevices支持A2DP,请首先创建自定义BluetoothProfile.ServiceListener

public class cServiceListener implements BluetoothProfile.ServiceListener {

private static final int[] states={ BluetoothProfile.STATE_DISCONNECTING,

BluetoothProfile.STATE_DISCONNECTED,

BluetoothProfile.STATE_CONNECTED,

BluetoothProfile.STATE_CONNECTING};

@Override

public void onServiceConnected(int profile, BluetoothProfile bluetoothProfile) {

List Devices=bluetoothProfile.getDevicesMatchingConnectionStates(states);

for (BluetoothDevice loop:Devices){

Log.i("myTag",loop.getName());

}

}

@Override

public void onServiceDisconnected(int profile) {

}

}

然后将其附加到要检查的配置文件,在此示例中为A2DP

mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

cServiceListener mServiceListener=new cServiceListener();

mBluetoothAdapter.getProfileProxy(thisContext,mServiceListener, BluetoothProfile.A2DP);

这将记录所有支持A2DP的蓝牙设备,这些设备处于请求状态.在此示例中,它包括当前连接的所有设备和先前已断开连接的配对设备.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值