¿Cómo obtener el nivel de batería después de conectarlo al dispositivo BLE?
Estoy desarrollando una aplicación en la que tengo que conectarme al dispositivo Bluetooth en Android 4.3.
Y quiero obtener el nivel de batería utilizandoBattery_Service yNivel de bateria.
public class BluetoothLeService extends Service {
private static final UUID Battery_Service_UUID = UUID.fromString("0000180F-0000-1000-8000-00805f9b34fb");
private static final UUID Battery_Level_UUID = UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb");
public void getbattery() {
BluetoothGattService batteryService = mBluetoothGatt.getService(Battery_Service_UUID);
if(batteryService == null) {
Log.d(TAG, "Battery service not found!");
return;
}
BluetoothGattCharacteristic batteryLevel = batteryService.getCharacteristic(Battery_Level_UUID);
if(batteryLevel == null) {
Log.d(TAG, "Battery level not found!");
return;
}
mBluetoothGatt.readCharacteristic(batteryLevel);
// What should I do that I can get the battery level ??
Log.d(TAG, "Battery level " + mBluetoothGatt.readCharacteristic(batteryLevel););
}
Pero el valor demBluetoothGatt.readCharacteristic(batteryLevel);
no es el valor del nivel de batería
¿Cómo leer la batería?