Home » Android » java – How to read the number of battery charges?

java – How to read the number of battery charges?

Posted by: admin May 14, 2020 Leave a comment

Questions:

as mentioned above, I want to get the total number of battery chrarges.
The batery Intent I’m already using only shows me Level, Voltage, Temperature … but not the total loading cycles.

How to&Answers:

You can register an Intent receiver to receive the broadcast for ACTION_BATTERY_CHANGED: http://developer.android.com/reference/android/content/Intent.html#ACTION_BATTERY_CHANGED.

Broadcast Action: This is a sticky broadcast containing the charging state, level, and other information about the battery. See BatteryManager for documentation on the contents of the Intent.

You can not receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver(). See ACTION_BATTERY_LOW, ACTION_BATTERY_OKAY, ACTION_POWER_CONNECTED, and ACTION_POWER_DISCONNECTED for distinct battery-related broadcasts that are sent and can be received through manifest receivers.

This is a protected intent that can only be sent by the system.
Constant Value: “android.intent.action.BATTERY_CHANGED