我遇到了同样的问题.您似乎无法从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的蓝牙设备,这些设备处于请求状态.在此示例中,它包括当前连接的所有设备和先前已断开连接的配对设备.