0

As you all might be aware the Android L has introduced a new feature called battery saver mode. I want direct the user from my app to that specific activity in the Settings page. How should I go about doing that?

E.g.: For starting a "Data Usage Activity" in settings page, I do this

Intent i = new Intent();
i.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings$DataUsageSummaryActivity"));
startActivityForResult(i, 0);

How can I do something similar for going to the Battery saver page? Settings -> Battery -> (Options on top right) -> Battery Saver

Thanks

user2453055
  • 975
  • 1
  • 9
  • 19

1 Answers1

3
Intent battSaverIntent = new Intent();
battSaverIntent.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings$BatterySaverSettingsActivity"));
startActivityForResult(battSaverIntent, 0);

That worked for me.

But be aware that this hardcoded string is not from Android Settings, so this shortcut might change, I suppose.

EDIT:

Now the ACTION has been made visible in the Android Settings (since API level 22). See here.

The action is now called ACTION_BATTERY_SAVER_SETTINGS

But beware that not all phones have this setting, so you need to guardcheck.

maksim
  • 176
  • 7
  • Awesome Thanks. Follow up question - Do you think we can change it programmatically ? Any other better practices to do the above? – user2453055 Jan 30 '15 at 19:41
  • I think you have to use this way for now. But it seems that soon there will be a way to use a predefined action for that (see [android source code , line 880](https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/provider/Settings.java)) called ACTION_BATTERY_SAVER_SETTINGS – maksim Jan 30 '15 at 19:55