diff --git a/android/src/main/java/com/wix/reactnativenotifications/core/notifications/LocalNotification.java b/android/src/main/java/com/wix/reactnativenotifications/core/notifications/LocalNotification.java index e105de55e..a60fd5cee 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/core/notifications/LocalNotification.java +++ b/android/src/main/java/com/wix/reactnativenotifications/core/notifications/LocalNotification.java @@ -130,7 +130,6 @@ protected PendingIntent getCTAPendingIntent() { protected Notification.Builder getNotificationBuilder(PendingIntent intent) { final Integer icon = mNotificationProps.getIcon(); - final Integer color = mNotificationProps.getColor(); final Notification.Builder builder = new Notification.Builder(mContext) .setContentTitle(mNotificationProps.getTitle()) @@ -141,10 +140,20 @@ protected Notification.Builder getNotificationBuilder(PendingIntent intent) { .setDefaults(Notification.DEFAULT_ALL) .setAutoCancel(true); + final Integer color = mNotificationProps.getColor(); + if (color != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setColor(color); } + final Integer lightsColor = mNotificationProps.getLightsColor(); + final Integer lightsOnMs = mNotificationProps.getLightsOnMs(); + final Integer lightsOffMs = mNotificationProps.getLightsOffMs(); + + if (lightsColor != null && lightsOnMs != null && lightsOffMs != null) { + builder.setLights(lightsColor, lightsOnMs, lightsOffMs); + } + return builder; } diff --git a/android/src/main/java/com/wix/reactnativenotifications/core/notifications/NotificationProps.java b/android/src/main/java/com/wix/reactnativenotifications/core/notifications/NotificationProps.java index c5bb907cd..88a8f99ab 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/core/notifications/NotificationProps.java +++ b/android/src/main/java/com/wix/reactnativenotifications/core/notifications/NotificationProps.java @@ -10,6 +10,7 @@ import com.google.firebase.messaging.RemoteMessage; import java.util.Map; +import java.util.Objects; public class NotificationProps { @@ -27,6 +28,9 @@ public class NotificationProps { // Local-only support private static final String LARGE_ICON = "largeIcon"; // Drawable name or URL + private static final String LIGHTS_COLOR = "lightsColor"; + private static final String LIGHTS_ON_MS = "lightsOnMs"; + private static final String LIGHTS_OFF_MS = "lightsOffMs"; public static NotificationProps fromRemoteMessage(Context context, RemoteMessage remoteMessage) { final Bundle properties = new Bundle(); @@ -123,6 +127,21 @@ public String getLargeIcon() { return mProperties.getString(LARGE_ICON); } + @Nullable + public Integer getLightsColor() { + return colorFromString(mProperties.getString(LIGHTS_COLOR)); + } + + @Nullable + public Integer getLightsOnMs() { + return getInteger(LIGHTS_ON_MS); + } + + @Nullable + public Integer getLightsOffMs() { + return getInteger(LIGHTS_OFF_MS); + } + @Nullable public Bundle getData() { return mProperties.getBundle(DATA); @@ -141,6 +160,30 @@ public String toString() { return sb.toString(); } + @Nullable + private Integer getInteger(String key) { + final Object object = mProperties.get(key); + + if (object instanceof Number) { + return ((Number) object).intValue(); + } + + return integerFromString(mProperties.getString(key)); + } + + @Nullable + private Integer integerFromString(String string) { + if (string != null) { + try { + return Integer.parseInt(string); + } catch (NumberFormatException e) { + // Move on + } + } + + return null; + } + @Nullable private Integer colorFromString(String string) { if (string != null) { diff --git a/notification.android.js b/notification.android.js index f7f388e9a..ba6836989 100644 --- a/notification.android.js +++ b/notification.android.js @@ -47,4 +47,16 @@ export default class NotificationAndroid { getLargeIcon() { return this.properties.largeIcon; } + + getLightsColor() { + return this.properties.lightsColor; + } + + getLightsOnMs() { + return this.properties.lightsOnMs; + } + + getLightsOffMs() { + return this.properties.lightsOffMs; + } }