Android device.getUuids returns null

I am trying to connect to Arduino Uno through an Android app using Bluetooth Low Energy (BLE).
I am developing on Android Studio, testing with Samsung Galaxy S4 and with Android version 5.0.1
I followed this link: http://www.truiton.com/2015/04/android-bluetooth-low-energy-ble-example/
I scan devices, and when I found it, I would like to get its UUID before connecting it, to make sure that it is the correct type of device:

mScanCallback = new ScanCallback() { @Override @TargetApi(21) public void onScanResult(int callbackType, ScanResult result) { BluetoothDevice btDevice = result.getDevice(); ParcelUuid[] uuids = btDevice.getUuids(); //<-- this is always null!! :( Log.d(TAG, ""+btDevice.fetchUuidsWithSdp()); //<-- prints true. Log.d(TAG, "result : " + result.toString()); //<-- prints a bunch of relevant info that contains the UUID I want to check. Log.d(TAG, "uuids : " + uuids); //<-- prints null. /* for (ParcelUuid u : uuids) { //Compare with the UUID of my device, and connect if ok. } */ } 

However, btDevice.getUuids (); always returns null without errors ...
How can I get the UUID of the scanned device?
The brute force method will use regexp with the result .toString () to grab what I want, but there should be a better way, right?
thanks

+6
source share
2 answers
  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 works for me on Android 6.0.1

+6
source

From Java DOC:

public ParcelUuid [] getUuids ()

Added to API Level 15 Returns the supported functions (UUIDs) of a remote device.

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

Use fetchUuidsWithSdp () if fresh UUIDs are required.

BLUETOOTH required.

Returns the supported function (UUID) of the remote device, or null on error

Probably ScanResult is a mistake

0
source

Source: https://habr.com/ru/post/989364/


All Articles