@Override
  public void onCharacteristicWrite(
      BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    super.onCharacteristicWrite(gatt, characteristic, status);
    // Log.d(LOG_TAG, "onCharacteristicWrite " + characteristic);

    if (writeCallback != null) {

      if (writeQueue.size() > 0) {
        byte[] data = writeQueue.get(0);
        writeQueue.remove(0);
        // Log.d(LOG_TAG, "rimangono in coda: " + writeQueue.size());
        doWrite(characteristic, data);
      } else {

        if (status == BluetoothGatt.GATT_SUCCESS) {
          writeCallback.invoke();
          // Log.e(LOG_TAG, "writeCallback invocato");
        } else {
          // writeCallback.error(status);
          Log.e(LOG_TAG, "errore onCharacteristicWrite:" + status);
          writeFailCallback.invoke("Error writing status: " + status);
        }

        writeCallback = null;
        writeFailCallback = null;
      }
    } else Log.e(LOG_TAG, "Nessun callback su write");
  }
Exemplo n.º 2
0
    /** Callback invoked by Android framework when a characteristic write completes */
    @Override
    public void onCharacteristicWrite(
        BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
      super.onCharacteristicWrite(gatt, characteristic, status);
      if (status == 0) {
        try {
          processCharacteristicWrite(characteristic);
        } catch (Throwable t) {
          Log.e(TAG, "error", t);
        }
      }

      mRequestQueue.next(); // Execute the next queued request, if any
    }
 @Override
 public void onCharacteristicWrite(
     BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
   super.onCharacteristicWrite(gatt, characteristic, status);
 }