【问题标题】:How to open Battery saver activity in android L如何在 android L 中打开省电模式
【发布时间】:2015-03-31 10:59:43
【问题描述】:

在 Android 的 Lollipop 版本中,我们在 Settings->Battery->(in action overflow)Battery saver 活动中有省电活动。我想以编程方式打开此活动。我必须使用哪个意图?

提前致谢!!!

【问题讨论】:

    标签: android android-intent android-5.0-lollipop


    【解决方案1】:

    尝试以下意图:

    Intent batterySaverIntent=new Intent(Settings.ACTION_BATTERY_SAVER_SETTINGS);
    startActivity(batterySaverIntent);
    

    或者

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

    有关文档,请打开以下链接here

    【讨论】:

    • 是否有可能知道以编程方式为此设置了什么样的设置?
    • @SabidHabib 文档中提到 “在某些情况下,可能不存在匹配的 Activity,因此请确保防范这种情况。”
    【解决方案2】:

    使用documented action string

    startActivity(new Intent(Settings.ACTION_BATTERY_SAVER_SETTINGS))
    

    请注意,此操作字符串是 API 级别 22 的新内容。欢迎您尝试在旧设备上使用它,但不太可能有支持它的活动。

    【讨论】:

    • 不适用于华为和小米
    猜你喜欢
    • 1970-01-01
    • 2019-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多