Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS in not firing

Tags:

android

I just wanted to disable battery optimization in my app. I used the below snippet

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);

The snippet is firing but not showing any option to disable battery optimization. And not showing any error in the log. Please help

like image 372
Jijith J Avatar asked Sep 14 '25 23:09

Jijith J


1 Answers

Ensure you have the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission defined in your AndroidManifest.xml

like image 182
Jon Douglas Avatar answered Sep 17 '25 14:09

Jon Douglas