Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Value from Parcelable Array in Android

I need to parse and get the Value from :

Parcelable[] uuidExtra = intent.getParcelableArrayExtra("android.bluetooth.device.extra.UUID");

My goal is to get UUID from above Parcelable[]. How to achieve it?

like image 237
Venky Avatar asked Apr 22 '26 11:04

Venky


2 Answers

Try something like this. It worked for me:

   if(BluetoothDevice.ACTION_UUID.equals(action)) {
     BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
     Parcelable[] uuidExtra = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID);
     for (int i=0; i<uuidExtra.length; i++) {
       out.append("\n  Device: " + device.getName() + ", " + device + ", Service: " + uuidExtra[i].toString());
     }

Hope this helps!

like image 169
digitalhack Avatar answered Apr 25 '26 00:04

digitalhack


You need to iterate over the Parcelable[], cast each Parcelable to ParcelUuid and use ParcelUuid.getUuid() to get the UUIDs. While you can use toString() on the Parcelables as in another answer, this will give you only a String representing the UUID, not an UUID Object.

Parcelable[] uuids = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID);
if (uuids != null) {
    for (Parcelable parcelable : uuids) {
        ParcelUuid parcelUuid = (ParcelUuid) parcelable;
        UUID uuid = parcelUuid.getUuid();
        Log.d("ParcelUuidTest", "uuid: " + uuid);
    }       
}       
like image 27
arne Avatar answered Apr 24 '26 23:04

arne