•   almost 6 years ago

Android detecting button presses


I've managed to get all the verification stuff working ok so the device stays connected to my Android phone, but I've been unable to get the button press callbacks working.

Here is what I'm doing:

// Configure the detect configuration to enable short and long button presses
UUID Detection_Configuration_UUID = UUID.fromString("fffffff2-00f7-4000-b000-000000000000");
BluetoothGattCharacteristic detectionConfigCharacteristic = gattService.getCharacteristic(Detection_Configuration_UUID);
byte[] val={ (byte)0x3 };

// Configure the notification UUID to enable callbacks
UUID Notification_UUID = UUID.fromString("fffffff4-00f7-4000-b000-000000000000");
BluetoothGattCharacteristic characteristic = gattService.getCharacteristic(Notification_UUID);
mBluetoothGatt.setCharacteristicNotification(characteristic, true);

BluetoothGattDescriptor descriptor = characteristic.getDescriptor(

So far I've never been able to see a callback to my onCharacteristicChanged method whenever I press the button.

Is there something obvious I am doing wrong or misunderstanding?

Thanks for any help,



  •   •   almost 6 years ago

    Just to follow up (to help others in the same boat), I have now got button press detection working.

    The key was that you need to wait for each individual write operation to complete before invoking the next (using the onCharacteristicWrite callback).



  • Manager   •   almost 6 years ago

    Thank JamieHiggins,
    As you state on your reply, the Android framework does not seem to handle multiple write/read requests. Your suggestion is correct, subsequent writes should be done after the previous onCharacteristicWrite/onCharacteristicRead call back is called.

  •   •   almost 6 years ago

    I can confirm that this works for me too. My phone now makes Mario sounds!! Woohoo!!

Comments are closed.