如何在Android“小米MIUI”设备中检测“省电模式”?
我使用此代码检测Android 5,6中的“省电模式”:
PowerManager powerManager = (PowerManager)
getActivity().getSystemService(Context.POWER_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& powerManager.isPowerSaveMode())
{
//power saving mode
}
但它在“小米MIUI”设备中无效。
答案 0 :(得分:0)
对于Xiaomi
ROM,系统设置名称POWER_SAVE_MODE_OPEN
将用于保存省电模式,因此我们可以通过系统设置api使用此名称来检测它是开启还是关闭。< /p>
android.provider.Settings.System#getInt(android.content.ContentResolver, java.lang.String, int)
为了监控省电模式的变化,我们可以为 miui.intent.action.POWER_SAVE_MODE_CHANGED
注册一个意图接收器,或者为 uri ContentObserver
使用 content://settings/system/POWER_SAVE_MODE_OPEN
查看此 answer 中的详细代码实现。
答案 1 :(得分:0)
private void isPowerSaveModeHuaweiXiaomi(){
if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")) {
try {
int value = android.provider.Settings.System.getInt(getContext().getContentResolver(), "POWER_SAVE_MODE_OPEN");
} catch (Settings.SettingNotFoundException e) {
Log.d("Valor modo bateria:", "Error");
}
}else if (Build.MANUFACTURER.equalsIgnoreCase("Huawei")){
try {
int value = android.provider.Settings.System.getInt(getContext().getContentResolver(), "SmartModeStatus");
} catch (Settings.SettingNotFoundException e) {
Log.d("Valor modo bateria:", "Error");
}
}
}