Skip to content

Commit 1652c7f

Browse files
authored
Merge pull request #358 from wix/betterIntentHandling
Resolve intent by extra key and not by `google.message_id` string
2 parents f8296dd + 5056657 commit 1652c7f

File tree

14 files changed

+27
-25
lines changed

14 files changed

+27
-25
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,5 @@ package-lock.json
188188

189189
.history
190190
android/.idea
191-
android/build
191+
android/build
192+
android/.gradle
-660 KB
Binary file not shown.
Binary file not shown.
-7.65 MB
Binary file not shown.
-3.1 MB
Binary file not shown.
-747 KB
Binary file not shown.
-264 KB
Binary file not shown.
-5.09 MB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#Tue Mar 05 16:05:24 EET 2019
1+
#Mon Aug 12 14:22:42 IDT 2019
22
gradle.version=4.4
Binary file not shown.

android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.wix.reactnativenotifications.core.AppLifecycleFacade;
1919
import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder;
2020
import com.wix.reactnativenotifications.core.InitialNotificationHolder;
21+
import com.wix.reactnativenotifications.core.NotificationIntentAdapter;
2122
import com.wix.reactnativenotifications.core.ReactAppLifecycleFacade;
2223
import com.wix.reactnativenotifications.core.notification.IPushNotification;
2324
import com.wix.reactnativenotifications.core.notification.PushNotification;
@@ -62,8 +63,8 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
6263

6364
@Override
6465
public void onNewIntent(Intent intent) {
65-
Bundle notificationData = intent.getExtras();
66-
if (notificationData != null) {
66+
if (NotificationIntentAdapter.canHandleIntent(intent)) {
67+
Bundle notificationData = intent.getExtras();
6768
final IPushNotification notification = PushNotification.get(getReactApplicationContext().getApplicationContext(), notificationData);
6869
if (notification != null) {
6970
notification.onOpened();

android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.google.firebase.FirebaseApp;
1515
import com.wix.reactnativenotifications.core.AppLifecycleFacade;
1616
import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder;
17+
import com.wix.reactnativenotifications.core.NotificationIntentAdapter;
1718
import com.wix.reactnativenotifications.core.notification.IPushNotification;
1819
import com.wix.reactnativenotifications.core.notification.PushNotification;
1920
import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer;
@@ -64,13 +65,11 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
6465
notificationsDrawer.onNewActivity(activity);
6566

6667
Intent intent = activity.getIntent();
67-
if (intent != null) {
68+
if (NotificationIntentAdapter.canHandleIntent(intent)) {
6869
Bundle notificationData = intent.getExtras();
69-
if (notificationData != null) {
70-
final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData);
71-
if (pushNotification != null) {
72-
pushNotification.onOpened();
73-
}
70+
final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData);
71+
if (pushNotification != null) {
72+
pushNotification.onOpened();
7473
}
7574
}
7675
}

android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java

+11
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,15 @@ public static PendingIntent createPendingNotificationIntent(Context appContext,
1818
public static Bundle extractPendingNotificationDataFromIntent(Intent intent) {
1919
return intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME);
2020
}
21+
22+
public static boolean canHandleIntent(Intent intent) {
23+
if (intent != null) {
24+
Bundle notificationData = intent.getExtras();
25+
if (notificationData != null && intent.hasExtra(PUSH_NOTIFICATION_EXTRA_NAME)) {
26+
return true;
27+
}
28+
}
29+
30+
return false;
31+
}
2132
}

android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java

+5-15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import android.content.Intent;
99
import android.os.Build;
1010
import android.os.Bundle;
11+
import android.os.Debug;
12+
import android.util.Log;
1113

1214
import com.facebook.react.bridge.ReactContext;
1315
import com.wix.reactnativenotifications.core.AppLaunchHelper;
@@ -43,10 +45,6 @@ public void onAppNotVisible() {
4345
};
4446

4547
public static IPushNotification get(Context context, Bundle bundle) {
46-
if (verifyNotificationBundle(bundle) == false) {
47-
return null;
48-
}
49-
5048
Context appContext = context.getApplicationContext();
5149
if (appContext instanceof INotificationsApplication) {
5250
return ((INotificationsApplication) appContext).getPushNotification(context, bundle, AppLifecycleFacadeHolder.get(), new AppLaunchHelper());
@@ -62,14 +60,6 @@ protected PushNotification(Context context, Bundle bundle, AppLifecycleFacade ap
6260
mNotificationProps = createProps(bundle);
6361
}
6462

65-
private static boolean verifyNotificationBundle(Bundle bundle) {
66-
if (bundle.getString("google.message_id") != null) {
67-
return true;
68-
}
69-
70-
return false;
71-
}
72-
7363
@Override
7464
public void onReceived() throws InvalidNotificationException {
7565
postNotification(null);
@@ -168,13 +158,13 @@ protected Notification.Builder getNotificationBuilder(PendingIntent intent) {
168158

169159
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
170160
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
171-
CHANNEL_NAME,
172-
NotificationManager.IMPORTANCE_DEFAULT);
161+
CHANNEL_NAME,
162+
NotificationManager.IMPORTANCE_DEFAULT);
173163
final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
174164
notificationManager.createNotificationChannel(channel);
175165
notification.setChannelId(CHANNEL_ID);
176166
}
177-
167+
178168
return notification;
179169
}
180170

0 commit comments

Comments
 (0)