Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimmySorza/e73d571f65e8d56ce9068da2020eaa53 to your computer and use it in GitHub Desktop.
Save JimmySorza/e73d571f65e8d56ce9068da2020eaa53 to your computer and use it in GitHub Desktop.
diff --git a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java
index d7d32cd..2443037 100644
--- a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java
+++ b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java
@@ -4,28 +4,25 @@ import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
-import android.util.Log;
import com.facebook.react.ReactPackage;
-import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.google.firebase.FirebaseApp;
import com.wix.reactnativenotifications.core.AppLifecycleFacade;
import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder;
+import com.wix.reactnativenotifications.core.InitialNotificationHolder;
import com.wix.reactnativenotifications.core.NotificationIntentAdapter;
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;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import java.util.Map;
-
-import static com.wix.reactnativenotifications.Defs.LOGTAG;
public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade.AppVisibilityListener, Application.ActivityLifecycleCallbacks {
@@ -76,6 +73,13 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade.
@Override
public void onActivityStarted(Activity activity) {
+ Bundle bundle = activity.getIntent().getExtras();
+ if (bundle != null) {
+ PushNotificationProps props = new PushNotificationProps(bundle);
+ if (props.isFirebaseBackgroundPayload()) {
+ InitialNotificationHolder.getInstance().set(props);
+ }
+ }
}
@Override
diff --git a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java
index daab203..17fac3d 100644
--- a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java
+++ b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java
@@ -11,17 +11,21 @@ public class PushNotificationProps {
}
public String getTitle() {
- return mBundle.getString("title");
+ return getBundleStringFirstNotNull("gcm.notification.title", "title");
}
public String getBody() {
- return mBundle.getString("body");
+ return getBundleStringFirstNotNull("gcm.notification.body", "body");
}
public Bundle asBundle() {
return (Bundle) mBundle.clone();
}
+ public boolean isFirebaseBackgroundPayload() {
+ return mBundle.containsKey("google.message_id") && !mBundle.containsKey("title");
+ }
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder(1024);
@@ -34,4 +38,9 @@ public class PushNotificationProps {
protected PushNotificationProps copy() {
return new PushNotificationProps((Bundle) mBundle.clone());
}
+
+ private String getBundleStringFirstNotNull(String key1, String key2) {
+ String result = mBundle.getString(key1);
+ return result == null ? mBundle.getString(key2) : result;
+ }
}
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment