Skip to content

Instantly share code, notes, and snippets.

@turnerd18
Created April 22, 2020 21:25
Show Gist options
  • Select an option

  • Save turnerd18/6c07bb17cf65b669fc1ab0ad4eef3a86 to your computer and use it in GitHub Desktop.

Select an option

Save turnerd18/6c07bb17cf65b669fc1ab0ad4eef3a86 to your computer and use it in GitHub Desktop.

Revisions

  1. turnerd18 created this gist Apr 22, 2020.
    10 changes: 10 additions & 0 deletions Android power optimization exclusion
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    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);
    }
    }