Skip to content

Get Battery Status

Summary

  • Internal name: GetBatteryStatus
  • Category: Battery
  • Purpose: Read the current battery charging status. Returns a human-readable string such as Charging, Discharging, Full, or Not Charging.
  • 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 Status task reads the current charging status from the Android battery broadcast (ACTION_BATTERY_CHANGED). The result is a descriptive string 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 — one of Charging, Discharging, Full, Not Charging, Unknown Android 13 (API 33) → Android 16 (API 36) 1.1.0 → 1.1.0 <ANDROMATE_NULL_VALUE>

Possible output values

Value Description
Charging The device is currently charging
Discharging The battery is draining — not connected to a charger
Full The battery is fully charged
Not Charging Connected to a charger but not charging (e.g. damaged battery)
Unknown The status could not be determined

Special variables

When comparing the output of this task in a condition (e.g. Compare Strings), you can use the built-in AndroMate special variables instead of hardcoded strings. This avoids typos and keeps your workflow readable.

Special variable Resolved value
${BATTERY_STATUS_CHARGING} "Charging"
${BATTERY_STATUS_DISCHARGING} "Discharging"
${BATTERY_STATUS_FULL} "Full"
${BATTERY_STATUS_NOT_CHARGING} "Not Charging"
${BATTERY_STATUS_UNKNOWN} "Unknown"

Example — compare $battery_status against ${BATTERY_STATUS_CHARGING} in a Compare Strings task instead of typing "Charging" manually.


Exceptions

This task does not throw exceptions. If the status cannot be read, "Unknown" is stored in value_output.


Execution flowchart

flowchart TD
    Start([▶ GetBatteryStatus]) --> Register[📡 Register ACTION_BATTERY_CHANGED\none-shot receiver]

    Register --> ReadStatus[🔋 Read EXTRA_STATUS\nmap to string]

    ReadStatus --> 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 ReadStatus fill:#f3e5f5
    style StoreResult fill:#c8e6c9

How it works:

  1. Register battery receiver: registers a one-shot receiver for ACTION_BATTERY_CHANGED
  2. Read status: extracts EXTRA_STATUS and maps it to a descriptive string
  3. Store result: sets value_output with the status string
  4. Result: returns StrTaskResult

Code examples

Example 1 — Read battery status

{
  "GetBatteryStatus": [
    {
      "id": "1",
      "title": "Check battery status",
      "value_output": "$battery_status"
    }
  ]
}

Input parameter details

This task has no input parameters.


Output parameter details

value_output — Battery charging status

Stores the charging status as a descriptive string in the specified workflow variable.

  • One of Charging, Discharging, Full, Not Charging, Unknown
  • If the status cannot be determined, "Unknown" is stored
  • Tip: compare against the ${BATTERY_STATUS_*} special variables instead of hardcoded strings

Complete JSON example

{
  "GetBatteryStatus": [
    {
      "id": "1",
      "title": "Get Battery Status",
      "value_output": "$BATTERY_STATUS"
    }
  ]
}