Skip to content Skip to sidebar Skip to footer

Mbluetoothgatt.getservice(uuid) Returns Null

In my app , i am passng the UUID number of the hearing aid service as in the BLE sample from google i.e. 0000a00-0000-1000-8000-00805f9b34fb But the getservice returns null means t

Solution 1:

You have to first discover all services for the given device per documentation.

This function requires that service discovery has been completed for the given device. http://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#getService(java.util.UUID)

@Override// New services discoveredpublicvoidonServicesDiscovered(BluetoothGatt gatt, int status) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            BluetoothGattServicemBluetoothGattService= mBluetoothGatt.getService(UUID.fromString(serviceUUID));
            if (mBluetoothGattService != null) {
                Log.i(TAG, "Service characteristic UUID found: " + mBluetoothGattService.getUuid().toString());
            } else {
                Log.i(TAG, "Service characteristic not found for UUID: " + serviceUUID);
        }
    }

Or you can just run a search

for (BluetoothGattService gattService : gattServices) {
    Log.i(TAG, "Service UUID Found: " + gattService.getUuid().toString());
}

Solution 2:

Solution 3:

Your UUID is also wrong. It should be 0000a00X-0000-1000-8000-00805f9b34fb, not 0000a00-0000-1000-8000-00805f9b34fb

Post a Comment for "Mbluetoothgatt.getservice(uuid) Returns Null"