Skip to content

Instantly share code, notes, and snippets.

@turnerd18
Created April 22, 2020 21:25
Show Gist options
  • Save turnerd18/6c07bb17cf65b669fc1ab0ad4eef3a86 to your computer and use it in GitHub Desktop.
Save turnerd18/6c07bb17cf65b669fc1ab0ad4eef3a86 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