Get Battery Level
Summary
- Internal name:
GetBatteryLevel - Category: Battery
- Purpose: Read the current battery charge level as a percentage. Returns a value between 0 and 100.
- Task type: Normal
Compatibility
-
Minimum AndroMate version:
1.1.0 -
Maximum AndroMate version:
1.1.0 -
Minimum Android:
Android 13 (API 33) -
Maximum Android tested:
Android 16 (API 36) -
Required permissions: None
Detailed description
The Get Battery Level task reads the current battery charge level from the Android battery broadcast (ACTION_BATTERY_CHANGED). The level is expressed as a percentage from 0 (empty) to 100 (full) and is stored as a string in value_output.
No special permissions are required — ACTION_BATTERY_CHANGED is a protected system broadcast that any app can receive without declaring permissions.
Input parameters
This task has no input parameters.
Output parameters
| Field | Type | Trigger condition | Android Compatibility | AndroMate Compatibility | Default |
|---|---|---|---|---|---|
value_output |
String | Always on success — battery percentage as a numeric string (e.g. "85") |
Android 13 (API 33) → Android 16 (API 36) | 1.1.0 → 1.1.0 | <ANDROMATE_NULL_VALUE> |
Exceptions
This task does not throw exceptions. If the battery level cannot be read, Android returns -1, which is stored as "-1" in value_output.
Execution flowchart
flowchart TD
Start([▶ GetBatteryLevel]) --> Register[📡 Register ACTION_BATTERY_CHANGED\none-shot receiver]
Register --> ReadLevel[🔋 Read EXTRA_LEVEL / EXTRA_SCALE\ncompute percentage]
ReadLevel --> StoreResult[💾 Set value_output\nStrTaskResult]
StoreResult --> LogReport[📋 Log report]
LogReport --> Success([✅ StrTaskResult])
style Start fill:#e3f2fd
style Success fill:#c8e6c9
style Register fill:#fff9c4
style ReadLevel fill:#f3e5f5
style StoreResult fill:#c8e6c9
How it works:
- Register battery receiver: registers a one-shot receiver for
ACTION_BATTERY_CHANGED— no permission required - Read level: extracts
EXTRA_LEVELandEXTRA_SCALEfrom the battery intent and computes(level * 100) / scale - Store result: sets
value_outputwith the percentage string - Result: returns
StrTaskResult
Code examples
Example 1 — Read battery level into a variable
{
"GetBatteryLevel": [
{
"id": "1",
"title": "Read battery percentage",
"value_output": "$battery_level"
}
]
}
Example 2 — Read battery level without storing
Input parameter details
This task has no input parameters.
Output parameter details
value_output — Battery level percentage
Stores the battery level as a numeric string in the specified workflow variable.
- Range:
"0"(empty) to"100"(full) - Example:
"85"means 85 % battery remaining - If the level cannot be determined, Android returns
-1