public void readBatteryLevelCharacteristic() { if (isConnected()) { readCharacteristic(mBatteryLevelCharacteristic) .with(mBatteryLevelDataCallback) .fail((device, status) -> log(Log.WARN,"Battery Level characteristic not found")) .enqueue(); } }
/** * Reads the battery level from the device. * * @deprecated Use {@link #readCharacteristic(BluetoothGattCharacteristic)} instead. */ @SuppressWarnings("ConstantConditions") @Deprecated protected void readBatteryLevel() { Request.newReadBatteryLevelRequest().setManager(this) .with((device, data) -> { if (data.size() == 1) { final int batteryLevel = data.getIntValue(Data.FORMAT_UINT8, 0); log(Log.INFO, "Battery Level received: " + batteryLevel + "%"); mBatteryValue = batteryLevel; final BleManagerGattCallback callback = mGattCallback; if (callback != null) { callback.onBatteryValueReceived(mBluetoothGatt, batteryLevel); } mCallbacks.onBatteryValueReceived(device, batteryLevel); } }) .enqueue(); }
@Override protected void onDeviceReady() { super.onDeviceReady(); // Initialization is now ready. // The service or activity has been notified with TemplateManagerCallbacks#onDeviceReady(). // TODO Do some extra logic here, of remove onDeviceReady(). // Device is ready, let's read something here. Usually there is nothing else to be done // here, as all had been done during initialization. readCharacteristic(mOptionalCharacteristic) .with((device, data) -> { // Characteristic value has been read // Let's do some magic with it. if (data.size() > 0) { final Integer value = data.getIntValue(Data.FORMAT_UINT8, 0); log(LogContract.Log.Level.APPLICATION, "Value '" + value + "' has been read!"); } else { log(Log.WARN, "Value is empty!"); } }) .enqueue(); } };
super.initialize(); readCharacteristic(mBodySensorLocationCharacteristic) .with(new BodySensorLocationDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
.with(new CGMFeatureDataCallback() { @Override public void onContinuousGlucoseMonitorFeaturesReceived(@NonNull final BluetoothDevice device, @NonNull final CGMFeatures features, .with(new CGMStatusDataCallback() { @Override public void onContinuousGlucoseMonitorStatusChanged(@NonNull final BluetoothDevice device, @NonNull final CGMStatus status, final int timeOffset, final boolean secured) {
assertTrue(data.length <= MTU - 3); }) .with((device, data) -> {