如何在Java中通过A2DP配对蓝牙扬声器?

时间:2019-07-10 16:19:17

标签: java android bluetooth pairing

在我的Java应用程序中,我将两个设备相互连接。一台设备是装有该应用程序的设备,另一台是蓝牙扬声器。问题是,配对不起作用,而Google没有给我答案。

该代码在OnItemClickListener中执行,因为我与用户在列表中单击的设备配对。

这是我的代码:

Set<BluetoothDevice> bonded = bAdapter.getBondedDevices();
int counter;

for(counter = 0; counter < bonded.size()-1; counter++) {
     BluetoothDevice current = (BluetoothDevice) bonded.toArray()[counter];

     if(current.getName().equals(parent.getAdapter().getItem(position))) {
          break;
     }
}
bDevice = (BluetoothDevice) bonded.toArray()[counter];
Log.d("Info", "Device Name: " + bDevice.getName());

boolean b = bDevice.createBond();

if(b) {
     Log.d("Info","Successfully paired");
}
else {
     Log.d("Info", "Pairing failed");
}

在每种情况下配对都会失败,并且也不会显示错误消息。

我希望有人可以帮助我解决这个问题。 预先谢谢你。

0 个答案:

没有答案