I’m making some optimizations on my app for devices with "power saving mode" enabled.
Here's the sample code:
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();
}
Huawei's cloud debugging platform
https://developer.huawei.com/consumer/cn/console#/openCard/AppService/1045
log outputs
enable normal power save mode
disable normal power save mode
enable ultra power save mode
An intent was sent but don't know if it's public.
So how can I detect "Ultra power save mode" in Huawei devices with Settings.System.getInt
method(or their own api)?
btw, does Sony/Samsung or others has their own properties for this?
Thx