1. 程式人生 > >android電量優化

android電量優化

方法1、儘量在wifi狀態下執行任務

方法2、請求加入白名單

if (!powerManager.isIgnoringBatteryOptimizations(context.getPackageName())) {
    //1、請求開啟電量優化
context.startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
    //2、顯示系統對話方塊
    context.startActivity(
new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
).setData(Uri.parse("package:" +getPackageName()));
)