How do I properly fire ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS intent?

Intent intent = new Intent(); String packageName = context.getPackageName(); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations(packageName)) intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); else { intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse(“package:” + packageName)); } context.startActivity(intent); Kotlin val intent = Intent() val pm : PowerManager = getSystemService(Context.POWER_SERVICE) as PowerManager if (pm.isIgnoringBatteryOptimizations(context.packageName)) { intent.action = Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS } else { intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS intent.data = Uri.parse(“package:${context.packageName}”) } context.startActivity(intent) … Read more

How does doze mode affect background/foreground services, with/without partial/full wakelocks?

Processes which have a current running foreground service are supposed to be unaffected by Doze. Bound/unbound, started/not-started, and wakelocks do not affect this whitelisting process. However, there is an issue on Android M devices where foreground services are not properly whitelisted when the foreground service is the in the same process as the top activity … Read more