Checking for Power Saver Mode programmatically

前端 未结 5 687
旧时难觅i
旧时难觅i 2020-12-01 21:44

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

5条回答
  •  难免孤独
    2020-12-01 22:23

    This answer is only for the Samsung power saver mode, since as usual Samsung still chooses to mess with the standard APIs.

    iKeirNez posted an excellent answer that confirmed a suspicion of mine. This still happens on lower end devices you can buy that have 5.1.1. I have a list compiled of the devices which I know of that suffer from a camera crash when on power saving mode, but I have not yet checked for all the possible keys that relate to power saving mode.

    I know about these ones so far:

    content://settings/system/powersaving_switch

    content://settings/system/psm_switch

    You can register a ContentResolver and listen for changes OR you can check it when necessary:

    final String result = Settings.System.getString(getContentResolver(), "psm_switch");
    Log.v("Debug", "Powersaving active: " + TextUtils.equals(result, "1"));
    

提交回复
热议问题