Skip to content

Instantly share code, notes, and snippets.

@MrCrambo
Created July 1, 2020 09:19
Show Gist options
  • Save MrCrambo/fa81999e7fa51f61bf3809150df4e4db to your computer and use it in GitHub Desktop.
Save MrCrambo/fa81999e7fa51f61bf3809150df4e4db to your computer and use it in GitHub Desktop.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent intent = new Intent();
String packageName = getPackageName();
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
if (!pm.isIgnoringBatteryOptimizations(packageName)) {
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment