PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Logger.i(TAG,"isIgnoringBatteryOptimizations = " + pm.isIgnoringBatteryOptimizations(getPackageName()));
//返回true未被优化,后台不会断网
if(!pm.isIgnoringBatteryOptimizations(getPackageName())){
startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
}
}
被加入到优化列表后,app在后台后会断网