Obtain the battery information of the Android device.

Source: Internet
Author: User

1. To obtain the battery information of the Android device, register a BroadCastReceiver whose Action is Intent. ACTION_BATTERY_CHANGED.

2. In the BroadcastReceiver onReceive () event, the received Intent. ACTION_BATTERY_CHANGED includes the following information:

"Present" (boolean )...
"Level" (int )... Remaining battery capacity
"Scale" (int )... Maximum battery value, usually 100.
"Icon-small" (int )... Icon ID.
"Voltage" (int )... Battery voltage (volt)
"Temperature" (int )... The temperature of the battery, measured in 0.1 degrees. For example, 197 indicates 19.7 degrees.
"Technology" (String )... Battery type, such as Li-ion.

"Plugged" (int )... Charging method:
BatteryManager. BATTERY_PLUGGED_AC: AC is charged.
BatteryManager. BATTERY_PLUGGED_USB: USB charging.

"Status" (int )... Battery status:
BatteryManager. BATTERY_STATUS_CHARGING: the charging status.
BatteryManager. BATTERY_STATUS_DISCHARGING: discharge status.
BatteryManager. BATTERY_STATUS_NOT_CHARGING: not full.
BatteryManager. BATTERY_STATUS_FULL: fully charged.
BatteryManager. BATTERY_STATUS_UNKNOWN: Unknown Status.


"Health" (int )... Health status:
BatteryManager. BATTERY_HEALTH_GOOD: The status is good.
BatteryManager. BATTERY_HEALTH_DEAD: the battery has no power.
BatteryManager. BATTERY_HEALTH_OVER_VOLTAGE: the battery voltage is too high.
BatteryManager. BATTERY_HEALTH_OVERHEAT: The BatteryManager is overheated.
BatteryManager. BATTERY_HEALTH_UNKNOWN: Unknown Status.

 

BatteryActivity batteryReceiver = BatteryReceiver level = arg1.getIntExtra ("level", 0 "Battery", "remaining Battery power:" + level + "%"

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.