Я делаю приложение, которое должно сопрягать устройства и подключаться к устройству Bluetooth.Для установления соединения необходим UUID.Когда я собираюсь добавить UUID в список, компилятор говорит, что UUID равен нулю.Итак, суть в том, есть ли способ достижения UUID?
Может ли кто-нибудь помочь мне с этим вопросом?Где ошибка в моем коде?
private final BroadcastReceiver btReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Boolean flag = true;
//Parcelable uuidExtra = intent.getParcelableExtra(BluetoothDevice.EXTRA_UUID);
Parcelable[] uuidExtra = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID);
ParcelUuid[] deviceUuids = device.getUuids();
// if (listOfAllDevices != null) {
for (BluetoothDevice listOfAllDevice : listOfAllDevices) {
if (device.getAddress().equals(listOfAllDevice.getAddress()) && device.getName().equals(listOfAllDevice.getName())) {
flag = false;
}
}
// }
//if (flag && uuidExtra != null) {
if (flag) {
listOfAllDevices.add(device);
//for(Parcelable p: uuidExtra) allUUIDList.add(p.toString());
for(Parcelable p: deviceUuids) allUUIDList.add(p.toString());
if (!listOfAllDevices.isEmpty()) {
for (int i = 0; i < listOfAllDevices.size(); i++) {
BluetoothDevice fetchedDevice = listOfAllDevices.get(i);
if (fetchedDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
arrayListBluetoothDevicesReadyToPair.add(fetchedDevice);
// unpairedDevicesUUIDList.add(allUUIDList.get(i));
foundDevicesList.add(fetchedDevice.getName() + ", " + fetchedDevice.getAddress());
foundDevicesAdapter.notifyDataSetChanged();
} else {
pairedDevicesList.add(fetchedDevice);
// pairedDeivicesUUIDList.add(allUUIDList.get(i));
pairedList.add(fetchedDevice.getName() + ", " + fetchedDevice.getAddress());
pairAdapter.notifyDataSetChanged();
}
}
}
}
for (int i = 0; i < listOfAllDevices.size(); i++) {
Log.d("LISTA URZADZEN", "LISTA URZADZEN ZNALEZIONYCH: " + listOfAllDevices.get(i).getName() + ", UUID" + allUUIDList.get(i)); //+ allUUIDList.get(i));
}
// }
} else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
Log.e("bluetoothReceiver", "ACTION_DISCOVERY_STARTED");
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
Log.e("bluetoothReceiver", "ACTION_DISCOVERY_FINISHED");
}
}// onReceive()
};
Я также получаю сообщение об ошибке «Невозможно уничтожить активность, Получатель не зарегистрирован: функция null» onDestroy ().Я регистрирую получателя после нажатия кнопки поиска.
Спасибо за все советы:)