diff --git a/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java --- a/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java +++ b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java @@ -4,10 +4,13 @@ import android.content.Context; import android.service.notification.StatusBarNotification; import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.WritableMap; +import com.google.firebase.messaging.RemoteMessage; public class CommAndroidNotifications extends ReactContextBaseJavaModule { private NotificationManager notificationManager; @@ -42,4 +45,18 @@ } } } + + @ReactMethod + public void getInitialNotification(Promise promise) { + RemoteMessage initialNotification = + getCurrentActivity().getIntent().getParcelableExtra("message"); + if (initialNotification == null) { + promise.resolve(null); + return; + } + WritableMap jsReadableNotification = + CommAndroidNotificationParser.parseRemoteMessageToJSForegroundMessage( + initialNotification); + promise.resolve(jsReadableNotification); + } } diff --git a/native/push/android.js b/native/push/android.js --- a/native/push/android.js +++ b/native/push/android.js @@ -6,6 +6,7 @@ type CommAndroidNotificationsModuleType = { +removeAllActiveNotificationsForThread: (threadID: string) => void, + +getInitialNotification: () => Promise, ... }; export type AndroidForegroundMessage = { diff --git a/native/push/push-handler.react.js b/native/push/push-handler.react.js --- a/native/push/push-handler.react.js +++ b/native/push/push-handler.react.js @@ -349,9 +349,7 @@ return; } this.initialAndroidNotifHandled = true; - const initialNotif = await getFirebase() - .notifications() - .getInitialNotification(); + const initialNotif = await CommAndroidNotifications.getInitialNotification(); if (initialNotif) { await this.androidNotificationOpened(initialNotif); }