Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the UUID of a bluetooth device?

I need to know UUID on API 8 (2.2) or possibly 2.3.3.

As I understand the documentation, this should be allowed:

    phoneDevice = blueAdapter.getRemoteDevice(phoneAddress);
    ParcelUuid[] phoneUuids = phoneDevice.getUuids();  // Won't compile

Eclipse gives me: "The method getUuids() is undefined for the type BluetoothDevice." But see: http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getUuids()

Also, I would like to know how the UUIDs are "parceled" inside the ParcelUuid[]. In case I ever manage to get there, how do I retrieve a UUID from a parcelUuid[]? Documentation for Android bluetooth seems to be very poor, in my opinion.

What a joke! Now I try to get it from the intent, but this too gives: *"EXTRA_UUID cannot be resolved or is not a field"*:

intent.getParcelableExtra(BluetoothDevice.EXTRA_UUID); 
like image 776
Tombola Avatar asked Mar 05 '12 14:03

Tombola


2 Answers

You have to use reflection to use the getUuids() and fetchUuidsWithSdp() on android version < 3. So, try the code:

Method method = phoneDevice.getClass().getMethod("getUuids", null);
ParcelUuid[] phoneUuids = (ParcelUuid[]) method.invoke(phoneDevice, null);
like image 194
Naka Avatar answered Sep 28 '22 05:09

Naka


//this will support from API level 15 and above.

Broadcast Action: This intent is used to broadcast the UUID wrapped as a ParcelUuid of the remote device after it has been fetched. This intent is sent only when the UUIDs of the remote device are requested to be fetched using Service Discovery Protocol
    Always contains the extra field EXTRA_DEVICE
    Always contains the extra field EXTRA_UUID
    Requires BLUETOOTH to receive.
    Constant Value: "android.bluetooth.device.action.UUID"

//no way to degrade its hardware related. there is no supporting jar also. http://developer.android.com/sdk/compatibility-library.html

like image 36
Padma Kumar Avatar answered Sep 28 '22 06:09

Padma Kumar