diff --git a/README.md b/README.md index 46f0b34..e1923fc 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,7 @@ Set a number on the notification. Not yet implemented. **ongoing (`boolean`)** -Not yet implemented. +If set to true, the user will not be able to remove the notification. Defaults to `false`. **category (`string`)** Set the notification category, e.g.: `alarm`, `call`, `email`, `event`, `progress`, `reminder`, `social`. It may be used by the Android system for ranking and filtering. diff --git a/android/src/main/java/io/neson/react/notification/Notification.java b/android/src/main/java/io/neson/react/notification/Notification.java index 66a2f38..452abe2 100644 --- a/android/src/main/java/io/neson/react/notification/Notification.java +++ b/android/src/main/java/io/neson/react/notification/Notification.java @@ -126,6 +126,7 @@ public android.app.Notification build() { .setContentText(attributes.message) .setSmallIcon(context.getResources().getIdentifier(attributes.smallIcon, "mipmap", context.getPackageName())) .setAutoCancel(attributes.autoClear) + .setOngoing(attributes.ongoing) .setContentIntent(getContentIntent()); diff --git a/android/src/main/java/io/neson/react/notification/NotificationAttributes.java b/android/src/main/java/io/neson/react/notification/NotificationAttributes.java index 941288f..efbffa8 100644 --- a/android/src/main/java/io/neson/react/notification/NotificationAttributes.java +++ b/android/src/main/java/io/neson/react/notification/NotificationAttributes.java @@ -45,6 +45,7 @@ public class NotificationAttributes { public String vibrate; public String lights; public Boolean autoClear; + public Boolean ongoing; public Boolean onlyAlertOnce; public String tickerText; public Long when; @@ -161,6 +162,8 @@ public void loadFromReadableMap(ReadableMap readableMap) { if (readableMap.hasKey("lights")) lights = readableMap.getString("lights"); if (readableMap.hasKey("autoClear")) autoClear = readableMap.getBoolean("autoClear"); else autoClear = true; + if (readableMap.hasKey("ongoing")) ongoing = readableMap.getBoolean("ongoing"); + else ongoing = false; if (readableMap.hasKey("onlyAlertOnce")) onlyAlertOnce = readableMap.getBoolean("onlyAlertOnce"); if (readableMap.hasKey("tickerText")) tickerText = readableMap.getString("tickerText"); if (readableMap.hasKey("when")) when = Long.parseLong(readableMap.getString("when")); @@ -232,6 +235,7 @@ public ReadableMap asReadableMap() { if (vibrate != null) writableMap.putString("vibrate", vibrate); if (lights != null) writableMap.putString("lights", lights); if (autoClear != null) writableMap.putBoolean("autoClear", autoClear); + if (ongoing != null) writableMap.putBoolean("ongoing", ongoing); if (onlyAlertOnce != null) writableMap.putBoolean("onlyAlertOnce", onlyAlertOnce); if (tickerText != null) writableMap.putString("tickerText", tickerText); if (when != null) writableMap.putString("when", Long.toString(when)); diff --git a/index.android.js b/index.android.js index 9cf844c..e304514 100644 --- a/index.android.js +++ b/index.android.js @@ -112,6 +112,7 @@ function encodeNativeNotification(attributes) { if (!attributes.action) attributes.action = 'DEFAULT'; if (!attributes.payload) attributes.payload = {}; if (attributes.autoClear === undefined) attributes.autoClear = true; + if (attributes.ongoing === undefined) attributes.ongoing = false; if (attributes.tickerText === undefined) { if (attributes.subject) { attributes.tickerText = attributes.subject + ': ' + attributes.message;