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

Minimal android foreground service killed on high-end phone

A service started by startForeground belongs to the second most important group visible process: A visible process is doing work that the user is currently aware of, so killing it would have a noticeable negative impact on the user experience. A process is considered visible in the following conditions: It is running an Activity that … Read more