我正在为启用“省电模式”的设备对我的应用程序进行一些优化。
这是示例代码:
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)检测华为设备中的“超省电模式”?
顺便说一句,索尼/三星或其他公司有自己的属性吗?
谢谢