Guest User

Untitled

a guest
Jan 23rd, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. private final BroadcastReceiver btReceiver = new BroadcastReceiver() {
  2.  
  3. @Override
  4. public void onReceive(Context context, Intent intent) {
  5. String action = intent.getAction();
  6. if (BluetoothDevice.ACTION_FOUND.equals(action)) {
  7. BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
  8. Boolean flag = true;
  9.  
  10. //Parcelable uuidExtra = intent.getParcelableExtra(BluetoothDevice.EXTRA_UUID);
  11. Parcelable[] uuidExtra = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID);
  12. ParcelUuid[] deviceUuids = device.getUuids();
  13. // if (listOfAllDevices != null) {
  14. for (BluetoothDevice listOfAllDevice : listOfAllDevices) {
  15. if (device.getAddress().equals(listOfAllDevice.getAddress()) && device.getName().equals(listOfAllDevice.getName())) {
  16. flag = false;
  17. }
  18. }
  19. // }
  20.  
  21.  
  22. //if (flag && uuidExtra != null) {
  23. if (flag) {
  24. listOfAllDevices.add(device);
  25.  
  26. //for(Parcelable p: uuidExtra) allUUIDList.add(p.toString());
  27. for(Parcelable p: deviceUuids) allUUIDList.add(p.toString());
  28.  
  29. if (!listOfAllDevices.isEmpty()) {
  30. for (int i = 0; i < listOfAllDevices.size(); i++) {
  31. BluetoothDevice fetchedDevice = listOfAllDevices.get(i);
  32. if (fetchedDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
  33. arrayListBluetoothDevicesReadyToPair.add(fetchedDevice);
  34. // unpairedDevicesUUIDList.add(allUUIDList.get(i));
  35. foundDevicesList.add(fetchedDevice.getName() + ", " + fetchedDevice.getAddress());
  36. foundDevicesAdapter.notifyDataSetChanged();
  37.  
  38. } else {
  39.  
  40. pairedDevicesList.add(fetchedDevice);
  41. // pairedDeivicesUUIDList.add(allUUIDList.get(i));
  42.  
  43. pairedList.add(fetchedDevice.getName() + ", " + fetchedDevice.getAddress());
  44. pairAdapter.notifyDataSetChanged();
  45. }
  46. }
  47. }
  48.  
  49. }
  50. for (int i = 0; i < listOfAllDevices.size(); i++) {
  51. Log.d("LISTA URZADZEN", "LISTA URZADZEN ZNALEZIONYCH: " + listOfAllDevices.get(i).getName() + ", UUID" + allUUIDList.get(i)); //+ allUUIDList.get(i));
  52. }
  53. // }
  54. } else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
  55. Log.e("bluetoothReceiver", "ACTION_DISCOVERY_STARTED");
  56. } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
  57. Log.e("bluetoothReceiver", "ACTION_DISCOVERY_FINISHED");
  58. }
  59.  
  60. }// onReceive()
  61. };
Add Comment
Please, Sign In to add comment