Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
884 views
in Technique[技术] by (71.8m points)

java - Checking for Power Saver Mode programmatically

I have written an app (AutoWifiSwitch) and one of the features I plan to add is automatically disabling the wifi scanning service in my app if power saving mode is enabled.

I know Android L is supposed to have Battery Saving implemented (previously HTC and Samsung would add the features themselves to the software). Presumably this now means Google will have added some sort of API for it. Ideally there would be a new action added so I could listen for that.

I would also like to know if the above is possible with HTC/Samsung APIs and if so, how do I use them.

I've been searching everywhere for the above questions but had absolutely no luck, the app SecureSettings (an addon for Tasker) is able to hook into the HTC/Samsung APIs to enable the power saver anyway, I'm not quite sure how they do it.

Edit: The power saver value can be gotten from the PowerManager in Android L, not sure if there is an Action for it though.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
boolean powerSaveMode = powerManager.isPowerSaveMode();

Docs: developer.android.com/.../PowerManager#isPowerSaveMode()

Added in API level 21 (Android 5.0)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...