/** * 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(); }
case BluetoothDevice.BOND_NONE: if (previousBondState == BluetoothDevice.BOND_BONDING) { mCallbacks.onBondingFailed(device); log(Log.WARN, "Bonding failed"); if (mRequest != null) { // CREATE_BOND request mCallbacks.onBondingRequired(device); return; case BluetoothDevice.BOND_BONDED: log(Log.INFO, "Device bonded"); mCallbacks.onBonded(device); if (mRequest != null && mRequest.type == Request.Type.CREATE_BOND) { mRequest.notifySuccess(device);
mConnectionState = BluetoothGatt.STATE_DISCONNECTING; log(Log.VERBOSE, mConnected ? "Disconnecting..." : "Cancelling connection..."); mCallbacks.onDeviceDisconnecting(mBluetoothGatt.getDevice()); final boolean wasConnected = mConnected; log(Log.DEBUG, "gatt.disconnect()"); mCallbacks.onDeviceDisconnected(mBluetoothGatt.getDevice());
mCallbacks.onDeviceConnecting(device); log(Log.DEBUG, "gatt.connect()"); mBluetoothGatt.connect(); mGattCallback.setHandler(mHandler); log(Log.VERBOSE, connectRequest.isFirstAttempt() ? "Connecting..." : "Retrying..."); mCallbacks.onDeviceConnecting(device); mConnectionTime = SystemClock.elapsedRealtime(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
/** * 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(); }