6

I am developing an Android app which connects to the BLE devices, Device does connect most of the time and i am able to capture the readings. But sometime after many connects disconnects, Bluetooth On/Off, my BluetoothGattCallback class method

onServicesDiscovered(BluetoothGatt gatt, int status)

with status 0 [which means GATT_SUCCESS].

now when i try to get the BluetoothGattService like:

BluetoothGattService service = gatt.getService(getServiceUUID());

it return null, so that i am unable to perform next steps. Please help me to find the problem.

jitain sharma
  • 584
  • 5
  • 19
  • If you can't understand, in what context question has been asked, please don't put your concern here. As i am seeing two users has downgrade this question. If you want more info about the ques, just ask and add comment. This type of behavior is not a professional outlook. So please maintain this. – jitain sharma May 02 '14 at 07:33

2 Answers2

4

You have to first discover all services for the given device, otherwise when you run BluetoothGattService service = gatt.getService(getServiceUUID()); it will return null.

I would recommend you add the onServicesDiscovered function and use gatt.discoverServices(); instead.

@Override
    // New services discovered
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            for (BluetoothGattService gattService : gattServices) {
                Log.i(TAG, "Service UUID Found: " + gattService.getUuid().toString());
            }
        }
    }
Omar
  • 492
  • 4
  • 10
0

hello because of bluetooth low energy is unstable . and as your question define that you get call back function with 0 status code. then instead of using getServivce(UUID). you can use getServices() method to discover avaliable services. this might be uuid issue!! Maybe you've got the UUID wrong..

Community
  • 1
  • 1
mcd
  • 1,434
  • 15
  • 31
  • 1
    UUID is correct as i am able to get the services, but as i mention after 7 attempts of on/off BT or connect disconnect the device, both getService with UUID and getServices() returns null. – jitain sharma May 01 '14 at 16:40