Search code examples
javaandroidbluetoothbluetooth-lowenergyuuid

Invalid UUID/Services returned while scanning paired devices


I am trying to find a specific type of device based on its services from the list of already paired devices, but when I get the devices UUID, none of the services supported by the device actually show up.

I don't want to device.connectGatt(this, false, gattCallback); to every single device paired to eventually find the right one, due to it being inefficient.

The relevant segment of code is as follows

            for(BluetoothDevice device : bondedDevices) {
                ParcelUuid temp_uuids = device.getUuids();
                for (ParcelUuid uuids : myUuids) {
                    if (uuids.equals(temp_uuids)) {
                        targetDevice = device;
                        return targetDevice;
                    }
                }
            }
           Log.d(TAG, "Target Device Not Found");
           return targetDevice;

the if (uuids.equals(temp_uuids))statement where it checks equals is never met, I believe my bluetooth device is supposed to add the GATT service UUID under its list of services included in SDP, but for some reason it is not being detected.


Solution

  • From my understanding and my work-around to my own question: Problem: there is not a be BLE connection started yet and thus I am reading the Bluetooth Classic services rather than BLE. Thus, reading the incorrect ones. (Not sure this is true for all Android versions or just Android 10)

    To solve this, I fell back onto to primary checking the address of the Bluetooth device. This is due to my goal of only connecting to a certain brand of device and them having only a set of specific vendor address. I am then checking UUIDs after connection is made.

    Hope this helps whoever faces this issue in the future.