diff --git a/android/src/main/java/com/wix/reactnativenotifications/core/notification/IPushNotification.java b/android/src/main/java/com/wix/reactnativenotifications/core/notification/IPushNotification.java index a142f4969b1bc24f98ba256841247f854010d30c..46f1015d59f84acd2feceee1f791451cec7a0098 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/core/notification/IPushNotification.java +++ b/android/src/main/java/com/wix/reactnativenotifications/core/notification/IPushNotification.java @@ -18,5 +18,11 @@ public interface IPushNotification { */ void onOpened(); + /** + * Handle a request to post this notification. + * @return ID to optionally use for notification deletion. + */ + int onPostRequest(); + PushNotificationProps asProps(); } diff --git a/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java b/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java index 03706c5ffabe925d34a581753487d9d9d8bb6010..5b8224e66d798acf6ef3de66c304747fd81c9c73 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java +++ b/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java @@ -68,15 +68,20 @@ public class PushNotification implements IPushNotification { PushNotificationsDrawer.get(mContext).onNotificationOpened(); } + @Override + public int onPostRequest() { + return postNotification(); + } + @Override public PushNotificationProps asProps() { return mNotificationProps.copy(); } - protected void postNotification() { + protected int postNotification() { final PendingIntent pendingIntent = getCTAPendingIntent(); final Notification notification = buildNotification(pendingIntent); - postNotification((int) System.currentTimeMillis(), notification); + return postNotification(notification); } protected void digestNotification() { @@ -141,11 +146,21 @@ public class PushNotification implements IPushNotification { .setAutoCancel(true); } + protected int postNotification(Notification notification) { + int id = createNotificationId(notification); + postNotification(id, notification); + return id; + } + protected void postNotification(int id, Notification notification) { final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(id, notification); } + protected int createNotificationId(Notification notification) { + return (int) System.currentTimeMillis(); + } + protected ReactContext getRunningReactContext() { final ReactNativeHost rnHost = ((ReactApplication) mContext.getApplicationContext()).getReactNativeHost(); if (!rnHost.hasInstance()) {