//BE CAREFUL WITH THIS - App may get suspended from Google Play without prior notice for //requesting REQUEST_IGNORE_BATTERY_OPTIMIZATIONS @RequiresApi(api = Build.VERSION_CODES.M) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String packageName = getPackageName(); Intent intent = new Intent(); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations(packageName)) { //do stuff } else { intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:"+packageName)); //OR //Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS to see list of white listed apps startActivity(intent); } }