Get Battery Voltage
Summary
- Internal name:
GetBatteryVoltage - Category: Battery
- Purpose: Read the current battery voltage in millivolts (mV). Useful for hardware diagnostics and battery health monitoring.
- 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 Voltage task reads the current battery voltage from the Android battery broadcast (ACTION_BATTERY_CHANGED). The voltage is returned in millivolts as a numeric string (e.g. "4200" for 4.2 V) and stored in value_output.
No special permissions are required — ACTION_BATTERY_CHANGED is a protected system broadcast available to all apps.
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 voltage in millivolts as a numeric string (e.g. "4200") |
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 voltage cannot be read, Android returns 0, which is stored as "0" in value_output.
Execution flowchart
flowchart TD
Start([▶ GetBatteryVoltage]) --> Register[📡 Register ACTION_BATTERY_CHANGED\none-shot receiver]
Register --> ReadVoltage[⚡ Read EXTRA_VOLTAGE\nin millivolts]
ReadVoltage --> 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 ReadVoltage fill:#f3e5f5
style StoreResult fill:#c8e6c9
How it works:
- Register battery receiver: registers a one-shot receiver for
ACTION_BATTERY_CHANGED - Read voltage: extracts
EXTRA_VOLTAGEin millivolts - Store result: sets
value_outputwith the voltage string in mV - Result: returns
StrTaskResult
Code examples
Example 1 — Read battery voltage
{
"GetBatteryVoltage": [
{
"id": "1",
"title": "Read battery voltage",
"value_output": "$battery_voltage"
}
]
}
Input parameter details
This task has no input parameters.
Output parameter details
value_output — Battery voltage in mV
Stores the battery voltage as a numeric string in millivolts.
- Example:
"4200"means 4.2 V (4200 mV) - Typical range:
3200mV (nearly empty) to4350mV (fully charged), varies by battery chemistry - Divide by
1000in a workflow to convert to volts