I have gingerbread(2.3.6) phone with dropbear installed. I usually access my phone over wifi & run commands in putty. I want to get Battery status & percentage in terminal. Is there any command or program to obtain battery info ?

  • See if there is/are any system service(s) having the string "battery". For example, dumpsys battery (needs root) does the job in Android 4.2.1. Or, see if /sys/class/power_supply/battery/BatteryAverageCurrent/uevent give you anything. See my answer here for more: How can profile (log the charging and discharging current for some time period) my battery? – Firelord Nov 5 '15 at 8:24
  • Yup.. "dumpsys battery" worked for me. It returned following info :: ` Current Battery Service state: AC powered: true USB powered: false status: 2 health: 2 present: false level: 10 scale: 100 voltage:3 temperature: 420 technology: Li-ion` – jonny789 Nov 5 '15 at 8:59

Query the system service battery (possibly requires root access)

dumpsys battery

Output would be like

Current Battery Service state:
  AC powered: false
  USB powered: true
  Wireless powered: false
  status: 2
  health: 2
  present: true
  level: 70
  scale: 100
  temperature: 260
  technology: Li-ion

level: 70 is the battery percentage here.

Not sure about Android 2.3 but this is relevant for at least Android 4.2.1 and above:

(Prefix adb shell next to every command to run the command using adb.)

  • This would give you a list of all the historical broadcasts as well as the sticky ones:

    dumpsys activity broadcasts

    In the output search:

    Sticky action android.intent.action.BATTERY_CHANGED:

    The lines next to it, until you encounter a new sticky broadcast, are useful to us. In my devices, they are listed as:

    Intent: act=android.intent.action.BATTERY_CHANGED flg=0x60000010
    Bundle[{icon-small=17302819, present=true, scale=100, level=100, technology=Li-ion, status=4, voltage=4140, invalid_charger=0, plugged=0, health=2, temperature=200}]

    Assuming that your Android has grep utility, you can shorten the search by using:

    dumpsys activity broadcasts | grep -A2 "Sticky action android.intent.action.BATTERY_CHANGED:"

    (Source: Monitoring the Battery Level and Charging State)

  • Alternative: it is possible to query the battery info from /sys or I should say the Linux kernel.

    /sys/class/power_supply/battery/ has some files with useful information. The file named capacity is equivalent to current battery percentage. You can get an accumulated info from uevent file as well.

    For more and related info, read my answer here.

  • 1
    +1 to that: I can fully confirm the first approach (via dumpsys), which is exactly what I successfully use with Adebar, tested on multiple devices. So your command will probably be something like dumpsys battery | grep "level:" | awk '{ print $2 }'. However, I've never tested that with Android versions <4. – Izzy Nov 5 '15 at 11:51
  • Neither did I test on <4, but posted it because OP confirmed it. :) Waiting for somebody to verify the second approach here. – Firelord Nov 5 '15 at 12:04
  • 1
    Looks like I can confirm this for cat /sys/class/power_supply/battery/capacity at least on Android 4.1. As sysfs is a Linux feature already available for quite a while, this should work on other/previous Android versions as well. Other "files" in the context of the question: health (e.g. "Good"), status ("Full"), temp (centi-degrees Celsius? here: "300"). Just figuring the current power source might prove a bit tricky :) – Izzy Nov 5 '15 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.