2

我正在为启用“省电模式”的设备对我的应用程序进行一些优化。

这是示例代码:

import android.content.Context;
import android.os.PowerManager;
import android.provider.Settings;

//for MIUI
private boolean isPowerSaveModeMiui(Context context) throws Settings.SettingNotFoundException{
//available for normal or ultra power save mode
//In recent tests, miui use PowerManager.isPowerSaveMOde() on Android S
    return Settings.System.getInt(
        context.getContentResolver(),
        "POWER_SAVE_MODE_OPEN"
    )==1;
}

//for Huawei(EMUI/HARMONY)
private boolean isPowerSaveModeHuawei(Context context) throws Settings.SettingNotFoundException{
    //this is only available for normal power save mode
    //when ultra power save mode is enabled or power save mode is disabled,it returns 1
    return Settings.System.getInt(
        context.getContentResolver(),
        "SmartModeStatus"
    )==4;
    //I can't find any docs for this
}

//for other systems which is api21+
private boolean isPowerSaveMode(Context context){
    return ((PowerManager)context.getSystemService("power"))
        .isPowerSaveMode();
}

华为云调试平台
https://developer.huawei.com/consumer/cn/console#/openCard/AppService/1045


日志输出
启用正常省电模式
省电模式开启:

禁用正常省电模式
省电模式关闭:

启用超级省电模式 发送了一个意图,但不知道它是否公开。


那么如何通过Settings.System.getInt方法(或他们自己的api)检测华为设备中的“超省电模式”?
顺便说一句,索尼/三星或其他公司有自己的属性吗?
谢谢

4

0 回答 0