title: Android 4.3 BLE how to write Characteristic
body: <p>Followed <a href="http://developer.android.com/guide/topics/connectivity/bluetooth-le.html" rel="nofollow">sample</a></p>
  
  <p>I know: </p>
  
  <ul>
  <li>How to read Characteristic value.</li>
  </ul>
  
  <p>But I don't know:</p>
  
  <ul>
  <li>How to write data to the firmware.</li>
  </ul>
  
  <p>I tried several times, but it did not work.</p>
  
  <p>This is the coding:</p>
  
  <pre><code>if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) &gt; 0) {
                  System.out.println("read!!!!!!");
                  // If there is an active notification on a characteristic,
                  // clear
                  // it first so it doesn't update the data field on the user
                  // interface.
                  if (mNotifyCharacteristic != null) {
                      mBluetoothLeService.setCharacteristicNotification(
                              mNotifyCharacteristic, false);
                      mNotifyCharacteristic = null;
                  }
                  mBluetoothLeService.readCharacteristic(characteristic);
              }
              if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) &gt; 0) {
                  System.out.println("notify!!!!!!");
                  mNotifyCharacteristic = characteristic;
                  mBluetoothLeService.setCharacteristicNotification(
                          characteristic, true);
              }
              if ((charaProp | BluetoothGattCharacteristic.PROPERTY_WRITE) &gt; 0) {
                  if (SampleGattAttributes.AppConfigToBongCharacteristicUUID
                          .equals(characteristic.getUuid())) {
                      System.out.println("write!!!!!!");
                      mBluetoothLeService.writeCharacteristic(characteristic);
                  }
              }
  
  
  
  public void writeCharacteristic(BluetoothGattCharacteristic characteristic) {
      if (mBluetoothAdapter == null || mBluetoothGatt == null) {
          Log.w(TAG, "BluetoothAdapter not initialized");
          return;
      }
      if (UUID_SEND_CONFIG_TO_BONG.equals(characteristic.getUuid())) {
  
          Calendar date = Calendar.getInstance();
          StringBuilder data = new StringBuilder();
          String data_date_y = String.format("%4s", date.get(Calendar.YEAR))
                  .replace(' ', '0');
          String data_date_m = String.format("%2s", date.get(Calendar.MONTH))
                  .replace(' ', '0');
          String data_date_d = String.format("%2s", date.get(Calendar.DATE))
                  .replace(' ', '0');
          String data_date_h = String.format("%2s", date.get(Calendar.HOUR))
                  .replace(' ', '0');
          String data_date_min = String.format("%2s",
                  date.get(Calendar.MINUTE)).replace(' ', '0');
  
          data.append("10FFFF");
          data.append(data_date_y);
          data.append(data_date_m);
          data.append(data_date_d);
          data.append(data_date_h);
          data.append(data_date_min);
          System.out.println(data);
          byte[] dataByte = data.toString().getBytes();
  
          characteristic.setValue(dataByte);
          mBluetoothGatt.writeCharacteristic(characteristic);
      }
  
  }
  </code></pre>
  
  <p>//onCharacteristicWrite()  Not being called</p>
  
  <pre><code>@Override
      public void onCharacteristicWrite(BluetoothGatt gatt,
              BluetoothGattCharacteristic characteristic, int status) {
          System.out.println("writeCharacteristic111");
          System.out.println("status:" + status);
          System.out.println(BluetoothGatt.GATT_SUCCESS);
          if (status == BluetoothGatt.GATT_SUCCESS) {
              broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
          }
      }
  </code></pre>