From 2e0eac4e9ae203aa58c2b59d41fc5b8ca7028b1d Mon Sep 17 00:00:00 2001 From: Xavier Date: Mon, 15 Oct 2018 18:36:09 +0800 Subject: [PATCH] Fix issue with Android not getting Led ON for notifications on Android O --- .../FirebasePluginMessagingService.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/android/FirebasePluginMessagingService.java b/src/android/FirebasePluginMessagingService.java index d640cf687..4017bedff 100755 --- a/src/android/FirebasePluginMessagingService.java +++ b/src/android/FirebasePluginMessagingService.java @@ -18,6 +18,7 @@ import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; +import java.util.List; import java.util.Map; import java.util.Random; @@ -152,11 +153,12 @@ private void sendNotification(String id, String title, String messageBody, Map= android.os.Build.VERSION_CODES.M) { int accentID = getResources().getIdentifier("accent", "color", getPackageName()); notificationBuilder.setColor(getResources().getColor(accentID, null)); - } Notification notification = notificationBuilder.build(); @@ -184,8 +185,25 @@ private void sendNotification(String id, String title, String messageBody, Map= android.os.Build.VERSION_CODES.O) { - NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH); - notificationManager.createNotificationChannel(channel); + List channels = notificationManager.getNotificationChannels(); + + boolean channelExists = false; + for (int i = 0; i < channels.size(); i++) { + if (channelId.equals(channels.get(i).getId())) { + channelExists = true; + } + } + + if (!channelExists) { + NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH); + channel.enableLights(true); + channel.enableVibration(true); + channel.setShowBadge(true); + if (lights != null) { + channel.setLightColor(lightArgb); + } + notificationManager.createNotificationChannel(channel); + } } notificationManager.notify(id.hashCode(), notification);