更新 BatteryOptimizationUtil.java
parent
4cd24ebe02
commit
08403b9109
|
|
@ -32,19 +32,22 @@ public class BatteryOptimizationUtil {
|
|||
* 请求将应用加入电池优化白名单。
|
||||
*/
|
||||
public static void requestIgnoreBatteryOptimization(Context context) {
|
||||
if (isAppIgnoringBatteryOptimizations(context)) {
|
||||
Timber.d("已在忽略电池优化白名单");
|
||||
return;
|
||||
}
|
||||
Timber.d("请求电池优化白名单");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
String packageName = context.getPackageName();
|
||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
if (pm != null && !pm.isIgnoringBatteryOptimizations(packageName)) {
|
||||
Intent intent = new Intent();
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
||||
intent.setData(Uri.parse("package:" + packageName));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 添加FLAG_ACTIVITY_NEW_TASK标志
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue