Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if Android Lollipop battery saver is on

Tags:

Android Lollipop introduced a battery saver mode that can be turned on at any time, and turns on by default when the battery is at 15% or lower. This poses a problem for my app, since the battery saver disables animations that provide crucial information. (Just to give context, my app allows users to configure an Android Wear watch face; when they save a new "theme," I animate the theme moving to a button on the action bar so that they know where it was saved to. When animations are disabled by the battery saver, nothing happens when they hit save, which I think would be confusing.)

So, is there a way to programmatically determine whether the battery saver is on? That way I can provide an alternative to the animation(s) such as displaying a Toast.

like image 865
Tony Wickham Avatar asked Aug 08 '15 17:08

Tony Wickham


People also ask

Does battery saver turn on automatically?

Battery saver mode changes certain settings to conserve battery power until you can recharge your phone. If you turn Battery saver mode On, it will automatically activate when the battery charge level drops to the level you set.

How do I turn battery saver mode off?

Go to your phone settings. Tap Battery. Make sure that Battery Saver & Super Battery Saver are toggled OFF.


1 Answers

Take a look at power manager

It has a method isPowerSaveMode() that will tell you if battery saver is on

Example code:

PowerManager powerManager = (PowerManager)     getActivity().getSystemService(Context.POWER_SERVICE); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP         && powerManager.isPowerSaveMode()) {     // Animations are disabled in power save mode, so just show a toast instead.     Toast.makeText(mContext, getString(R.string.toast), Toast.LENGTH_SHORT).show(); } 
like image 159
Andrew Brooke Avatar answered Oct 18 '22 10:10

Andrew Brooke