We are developing an Android application that will be running on devices fitted with large batteries, so as to provide a longer running time between charges.
The problem is that the operating system does not read the power levels of the battery correctly and displays the low battery alert when there is a lot of charge left.
We have used a device for an extended period of time on a single battery charge and have been presented with the low battery alert approximately every 4 hours.
Is there any way of preventing this alert from appearing without having to root the device? Should it be possible to intercept the broadcast of the battery status and prevent the system from responding to it? Or is there anything that we can do to dismiss the battery warning as soon as it is displayed?
Our research so far has turned up nothing, as we suspect that this is not possible for security reasons. Hopefully one of you Android experts can confirm/deny our suspicions.
You have two options for dealing with those annoying "Battery is low" notifications in Android 9.0 Pie: You can either make them less intrusive, or outright disable them. I'll cover both method, starting with instructions for turning it off. Open the main Settings menu and select "Apps & notifications.".
However, understand that turning off this alert can be bittersweet. While you won't be bothered by the warning, besides actively checking your battery percentage, you will not know when your phone's battery is near depletion. However, Android Pie gives you more than just the ability to turn it off. You can also modify the alert to your liking.
Find the checkbox next to "Battery" and simply tap it to disable notifications. Select the back arrow in the upper-left corner to save your choice. When done correctly, you will see a message at the bottom of this menu stating "1 category deleted," indicating you turned off battery alerts. Option 2: Change How the Alert Appears
With modern Li-Ion batteries, it's not recommanded that you let your battery level go down below 20%. You're missing the point. I'm not. No, he is not missing the point. He answered your question. There is no way to avoid seeing those messages.
Let's dig into android source code:
BatteryService
There is a BatteryService
which is responsible for detecting when battery is low and if this happens it sends appropriate broadcast. The exact place that detects whether battery is low can be found here.
/* 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);
}
You won't be able to modify this behavior without rebuilding the Android OS. You could probably change mLowBatteryWarningLevel
value because its taken from com.android.internal.R.integer.config_lowBatteryWarningLevel
resource. But this requires root and will invalidate the signature of package where this resources is located.
StatusBarPolicy
So we now know that BatteryService
sends broadcast when batter gets low. But its clear from the source code that it does not show the warning. So next step was to find who actually shows that "low battery" warning. The class responsible for this is StatusBarPolicy
. Its not documented. Two pieces of code that can be interesting to you are onBatteryLow()
and showLowBatteryWarning()
functions.
But these two functions have no reasonable influence points from outter world. So no hacks will help you here also.
So it looks like this will be impossible without root. And even if you had root this would be challenging as you need to modify either resources or code (and then re-sign them).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With