I have a mileage logbook app which does GPS tracking and is able to establish a OBDII connection to a car in background.
Now I want to show a Popup which informs the users if my app is not whitelisted in doze since this may stop my background (actually foreground) services...
I do:
String PACKAGE_NAME = getApplicationContext().getPackageName();
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
boolean status = false;
status = pm.isIgnoringBatteryOptimizations(PACKAGE_NAME);
if (!status) {
// show popup
}
but PowerManager.isIgnoringBatteryOptimizations always returns 'true' even if it is removed from 'Not optimized apps' again. Only if I uninstall the app 'false' is returned again... Tested on Galaxy Note 8 (Android 8.0) and Emulator 8.1
Question is simple: Is this a bug? Or how to remove the app from whitelist so that PowerManager.isIgnoringBatteryOptimizations is returnung 'false' again?