如何读取电池的充电次数?次数、电池

2023-09-06 01:04:18 作者:再忧傷也要用微笑帶過

如上所述,我想获得的电池chrarges总数。 我已经只能用batery意向书显示我等级,电压,温度......但不是总负载循环。

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.

推荐答案

您可以注册一个Intent接收器来接收广播的ACTION_BATTERY_CHANGED:的http://developer.android.com/reference/android/content/Intent.html#ACTION_BATTERY_CHANGED.

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.

广播事件:这是一个包含了充电状态,水平,以及其他关于电池信息的持久广播。请参见 BatteryManager 有关意图的内容的文件。

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.

您可以的没有的通过舱单申报组件收到此,只因为它明确地注册与 Context.registerReceiver()。请参阅 ACTION_BATTERY_LOW ACTION_BATTERY_OKAY ACTION_POWER_CONNECTED ACTION_POWER_DISCONNECTED 为发送,并可以通过舱单接收机接收不同的电池相关的节目。

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.

这是一个只能由系统发送的受保护的意图。 常数值: android.intent.action.BATTERY_CHANGED

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