Search code examples
androidandroid-intentstart-activitypowermanagerbattery-saver

Android L Battery Saver Mode - startActivityforResult


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


Solution

  • 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.