1

I am attempting to connect to a bluetooth peripheral device using bluetooth 4.0 (LE). I am following the guide from the android developer page found here.

I have already successfully built this application on iOS, and this is my first time working with Android. I am running version 4.4. I want to be able to check the UUID of the peripheral found (just like I do on iOS) when the android device does a bluetooth search. I am not sure how to do this but I believe it happens in this method:

 public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
        Log.i(TAG, "New LE Device: " + device.getName() + " @ " + rssi);

          //DETERMINE UUID OF PERIPHERAL

    }

Can anyone please tell me how this can be done?

Thanks!

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72
Teddy13
  • 3,824
  • 11
  • 42
  • 69

1 Answers1

1

You may search for devices only for your specified UUID: (Android BLE Doc)

public boolean startLeScan (UUID[] serviceUuids, BluetoothAdapter.LeScanCallback callback)

But, there are known issues in Android version 4.4.4 with this method, may it change in the future.

You may use this method successfully with 16 bit UUID search, but it would fail with 128 bit UUID on Nexus devices. (Worked on Samsung S5 for me).

If you want to stick with 128 bit UUID search, you need some workaround (at least for current android version 4.4.4)

This post has some good details about scanRecord byte array structure.

Community
  • 1
  • 1
Khulja Sim Sim
  • 3,469
  • 1
  • 29
  • 28