•   over 5 years ago

Android detecting button presses

Hi,

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 };
detectionConfigCharacteristic.setValue(val);
mBluetoothGatt.writeCharacteristic(detectionConfigCharacteristic);

// 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(
UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);

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,

Jamie

  • 3 comments

  •   •   over 5 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).

    Cheers,

    Jamie

  • Manager   •   over 5 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.

  •   •   over 5 years ago

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

Comments are closed.