Android - Get Bluetooth UUID for this device Android - Get Bluetooth UUID for this device android android

Android - Get Bluetooth UUID for this device


Using reflection you can invoke the hidden method getUuids() on the BluetoothAdater:

BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();Method getUuidsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null);ParcelUuid[] uuids = (ParcelUuid[]) getUuidsMethod.invoke(adapter, null);for (ParcelUuid uuid: uuids) {    Log.d(TAG, "UUID: " + uuid.getUuid().toString());}

This is the result on a Nexus S:

UUID: 00001000-0000-1000-8000-00805f9b34fbUUID: 00001001-0000-1000-8000-00805f9b34fbUUID: 00001200-0000-1000-8000-00805f9b34fbUUID: 0000110a-0000-1000-8000-00805f9b34fbUUID: 0000110c-0000-1000-8000-00805f9b34fbUUID: 00001112-0000-1000-8000-00805f9b34fbUUID: 00001105-0000-1000-8000-00805f9b34fbUUID: 0000111f-0000-1000-8000-00805f9b34fbUUID: 0000112f-0000-1000-8000-00805f9b34fbUUID: 00001116-0000-1000-8000-00805f9b34fb

where, for instance, 0000111f-0000-1000-8000-00805f9b34fb is for HandsfreeAudioGatewayServiceClass and 00001105-0000-1000-8000-00805f9b34fb is for OBEXObjectPushServiceClass. Actual availability of this method may depend on device and firmware version.


To achieve this you must define the Bluetooth permission:

<uses-permission android:name="android.permission.BLUETOOTH"/>

Then you can invoke the method getUuids() using reflection:

    try {    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();    Method getUuidsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null);    ParcelUuid[] uuids = (ParcelUuid[]) getUuidsMethod.invoke(adapter, null);         if(uuids != null) {             for (ParcelUuid uuid : uuids) {                 Log.d(TAG, "UUID: " + uuid.getUuid().toString());             }         }else{             Log.d(TAG, "Uuids not found, be sure to enable Bluetooth!");         }    } catch (NoSuchMethodException e) {        e.printStackTrace();    } catch (IllegalAccessException e) {        e.printStackTrace();    } catch (InvocationTargetException e) {        e.printStackTrace();    }

You must enable bluetooth to get Uuids.