I have an app that needs to ignore doze mode and it asks the user to add it to not optimized apps list the usual way with:
Intent intent = new Intent();
String packageName = getPackageName();
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
startActivityForResult(intent, BATTERY_OPTIMIZATION_REQUEST);
In onActivityResult()
I check if he really added it to "Not optimized" list. So far so so good. My app starts its service which gets and holds a WAKE_LOCK and works permanently (Yes, I know that this drains the battery but my use case requires it).
My problem is that later the user may decide to remove the app from the "Not optimized" list.
My question(s):
Is there a broadcast which I can register for to get notified that battery optimization settings changed?
If not, is there another way to detect that battery optimization setting for my app changed than periodically check its state with
isIgnoringBatteryOptimizations()
Initially I thought that in this case the app will be stopped (as when permission is removed) but that is not the case.