I\'m developing an app that should alert an user if is near a place. and of course have to do that also if the phone is in idle. With DOZE now I understood that I have to whitel
To open list of apps for choosing battery optimization you can use this code sample:
private void openPowerSettings(Context context) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
context.startActivity(intent);
}
It doesn't need to have
permission, so it should be ok to publish it to Google Play (for details please check this thread and comments to this question).
NOTE
Adding this line
intent.setData(Uri.parse("package:" + mContext.getPackageName()));
will cause crash "Fatal Exception: android.content.ActivityNotFoundException No Activity found to handle Intent { act=android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS dat=package:io.demo.example }". User has to find the app in the list, it seems no way to jump directly to our app.