android device.getUuids returns null android device.getUuids returns null android android

android device.getUuids returns null


 BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner(); // scan for devices scanner.startScan(new ScanCallback() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void onScanResult(int callbackType, ScanResult result)    {      List<ParcelUuid> uuids = result.getScanRecord().getServiceUuids();   }}

this is worked for me in Android 6.0.1


After hours of searching I find out that getUuid() is not the way to go if you want to retrieve the uuid of an iBeacon.

If that is the case, you need to get it directly from the Scan result result object.

I managed to work by using the answer provided by ADEBAYO OSIPITAN.BLE obtain uuid encoded in advertising packet

Here is his code snipet:

//For APIs greater than 21, Returns Device UUIDpublic String getUUID(ScanResult result){String UUIDx = UUID        .nameUUIDFromBytes(result.getScanRecord().getBytes()).toString();    return UUIDx;}


From Java DOC:

public ParcelUuid[] getUuids ()

Added in API level 15Returns the supported features (UUIDs) of the remote device.

This method does not start a service discovery procedure to retrieve the UUIDs from the remote device. Instead, the local cached copy of the service UUIDs are returned.

Use fetchUuidsWithSdp() if fresh UUIDs are desired.

Requires BLUETOOTH.

Returnsthe supported features (UUIDs) of the remote device, or null on error

Your ScanResult probably is a error