From 2ba058abcfe2b371ee7f17e6bff601ea68a19d23 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Fri, 22 Jul 2016 00:46:22 -0400 Subject: [PATCH] use onNewIntent from RN 0.30.0 --- README.md | 2 +- android/react-native-fcm.iml | 36 ++++++++--------- .../evollu/react/fcm/FIRMessagingModule.java | 40 ++++++++++++------- 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 8664474..a5d3e06 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Notes: - replace `"fcm.ACTION.HELLO"` by the `click_action` you want to match -And pass intent into package, edit `MainActivity.java`: +If you are using RN<0.30.0 and react-native-fcm < 1.0.15, pass intent into package, edit `MainActivity.java`: - RN 0.28+: diff --git a/android/react-native-fcm.iml b/android/react-native-fcm.iml index fa72a0d..1281143 100644 --- a/android/react-native-fcm.iml +++ b/android/react-native-fcm.iml @@ -65,14 +65,6 @@ - - - - - - - - @@ -81,6 +73,14 @@ + + + + + + + + @@ -103,31 +103,31 @@ - + - + - - + - - + - + + + - - + - + + \ No newline at end of file diff --git a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java index 328b710..e0b036b 100644 --- a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java +++ b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver; import android.content.Intent; import android.content.IntentFilter; +import com.facebook.react.bridge.ActivityEventListener; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.LifecycleEventListener; import com.facebook.react.bridge.Promise; @@ -25,13 +26,14 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -public class FIRMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener { +public class FIRMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ActivityEventListener { private final static String TAG = FIRMessagingModule.class.getCanonicalName(); - Intent currentIntent; + Intent initIntent; public FIRMessagingModule(ReactApplicationContext reactContext) { super(reactContext); getReactApplicationContext().addLifecycleEventListener(this); + getReactApplicationContext().addActivityEventListener(this); registerTokenRefreshHandler(); registerMessageHandler(); } @@ -112,14 +114,9 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li }, intentFilter); } - @Override - public void onHostResume() { - Intent newIntent = getCurrentActivity().getIntent(); - if(newIntent == currentIntent){ - return; - } + private WritableMap parseIntent(Intent intent){ WritableMap params; - Bundle extras = newIntent.getExtras(); + Bundle extras = intent.getExtras(); if (extras != null) { try { params = Arguments.fromBundle(extras); @@ -131,15 +128,19 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li params = Arguments.createMap(); } WritableMap fcm = Arguments.createMap(); - fcm.putString("action", newIntent.getAction()); + fcm.putString("action", intent.getAction()); params.putMap("fcm", fcm); - if (currentIntent == null){ + return params; + } + + @Override + public void onHostResume() { + if (initIntent == null){ //the first intent is initial intent that opens the app - sendEvent("FCMInitData", params); - } else { - sendEvent("FCMNotificationReceived", params); + Intent newIntent = getCurrentActivity().getIntent(); + sendEvent("FCMInitData", parseIntent(newIntent)); + initIntent = newIntent; } - currentIntent = newIntent; } @Override @@ -150,4 +151,13 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li public void onHostDestroy() { } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + } + + @Override + public void onNewIntent(Intent intent){ + sendEvent("FCMNotificationReceived", parseIntent(intent)); + } } -- 2.26.2