Commit 5056657a authored by yogevbd's avatar yogevbd

Handle intent by extra key and not by google.message_id string

parent f8296ddd
......@@ -189,3 +189,4 @@ package-lock.json
.history
android/.idea
android/build
android/.gradle
\ No newline at end of file
#Tue Mar 05 16:05:24 EET 2019
#Mon Aug 12 14:22:42 IDT 2019
gradle.version=4.4
......@@ -18,6 +18,7 @@ import com.facebook.react.bridge.ReadableMap;
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.ReactAppLifecycleFacade;
import com.wix.reactnativenotifications.core.notification.IPushNotification;
import com.wix.reactnativenotifications.core.notification.PushNotification;
......@@ -62,8 +63,8 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
@Override
public void onNewIntent(Intent intent) {
if (NotificationIntentAdapter.canHandleIntent(intent)) {
Bundle notificationData = intent.getExtras();
if (notificationData != null) {
final IPushNotification notification = PushNotification.get(getReactApplicationContext().getApplicationContext(), notificationData);
if (notification != null) {
notification.onOpened();
......
......@@ -14,6 +14,7 @@ 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.NotificationIntentAdapter;
import com.wix.reactnativenotifications.core.notification.IPushNotification;
import com.wix.reactnativenotifications.core.notification.PushNotification;
import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer;
......@@ -64,16 +65,14 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade.
notificationsDrawer.onNewActivity(activity);
Intent intent = activity.getIntent();
if (intent != null) {
if (NotificationIntentAdapter.canHandleIntent(intent)) {
Bundle notificationData = intent.getExtras();
if (notificationData != null) {
final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData);
if (pushNotification != null) {
pushNotification.onOpened();
}
}
}
}
@Override
public void onActivityStarted(Activity activity) {
......
......@@ -18,4 +18,15 @@ public class NotificationIntentAdapter {
public static Bundle extractPendingNotificationDataFromIntent(Intent intent) {
return intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME);
}
public static boolean canHandleIntent(Intent intent) {
if (intent != null) {
Bundle notificationData = intent.getExtras();
if (notificationData != null && intent.hasExtra(PUSH_NOTIFICATION_EXTRA_NAME)) {
return true;
}
}
return false;
}
}
......@@ -8,6 +8,8 @@ import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Debug;
import android.util.Log;
import com.facebook.react.bridge.ReactContext;
import com.wix.reactnativenotifications.core.AppLaunchHelper;
......@@ -43,10 +45,6 @@ public class PushNotification implements IPushNotification {
};
public static IPushNotification get(Context context, Bundle bundle) {
if (verifyNotificationBundle(bundle) == false) {
return null;
}
Context appContext = context.getApplicationContext();
if (appContext instanceof INotificationsApplication) {
return ((INotificationsApplication) appContext).getPushNotification(context, bundle, AppLifecycleFacadeHolder.get(), new AppLaunchHelper());
......@@ -62,14 +60,6 @@ public class PushNotification implements IPushNotification {
mNotificationProps = createProps(bundle);
}
private static boolean verifyNotificationBundle(Bundle bundle) {
if (bundle.getString("google.message_id") != null) {
return true;
}
return false;
}
@Override
public void onReceived() throws InvalidNotificationException {
postNotification(null);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment