gpt4 book ai didi

android - 当 android 触发 ACTION_BATTERY_LOW

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:13:51 25 4
gpt4 key购买 nike

在我的应用程序中,我想在电池电量不足时做一些事情。当电池电量低时,android 会触发 ACTION_BATTERY_LOW,当电池再次达到良好状态时,它会触发 intent ACTION_BATTERY_OKAY。因此,我对此有三个问题:

1.android 在多少电池百分比下实际触发 ACTION_BATTERY_LOW

2.如果电池电量更低,它会重复触发相同的事件吗?

3.我们可以配置 android 触发 ACTION_BATTERY_LOW intent 的电池百分比吗?

我比较关心第三点。

最佳答案

不,您无法设置何时发送 ACTION_BATTERY_LOW 阈值。这是由 Android ROM 指定的系统级 Intent 。这是在电池服务中设置值的代码:

mLowBatteryWarningLevel = mContext.getResources().getInteger(
com.android.internal.R.integer.config_lowBatteryWarningLevel);

Battery Service更新方法中Android系统代码截取如下代码:

/* The ACTION_BATTERY_LOW broadcast is sent in these situations:
* - is just un-plugged (previously was plugged) and battery level is
* less than or equal to WARNING, or
* - is not plugged and battery level falls to WARNING boundary
* (becomes <= mLowBatteryWarningLevel).
*/
final boolean sendBatteryLow = !plugged
&& mBatteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN
&& mBatteryLevel <= mLowBatteryWarningLevel
&& (oldPlugged || mLastBatteryLevel > mLowBatteryWarningLevel);

sendIntent();

// Separate broadcast is sent for power connected / not connected
// since the standard intent will not wake any applications and some
// applications may want to have smart behavior based on this.
Intent statusIntent = new Intent();
statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
if (mPlugType != 0 && mLastPlugType == 0) {
statusIntent.setAction(Intent.ACTION_POWER_CONNECTED);
mContext.sendBroadcast(statusIntent);
}
else if (mPlugType == 0 && mLastPlugType != 0) {
statusIntent.setAction(Intent.ACTION_POWER_DISCONNECTED);
mContext.sendBroadcast(statusIntent);
}

if (sendBatteryLow) {
mSentLowBatteryBroadcast = true;
statusIntent.setAction(Intent.ACTION_BATTERY_LOW);
mContext.sendBroadcast(statusIntent);

关于android - 当 android 触发 ACTION_BATTERY_LOW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11970185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com