@Override protected void initialize() { super.initialize(); setIndicationCallback(mHTCharacteristic) .with(new TemperatureMeasurementDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { log(LogContract.Log.Level.APPLICATION, "\"" + TemperatureMeasurementParser.parse(data) + "\" received"); super.onDataReceived(device, data); } @Override public void onTemperatureMeasurementReceived(@NonNull final BluetoothDevice device, final float temperature, final int unit, @Nullable final Calendar calendar, @Nullable final Integer type) { mCallbacks.onTemperatureMeasurementReceived(device, temperature, unit, calendar, type); } }); enableIndications(mHTCharacteristic).enqueue(); }
/** * Returns the callback that is registered for value changes (notifications) of given * characteristic. After assigning the notifications callback, notifications must be * enabled using {@link #enableNotifications(BluetoothGattCharacteristic)}. * This applies also when they were already enabled on the remote side. * <p> * To remove the callback, disable notifications using * {@link #disableNotifications(BluetoothGattCharacteristic)}. * * @param characteristic characteristic to bind the callback with. If null, the returned * callback will not be null, but will not be used. * @return The callback. */ @MainThread @NonNull protected final ValueChangedCallback setNotificationCallback(@Nullable final BluetoothGattCharacteristic characteristic) { ValueChangedCallback callback = mNotificationCallbacks.get(characteristic); if (callback == null) { callback = new ValueChangedCallback(); if (characteristic != null) { mNotificationCallbacks.put(characteristic, callback); } } return callback.free(); }
/** * This method enables notifications on the Battery Level characteristic. * * @deprecated Use {@link #setNotificationCallback(BluetoothGattCharacteristic)} and * {@link #enableNotifications(BluetoothGattCharacteristic)} instead. */ @SuppressWarnings("ConstantConditions") @Deprecated protected void enableBatteryLevelNotifications() { if (mBatteryLevelNotificationCallback == null) { mBatteryLevelNotificationCallback = new ValueChangedCallback() .with((device, data) -> { if (data.size() == 1) { final int batteryLevel = data.getIntValue(Data.FORMAT_UINT8, 0); mBatteryValue = batteryLevel; final BleManagerGattCallback callback = mGattCallback; if (callback != null) { callback.onBatteryValueReceived(mBluetoothGatt, batteryLevel); } mCallbacks.onBatteryValueReceived(device, batteryLevel); } }); } Request.newEnableBatteryLevelNotificationsRequest().setManager(this) .done(device -> log(Log.INFO, "Battery Level notifications enabled")) .enqueue(); }
@Override protected void initialize() { super.initialize(); setNotificationCallback(mRSCMeasurementCharacteristic) .with(new RunningSpeedAndCadenceMeasurementDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { log(LogContract.Log.Level.APPLICATION, "\"" + RSCMeasurementParser.parse(data) + "\" received"); super.onDataReceived(device, data); } @Override public void onRSCMeasurementReceived(@NonNull final BluetoothDevice device, final boolean running, final float instantaneousSpeed, final int instantaneousCadence, @Nullable final Integer strideLength, @Nullable final Long totalDistance) { mCallbacks.onRSCMeasurementReceived(device, running, instantaneousSpeed, instantaneousCadence, strideLength, totalDistance); } }); enableNotifications(mRSCMeasurementCharacteristic).enqueue(); }
.with(new CyclingSpeedAndCadenceMeasurementDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) {
.with(new IntermediateCuffPressureDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { .with(new BloodPressureMeasurementDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
@Override protected void initialize() { setNotificationCallback(mTXCharacteristic) .with((device, data) -> { final String text = data.getStringValue(0); log(LogContract.Log.Level.APPLICATION, "\"" + text + "\" received"); mCallbacks.onDataReceived(device, text); }); requestMtu(260).enqueue(); enableNotifications(mTXCharacteristic).enqueue(); }
.with(new GlucoseMeasurementDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { .with(new GlucoseMeasurementContextDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { .with(new RecordAccessControlPointDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
public void enableBatteryLevelCharacteristicNotifications() { if (isConnected()) { // If the Battery Level characteristic is null, the request will be ignored setNotificationCallback(mBatteryLevelCharacteristic) .with(mBatteryLevelDataCallback); enableNotifications(mBatteryLevelCharacteristic) .done(device -> log(Log.INFO, "Battery Level notifications enabled")) .fail((device, status) -> log(Log.WARN, "Battery Level characteristic not found")) .enqueue(); } }
.enqueue(); setNotificationCallback(mHeartRateCharacteristic) .with(new HeartRateMeasurementDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
.with(new ContinuousGlucoseMeasurementDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { .with(new CGMSpecificOpsControlPointDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { .with(new RecordAccessControlPointDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
.with(new TemplateDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {