我遇到了同樣的問題。您似乎沒有從BluetoothDevice類中獲得可用的配置文件。 但周圍有很長的路要走通過從藍牙規範類getDevicesMatchingConnectionStates方法得到的BluetoothDevice類個列表。
例如,如果你想找到這BluetoothDevice類的支持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<BluetoothDevice> 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);
這將logcat的所有支持A2DP藍牙設備,其在請求的狀態。在這個例子中,它包括當前連接的所有設備和先前已斷開連接的設備。