Skip to content

Latest commit

 

History

History
63 lines (55 loc) · 3.05 KB

File metadata and controls

63 lines (55 loc) · 3.05 KB

Changes in version 2.0:

  1. BLE operation methods (i.e. writeCharacteristic(...), etc.) return the Request class now, instead of boolean.
  2. onLinklossOccur callback has been renamed to onLinkLossOccurred.
  3. GATT callbacks (for example: onCharacteristicRead, onCharacteristicNotified, etc.) inside BleManagerGattCallback has been deprecated. Use Request callbacks instead.
  4. Build-in Battery Level support has been deprecated. Request Battery Level as any other value.
  5. A new callbacks method: onBondingFailed has been added to BleManagerCallbacks.
  6. shouldAutoConnect() has ben deprecated, use useAutoConnect(boolean) in ConnectRequest instead.
  7. Timeout is supported for connect, disconnect and wait for notification/indication. Most BLE operations do not support setting timeout, as receiving the BluetoothGattCallback is required in order to perform the next operation.
  8. Atomic RequestQueue and ReliableWriteRequest are supported.
  9. BLE Library 2.0 uses Java 8. There's no good reason for this except to push the ecosystem to having this be a default. As of AGP 3.2 there is no reason not to do this (via butterknife).

Migration guide:

  1. Replace initGatt(BluetoothGatt) with initialize():

Old code:

@Override
protected Deque<Request> initGatt(final BluetoothGatt gatt) {
  final LinkedList<Request> requests = new LinkedList<>();
  requests.add(Request.newEnableNotificationsRequest(characteristic));
  return requests;
}

New code:

@Override
protected void initialize() {
  setNotificationCallback(characteristic)
    .with(new DataReceivedCallback() {
      @Override
      public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
        ...
      }
    });
  enableNotifications(characteristic)
    .enqueue();
}

See changes in Android nRF Toolbox and Android nRF Blinky for more examples.

Remember to call .enqueue() method for initialization requests!

Connect's completion callback is called after the initialization is done (without or with errors).

  1. Move your callback implementation from BleManagerGattCallback to request callbacks.
  2. To split logic from parsing, we recommend to extend DataReceivedCallback interface in a class where your parse your data, and return higher-level values. For a sample, check out nRF Toolbox and Android BLE Common Library. If you are depending on a SIG adopted profile, like Heart Rate Monitor, Proximity, etc., feel free to include the BLE Common Library in your project. It has all the parsers implemented. If your profile isn't there, we are happy to accept PRs.
  3. connect() and disconnect() methods also require calling .enqueue() in asynchronous use.
  4. Replace the shouldAutoConnect() method in the manager with connect(device).useAutConnect(true).enqueue()/await().