Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- };
Add Comment
Please, Sign In to add comment