Patch RNNotification Android (#6615)

This commit is contained in:
Elias Nahum
2022-09-02 10:45:23 -04:00
committed by GitHub
parent de328f0ebe
commit 0d7cc9fa75
2 changed files with 54 additions and 8 deletions

View File

@@ -181,13 +181,11 @@ class PushNotifications {
// This triggers when a notification is tapped and the app was in the background (iOS)
onNotificationOpened = (incoming: Notification, completion: () => void) => {
if (Platform.OS === 'ios') {
const notification = convertToNotificationData(incoming, false);
notification.userInteraction = true;
const notification = convertToNotificationData(incoming, false);
notification.userInteraction = true;
this.processNotification(notification);
completion();
}
this.processNotification(notification);
completion();
};
// This triggers when the app was in the background (iOS)

View File

@@ -21,9 +21,18 @@ index 24cd226..4bfacba 100644
</manifest>
diff --git a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java
index 90969b2..778cb29 100644
index 90969b2..3420045 100644
--- a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java
+++ b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java
@@ -63,7 +63,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
@Override
public void onNewIntent(Intent intent) {
if (NotificationIntentAdapter.canHandleIntent(intent)) {
- Bundle notificationData = intent.getExtras();
+ Bundle notificationData = NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent);
final IPushNotification notification = PushNotification.get(getReactApplicationContext().getApplicationContext(), notificationData);
if (notification != null) {
notification.onOpened();
@@ -102,7 +102,12 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
if(BuildConfig.DEBUG) Log.d(LOGTAG, "Native method invocation: postLocalNotification");
final Bundle notificationProps = Arguments.toBundle(notificationPropsMap);
@@ -38,6 +47,45 @@ index 90969b2..778cb29 100644
}
@ReactMethod
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 eadf41e..a3f71dd 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
@@ -96,8 +96,7 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade.
Intent intent = activity.getIntent();
if (NotificationIntentAdapter.canHandleIntent(intent)) {
Context appContext = mApplication.getApplicationContext();
- Bundle notificationData = NotificationIntentAdapter.cannotHandleTrampolineActivity(appContext) ?
- NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent) : intent.getExtras();
+ Bundle notificationData = NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent);
final IPushNotification pushNotification = PushNotification.get(appContext, notificationData);
if (pushNotification != null) {
pushNotification.onOpened();
diff --git a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java
index 41b4824..4285ac5 100644
--- a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java
+++ b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java
@@ -14,17 +14,9 @@ public class NotificationIntentAdapter {
@SuppressLint("UnspecifiedImmutableFlag")
public static PendingIntent createPendingNotificationIntent(Context appContext, PushNotificationProps notification) {
- if (cannotHandleTrampolineActivity(appContext)) {
- Intent mainActivityIntent = appContext.getPackageManager().getLaunchIntentForPackage(appContext.getPackageName());
- mainActivityIntent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
- TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(appContext);
- taskStackBuilder.addNextIntentWithParentStack(mainActivityIntent);
- return taskStackBuilder.getPendingIntent((int) System.currentTimeMillis(), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
- } else {
- Intent intent = new Intent(appContext, ProxyService.class);
- intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
- return PendingIntent.getService(appContext, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_ONE_SHOT);
- }
+ Intent intent = appContext.getPackageManager().getLaunchIntentForPackage(appContext.getPackageName());
+ intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
+ return PendingIntent.getActivity(appContext, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
}
public static boolean cannotHandleTrampolineActivity(Context appContext) {
diff --git a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/helpers/ScheduleNotificationHelper.java b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/helpers/ScheduleNotificationHelper.java
new file mode 100644
index 0000000..433c754
@@ -413,4 +461,4 @@ index afd5c73..6036dda 100644
+ callback(formattedNotifications);
}];
}