Is there a way to suppress a low battery warning on Android devices or reject a pop-up warning?

We are developing an Android application that will run on devices with larger batteries to provide a longer time between charges.

The problem is that the operating system does not read the battery power levels correctly and displays a warning about low battery when there is a lot of charge left.

We used the device for a long period of time with one battery charge and were presented with a warning about low battery approximately every 4 hours.

Is there a way to prevent this warning from appearing without having to start the device? Should the battery status broadcast be intercepted and prevent the system from responding to it? Or is there anything we can do to clear the battery warning as soon as it displays?

Our research has so far failed, because we suspect that this is not possible for security reasons. I hope one of you, Android experts, can confirm / refute our suspicions.

+5
source share
1 answer

Let dig into the Android source code:


Battery service

BatteryService, , , , . , , .

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

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

, Android. , mLowBatteryWarningLevel, com.android.internal.R.integer.config_lowBatteryWarningLevel. root , .


StatusBarPolicy

, , BatteryService , . , . , , , " ". , , StatusBarPolicy. . onBatteryLow() showLowBatteryWarning().

. , .


, , root. root, , ( ).

+7

All Articles