title: How to write 2-byte or 4-byte BLE characteristics value in android?
body: <p>I am developing an automation system in which I am using android phone(having low energy Bluetooth) as a remote control. </p>
  
  <p>I can write 1-byte(0xFF) characteristic value successfully. Here is my sample code.</p>
  
  <pre><code>byte[] value= {(byte) 0xFF};
  characteristic.setValue(value);
  mBluetoothGatt.writeCharacteristic(characteristic);
  </code></pre>
  
  <p>Now the issue is that I want to write more than one-byte characteristic value like:</p>
  
  <pre><code>byte[] value= {(byte) 0xFF,(byte) 0xFF,(byte) 0xFF};
  characteristic.setValue(value);
  mBluetoothGatt.writeCharacteristic(characteristic);
  </code></pre>
  
  <p>When I change the value to 2-byte or 3-byte to write the characteristic value then in <code>onCharacteristicWrite()</code>callback method <code>else if (status == BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH)</code> part is executed of the conditional statement. You can see my sample code below. Now please guide me how can I write 2-byte or 3-byte value of characteristic, I would be very thankful to you in this respect. Thanks in andvace.</p>
  
  <pre><code>   public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) 
          {
  
              if (status == BluetoothGatt.GATT_SUCCESS) 
              {
                  broadcastUpdate(ACTION_DATA_WRITE, characteristic);
                  Log.e("WRITE SUCCESS", "onCharacteristicWrite() - status: " + status + "  - UUID: " + characteristic.getUuid());
              }
               ...
               ...
               ...
              else if (status == BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH) 
              {
                  Log.e("WRITE PROB", "A write operation exceeds the maximum length of the attribute");
              }
          }
  </code></pre>