当机器人火灾ACTION_BATTERY_LOW [英] When android fires ACTION_BATTERY_LOW

查看:252
本文介绍了当机器人火灾ACTION_BATTERY_LOW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我想做点什么,当电池电量低。当电池电量低的Andr​​oid火灾 ACTION_BATTERY_LOW 键,当电池再次达到其良好的健康它触发的意图 ACTION_BATTERY_OKAY 。所以,我有一个关于这三个问题:

In my application, I want to do something when the battery is low. When battery is low android fires ACTION_BATTERY_LOW and when the battery again reaches to its good health it fires intent ACTION_BATTERY_OKAY. So, I have three questions regarding this:

1.At什么电池百分比机器人实际上触发 ACTION_BATTERY_LOW

1.At what battery percentage android actually fires ACTION_BATTERY_LOW?

2.Does它多次触发同样的事件,如果电池电量甚至更低?

2.Does it fire that same event repeatedly if the battery gets even lower?

3,可我们配置的电池百分比在该机器人将激发 ACTION_BATTERY_LOW 意图是什么?

3.Can we configure the battery percentage at which android will fire ACTION_BATTERY_LOW intent?

我更关心的是第三点。

推荐答案

没有,你不能设置时ACTION_BATTERY_LOW门槛将被发送。这是由Android的ROM指定一个系统级的意图。这里是code其中它设置在电池服务的值:

No, you cannot set when the ACTION_BATTERY_LOW threshold will be sent. That is a system level intent that is specified by the Android ROM. Here is the code where it sets the value in the Battery Service:

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

见code以下是从Android系统code切断电池服务的更新方法:

See the code below which is cut from the Android system code in the update method of the Battery Service:

/* 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);

这篇关于当机器人火灾ACTION_BATTERY_LOW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆