Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 that the service is not supported by the BluetoothGatt . Why is this happening , can anybody please help me .

like image 914
beginner Avatar asked Oct 24 '13 02:10

beginner


2 Answers

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 discovered
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            BluetoothGattService mBluetoothGattService = 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());
}
like image 84
Omar Avatar answered Nov 05 '22 05:11

Omar


Try doing a full discover[1] of the remote database and then iterate through the services. Maybe you've got the UUID wrong.

[1] http://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#discoverServices()

like image 28
Vegar Westerlund Avatar answered Nov 05 '22 05:11

Vegar Westerlund