I'm trying to disable battery optimization on Android 9 with ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
in a push notification when the app is launched.
In the activity file (using notification builder):
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, intent, 0);
NotificationCompat.Builder...
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getContext());
notificationManager.notify(notificationId, builder.build());
In the AndroidManifest.xml
:
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
I'm able to get the push notification to show, but when you tap, it just disappears. The prompt for 'Allow' doesn't pop up. Am I doing something wrong with the setup?