From 21c2f51ea61f6d05b0c2e364bb08d8e4d90c45bd Mon Sep 17 00:00:00 2001 From: Oizaro <45825534+Oizaro@users.noreply.github.com> Date: Mon, 7 Sep 2020 19:01:10 +0200 Subject: [PATCH] Fix notification compatibility for API 26 and higher --- .../microg/gms/common/ForegroundServiceContext.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 5e21a22e..67a13d33 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 @@ -75,7 +75,16 @@ public class ForegroundServiceContext extends ContextWrapper { mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, mIntent, 0); - return new NotificationCompat.Builder(context, "foreground-service") + String notificationChannelID = "foreground-service"; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(notificationChannelID, context.getResources().getString(R.string.notification_service_name), NotificationManager.IMPORTANCE_MIN); + channel.setShowBadge(false); + channel.setLockscreenVisibility(0); + channel.setVibrationPattern(new long[0]); + context.getSystemService(NotificationManager.class).createNotificationChannel(channel); + } + return new NotificationCompat.Builder(context, notificationChannelID) .setOngoing(true) .setContentIntent(pendingIntent) .setContentTitle(context.getResources().getString(R.string.notification_service_title))