title: BLE with MiBand 3
body: <p>This is my first time asking so please forgive if I happen to show mistakes.</p>
  
  <p>Simply put, I want to create app that able to interact with Mi Band 3. The interaction I'm able to make is just reading battery info. What I truly want is enabling the real-time heart rate and steps scan. </p>
  
  <p>What have I done before? </p>
  
  <ul>
  <li><p>I've seen and tried <a href="https://github.com/pangliang/miband-sdk-android" rel="nofollow noreferrer">https://github.com/pangliang/miband-sdk-android</a> . It was actually this library that made me think that enabling heart scan from Android is possible to do. I tried following with my Mi Band 3 but failed: setHeartRateScanListener, startHeartRateScan, getBatteryInfo.</p></li>
  <li><p>I've seen, cloned, and tampered a little with <a href="https://github.com/Freeyourgadget/Gadgetbridge" rel="nofollow noreferrer">https://github.com/Freeyourgadget/Gadgetbridge</a> . It is amazing, It can interact with my Mi Band 3, but the problem is Gadgetbridge do not have heart rate scan feature and I kinda overwhelmed with the code.</p></li>
  <li><p>Of course, I've tried <a href="https://developer.android.com/guide/topics/connectivity/bluetooth-le" rel="nofollow noreferrer">https://developer.android.com/guide/topics/connectivity/bluetooth-le</a> . After reading the Pangliang's and Gadgetbridge's code I did following to do heart rate scan. </p></li>
  </ul>
  
  <p>First, I know that I should put listener right? So here's the function</p>
  
  <pre><code>    public void listenHeartRate() {
          BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb")).getCharacteristic(UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb"));
          bluetoothGatt.setCharacteristicNotification(characteristic, true);
          BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
          descriptor.setValue(new byte[] {0x01, 0x00});
          if(!bluetoothGatt.writeDescriptor(descriptor)) {
              Log.d(TAG, "tesListenHeartRate: failed");
  
          }
      }
  </code></pre>
  
  <p>And then, I start the scanning with this.</p>
  
  <pre><code>    public void startHeartRate() {
          Log.d(TAG, "tesHeartRate: start");
          BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb")).getCharacteristic(UUID.fromString("00002a39-0000-1000-8000-00805f9b34fb"));
          characteristic.setValue(new byte[]{21, 2, 1});
          if (!bluetoothGatt.writeCharacteristic(characteristic)) {
              Log.d(TAG, "tesStartHeartRate: failed");
          }
      }
  </code></pre>
  
  <p>The problem with this is that writeCharacteristic always returning status 3 which means GATT_WRITE_NOT_PERMITTED.</p>
  
  <p>So, where did I go wrong? Thank you very much.</p>