From 9298265a9ea6f448edf8a27c10273fc2ea45e697 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Mon, 18 Jul 2022 10:47:10 +0900 Subject: [PATCH] On Android12+ devices, tapping a notification immediately opens the ignore Battery Optimization dialog --- .../microg/gms/common/ForegroundServiceContext.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/play-services-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java b/play-services-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java index 8da30387..0a5f01c5 100644 --- a/play-services-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java +++ b/play-services-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java @@ -9,6 +9,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.ContextWrapper; import android.content.Intent; +import android.net.Uri; import android.os.Build; import android.os.PowerManager; import android.provider.Settings; @@ -89,8 +90,13 @@ public class ForegroundServiceContext extends ContextWrapper { private static Notification buildForegroundNotification(Context context, String serviceName) { Intent notificationIntent = new Intent(); - notificationIntent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); - notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + notificationIntent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + notificationIntent.setData(Uri.parse("package:" + context.getPackageName())); + } else { + notificationIntent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); + notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + } PendingIntent notificationPendingIntent = PendingIntent.getActivity(context, 0, notificationIntent,