0

I need send value like 0x0001 , 0x0002 in BLE setValue() ,

Does anyone know how to transmit ?

for Example :

private void command () {
   ongoing.setValue(0x0001);  //error
   mBluetoothLeService.writeCharacteristic(ongoing);
   BluetoothLeService.setCharacteristicNotification(ongoing, true);
   ...
   ...
   ...
   mBluetoothLeService.readCharacteristic(ongoing);
}

Thanks.

in DeviceControlActivity.java :

private void displayGattServices(List<BluetoothGattService> gattServices){
    UUID UBI_COMMAND = UUID.fromString(SampleGattAttributes.UBI_ONGOING_INFO_SERVICE_UUID);
    ...
    ...
    if (uuid.equals(SampleGattAttributes.UBI_ONGOING_INFO_SERVICE_UUID)){
       ongoing = gattService.getCharacteristic(UBI_ONGOING);
    }
}
leona lin
  • 39
  • 1
  • 7
  • What is the type of `ongoing`? – Sweeper Jun 06 '17 at 06:41
  • It should be BluetoothGattCharacteristic because its being passed to a method that requires it? – CmosBattery Jun 06 '17 at 07:22
  • I've only ever read, but see here for writing: https://stackoverflow.com/questions/36163998/writing-data-to-bluetooth-le-characteristic-in-android ... Notably, you could use an actual method like @Override public void onCharacteristicWrite(BluetoothGatt gatt, .... to write the data. But you just might not be writing correctly as per the link. – CmosBattery Jun 06 '17 at 07:28

1 Answers1

3

First define your input format(byte) then set the value of characterstics. Please check below snippet. "writeCharacterstics" function is available in the BluetoothGatt. If you have not a method in your service defined by you then also change the "mBluetoothLeService" object to "gatt" object to write the value.

            byte[] value = {(byte) 0x01};
            characteristic.setValue(value);
            mBluetoothLeService.writeCharacteristic(characteristic);
Anshika Bansal
  • 320
  • 2
  • 9