diff --git a/android/src/main/java/com/wix/reactnativenotifications/core/RNNotificationsModule.java b/android/src/main/java/com/wix/reactnativenotifications/core/RNNotificationsModule.java index 5db1c3273b35712486f2f5a16031c9837d2e445b..150196c47abcebef3edecf70fbf5bd7f5015c456 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/core/RNNotificationsModule.java +++ b/android/src/main/java/com/wix/reactnativenotifications/core/RNNotificationsModule.java @@ -12,6 +12,9 @@ import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.ReadableMap; +import com.wix.reactnativenotifications.core.notification.IPushNotification; +import com.wix.reactnativenotifications.core.notification.PushNotification; import com.wix.reactnativenotifications.core.notification.PushNotificationProps; import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer; import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer; @@ -66,6 +69,27 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements } } + @ReactMethod + public void postLocalNotification(ReadableMap notificationPropsMap, final Promise promise) { + Log.d(LOGTAG, "Native method invocation: postLocalNotification"); + Object result = null; + + try { + final Bundle notificationProps = Arguments.toBundle(notificationPropsMap); + final IPushNotification pushNotification = PushNotification.get(getReactApplicationContext().getApplicationContext(), notificationProps, ReactAppLifecycleFacade.get()); + int id = pushNotification.onPostRequest(); + result = id; + } finally { + promise.resolve(result); + } + } + + @ReactMethod + public void removeLocalNotification(int notificationId) { + IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); + notificationsDrawer.onNotificationClear(notificationId); + } + @Override public void onAppVisible() { final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); diff --git a/android/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java b/android/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java index 6711baa30cfdf7f443cffa4752613def6007f5ab..c7f9729e81cd6cbcfff687b242c017d8122727ae 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java +++ b/android/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java @@ -8,4 +8,5 @@ public interface IPushNotificationsDrawer { void onNewActivity(Activity activity); void onNotificationOpened(); + void onNotificationClear(int id); } diff --git a/android/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java b/android/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java index 9b3383bdcc7af65cf63bc4c3159806fd813daed4..5c96426deaba63e022d5c6d3da40e29854e1a80e 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java +++ b/android/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java @@ -47,6 +47,12 @@ public class PushNotificationsDrawer implements IPushNotificationsDrawer { clearAll(); } + @Override + public void onNotificationClear(int id) { + final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(id); + } + protected void clearAll() { final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancelAll();