Check battery level status
Instead of getting exact battery percentage, you can get battery level status described by device_battery_level_e enum, which gives you practical information about how critical the current battery level is (is the battery full, high, low, critical or empty).
#include <device/battery.h>
#include <dlog.h> //for logging purposes
device_battery_level_e battery_status = DEVICE_BATTERY_LEVEL_FULL;
if (device_battery_get_level_status(&battery_status) == DEVICE_ERROR_NONE)
{
if (battery_status == DEVICE_BATTERY_LEVEL_EMPTY ||
battery_status == DEVICE_BATTERY_LEVEL_CRITICAL ||
battery_status == DEVICE_BATTERY_LEVEL_LOW )
{
LOGI("Battery level is low! Connect the phone to the charger!");
}
else
{
LOGI("Battery level is OK!");
}
}