Skip to content

RN 0.68.2 - Android 12 (API 31) - RNN 4.3.1 - Issues #874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
claudiozam opened this issue May 28, 2022 · 48 comments
Closed

RN 0.68.2 - Android 12 (API 31) - RNN 4.3.1 - Issues #874

claudiozam opened this issue May 28, 2022 · 48 comments

Comments

@claudiozam
Copy link

Hi, after upgrading to RNN 4.3.1 and targetSdkVersion 31 (Android 12)

I notice some new issues.

Case 1

Dead state (100% dead) or Fake dead state (if I close the app with the android back button)
Send 2 notifications
Click on one notification message
The app opens ok
Notifications.getInitialNotification() returns data
While the app is open click on the second notification message
App will open again (restarting the main activity).
Notifications.getInitialNotification() returns no data

Case 2

Dead / Background state
Send 1 notification
I don't click the notification message
I open the App
Notifications.events().registerNotificationOpened is executed. (Related issue #872)

Case 3

Background state
Click on the notification message
App will open again
Notifications.getInitialNotification() returns data

react-native-notifications version

4.3.1

react-native version

0.68.2

Enviroment

"dependencies": {
"@alessiocancian/react-native-actionsheet": "^3.1.2",
"@codler/react-native-keyboard-aware-scroll-view": "2.0.1",
"@fortawesome/fontawesome-common-types": "file:./local_fortawesome/fontawesome-common-types",
"@fortawesome/fontawesome-svg-core": "file:./local_fortawesome/fontawesome-svg-core",
"@fortawesome/free-brands-svg-icons": "file:./local_fortawesome/free-brands-svg-icons",
"@fortawesome/pro-light-svg-icons": "file:./local_fortawesome/pro-light-svg-icons",
"@fortawesome/pro-regular-svg-icons": "file:./local_fortawesome/pro-regular-svg-icons",
"@fortawesome/pro-solid-svg-icons": "file:./local_fortawesome/pro-solid-svg-icons",
"@fortawesome/react-native-fontawesome": "file:./local_fortawesome/react-native-fontawesome",
"@invertase/react-native-apple-authentication": "^2.2.0",
"@react-native-async-storage/async-storage": "^1.17.5",
"@react-native-clipboard/clipboard": "^1.10.0",
"@react-native-community/art": "^1.2.0",
"@react-native-community/audio-toolkit": "^2.0.3",
"@react-native-community/datetimepicker": "^3.5.2",
"@react-native-community/masked-view": "^0.1.11",
"@react-native-community/slider": "^4.2.2",
"@react-native-firebase/analytics": "^14.11.0",
"@react-native-firebase/app": "^14.11.0",
"@react-native-google-signin/google-signin": "^7.2.2",
"@react-native-picker/picker": "^2.4.0",
"@react-navigation/drawer": "^6.4.1",
"@react-navigation/elements": "^1.3.3",
"@react-navigation/native": "^6.0.10",
"@react-navigation/stack": "^6.2.1",
"@types/uuid": "^8.3.4",
"axios": "^0.24.0",
"chance": "^1.1.8",
"color": "^3.1.3",
"detox": "^19.7.0",
"formik": "^2.2.6",
"fsevents": "^2.3.2",
"hermes-engine": "^0.11.0",
"immutability-helper": "^3.1.1",
"link-preview-js": "^2.1.15",
"lodash": "^4.17.20",
"native-base": "2.15.2",
"patch-package": "^6.4.7",
"postinstall-postinstall": "^2.1.0",
"pretty-bytes": "^6.0.0",
"randomcolor": "^0.6.2",
"react": "17.0.2",
"react-native": "0.68.2",
"react-native-add-calendar-event": "^4.0.0",
"react-native-autolink": "^4.0.0",
"react-native-base64": "^0.2.1",
"react-native-blob-util": "^0.16.0",
"react-native-bootsplash": "^4.1.4",
"react-native-calendars": "1.1279.0",
"react-native-color-palette": "^2.2.0",
"react-native-config": "^1.4.5",
"react-native-device-info": "^8.7.0",
"react-native-document-picker": "^8.1.0",
"react-native-fast-image": "^8.5.4",
"react-native-fbsdk-next": "^8.0.5",
"react-native-ffmpeg": "^0.5.2",
"react-native-file-viewer": "^2.1.5",
"react-native-gesture-handler": "^2.4.1",
"react-native-gifted-chat": "^0.16.3",
"react-native-hide-with-keyboard": "^1.2.1",
"react-native-image-crop-picker": "^0.37.3",
"react-native-image-zoom-viewer": "^3.0.1",
"react-native-inappbrowser-reborn": "^3.5.1",
"react-native-iphone-x-helper": "^1.3.1",
"react-native-linear-gradient": "^2.5.6",
"react-native-loading-spinner-overlay": "^2.0.0",
"react-native-localize": "^2.2.1",
"react-native-masked-text": "^1.13.0",
"react-native-mime-types": "^2.3.0",
"react-native-modal": "^13.0.0",
"react-native-modal-datetime-picker": "^13.1.2",
"react-native-modal-selector": "^2.1.0",
"react-native-notifications": "^4.3.0",
"react-native-orientation-locker": "^1.5.0",
"react-native-permissions": "^3.3.0",
"react-native-progress": "^5.0.0",
"react-native-push-notification-popup": "^1.6.0",
"react-native-rate": "^1.2.4",
"react-native-reanimated": "2.8.0",
"react-native-render-html": "^6.3.0",
"react-native-safe-area-context": "^4.2.2",
"react-native-screens": "^3.13.0",
"react-native-share": "^7.4.1",
"react-native-simple-toast": "^1.1.3",
"react-native-spinkit": "^1.5.1",
"react-native-svg": "^12.3.0",
"react-native-swipe-gestures": "^1.0.5",
"react-native-swiper": "^1.6.0",
"react-native-toast-message": "^2.1.5",
"react-native-vector-icons": "^9.1.0",
"react-native-version": "^4.0.0",
"react-native-video": "^5.2.0",
"react-native-webview": "11.18.2",
"react-redux": "^8.0.2",
"read-package-json": "^5.0.0",
"redux": "^4.2.0",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.4.1",
"rn-placeholder": "^3.0.3",
"rollbar-react-native": "^0.9.1",
"sanitize-filename": "^1.6.3",
"striptags": "^3.1.1",
"url": "^0.11.0",
"yup": "^0.32.8"
},
"resolutions": {
"@codler/react-native-keyboard-aware-scroll-view": "2.0.1",
"@react-native-community/datetimepicker": "3.5.2"
},
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/plugin-proposal-class-properties": "^7.17.12",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.17.12",
"@babel/plugin-proposal-optional-chaining": "^7.17.12",
"@babel/plugin-transform-arrow-functions": "^7.17.12",
"@babel/plugin-transform-shorthand-properties": "^7.16.0",
"@babel/plugin-transform-template-literals": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@babel/runtime": "^7.18.3",
"@react-native-community/eslint-config": "^3.0.2",
"babel-jest": "^28.1.0",
"eslint": "^8.16.0",
"jest": "^28.1.0",
"metro-react-native-babel-preset": "^0.71.0",
"properties-reader": "^2.2.0",
"react-test-renderer": "17.0.2",
"redux-devtools": "3.7.0"
},

Tested on a real device (Samsung S10 / S21 - Android 12)

Thanks

@aftabameen
Copy link

build failed for when minCompileSdk are upraded to 31

@claudiozam
Copy link
Author

@aftabameen this is my build.gradle

    buildToolsVersion = "31.0.0"
    minSdkVersion = 22
    compileSdkVersion = 31
    targetSdkVersion = 31
    googlePlayServicesAuthVersion = "17.0.0"
    kotlinVersion = "1.5.10"
    androidXAnnotation = "1.+"
    androidXBrowser = "1.+"

@claudiozam
Copy link
Author

https://developer.android.com/google/play/requirements/target-sdk#:~:text=Starting%20in%20August%202022%2C%20new,behavioral%20changes%20in%20Android%2012.

Starting in August 2022, new apps must target API level 31 (Android 12).
Starting in November 2022, app updates must target API level 31.

@oliviermtl
Copy link

Same issue here
react-native-notifications version
4.3.1

react-native version
0.68.2

@trugdn
Copy link

trugdn commented Jul 18, 2022

any solution

@artyorsh
Copy link

artyorsh commented Aug 1, 2022

There was an sdk update which caused the issue. A workaround is to target Android sdk which is less than 31

  compileSdkVersion = 30
  targetSdkVersion = 30

This way it works, but still not compatible with Android 13 where you have to request notification permissions in runtime

@oliviermtl
Copy link

There was an sdk update which caused the issue. A workaround is to target Android sdk which is less than 31

  compileSdkVersion = 30
  targetSdkVersion = 30

This way it works, but still not compatible with Android 13 where you have to request notification permissions in runtime

As @claudiozam mentioned SDK 31 will be soon mandatory

https://developer.android.com/google/play/requirements/target-sdk#:~:text=Starting%20in%20August%202022%2C%20new,behavioral%20changes%20in%20Android%2012.

Starting in August 2022, new apps must target API level 31 (Android 12). Starting in November 2022, app updates must target API level 31.

@enahum
Copy link
Contributor

enahum commented Aug 8, 2022

For us it seems to be "working" you can take a look at https://github.com/mattermost/mattermost-mobile/tree/gekidou (we use custom notifications)

The downside of it all is that we are using react-native-navigation and every time the app sits in the background tapping a notification it will sort of run the MainActivity again, which is displaying the splash screen and all. We are still looking for a better way of doing this, perhaps a transparent activity of some sort, but I'm no Android developer

@russmenum
Copy link

Is there a fix for this? Or is this library EOL?

Installation did not succeed.
The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED

List of apks:
[0] '/Users/[USERNAME]/github/[APP]/android/app/build/outputs/apk/release/app-release.apk'
Installation failed due to: 'Failed to commit install session 1735472622 with command cmd package install-commit 1735472622. Error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl1735472622.tmp/base.apk (at Binary XML file line #148): com.wix.reactnativenotifications.fcm.FcmInstanceIdListenerService: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present'
Retry
Failed to launch an application on all devices

As stated switching to targetSdkVersion = 30 will work, but new apps can not do that any more as of this month, and old apps wont be able to in 2 months.

This is EOL for this library if it can not be patched to be compliant with android:exported="true" more info here
https://developer.android.com/about/versions/12/behavior-changes-12#exported

@russmenum
Copy link

For us it seems to be "working" you can take a look at https://github.com/mattermost/mattermost-mobile/tree/gekidou (we use custom notifications)

The downside of it all is that we are using react-native-navigation and every time the app sits in the background tapping a notification it will sort of run the MainActivity again, which is displaying the splash screen and all. We are still looking for a better way of doing this, perhaps a transparent activity of some sort, but I'm no Android developer

Can you run your app on an Android 12 Emulator?

@enahum
Copy link
Contributor

enahum commented Aug 16, 2022

@russmenum Emulator and real devices no problem

@russmenum
Copy link

@russmenum Emulator and real devices no problem

That is an emulator with API 31+, because it runs fine on API 30-

@petarstamenkov
Copy link

We had the same or at least similar issues - the main activity was restarting when notification is clicked, and the notification payload data was wrapped in additional pushNotification object.
This fixed it in our case

react-native-notifications+4.3.1.patch

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..4c00e69 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();
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) {

You can apply this patch using patch-package

@artyorsh
Copy link

artyorsh commented Sep 5, 2022

@petarstamenkov thanks for sharing your progress on that. Could you please share your apps targetSdkVersion and compileSdkVersion? I didn't manage to get the package work with your patch, but what worked for us targeting and compiling for sdk-33, is

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..5903e02 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
@@ -17,7 +17,6 @@ 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;
 
@@ -96,9 +95,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();
-            final IPushNotification pushNotification = PushNotification.get(appContext, notificationData);
+            final IPushNotification pushNotification = PushNotification.get(appContext, intent.getExtras());
             if (pushNotification != null) {
                 pushNotification.onOpened();
             }

The above works with package version 4.3.1 and in combination with

compileSdkVersion = 33
targetSdkVersion = 33

Also attaching a video for the most curious 🙂

@DanielEliraz with the patch given, I think the NotificationIntentAdapter.extractPendingNotificationDataFromIntent should be adjusted depending on BuildConfig fields. The thing to do is to collect what people target and compile

@camboYY
Copy link

camboYY commented Sep 20, 2022

@artyorsh not work

@oliviermtl
Copy link

oliviermtl commented Sep 21, 2022

final IPushNotification pushNotification = PushNotification.get(appContext, intent.getExtras());

This works for us with
compileSdkVersion=33
targetSdkVersion = 32

and RN 0.70

diegolmello added a commit to RocketChat/Rocket.Chat.ReactNative that referenced this issue Sep 30, 2022
diegolmello added a commit to RocketChat/Rocket.Chat.ReactNative that referenced this issue Oct 4, 2022
Lunziyuan pushed a commit to NeyberTech/react-native-notifications that referenced this issue Oct 12, 2022
@diegolmello
Copy link
Contributor

None of the patches worked with the app closed.
This one worked with the app in background #874 (comment)

  • App closed
  • Receive a push notification
  • Open the app by tapping the push notification
  • Move the app to background (home or back button)
  • Open from app icon
  • Notifications.events().registerNotificationOpened is going to run again

I can help testing, but I'm no Android dev to work on a fix.

@stale
Copy link

stale bot commented Nov 19, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Nov 19, 2022
@hubastard
Copy link

hubastard commented Nov 23, 2022

None of the patches worked with the app closed. This one worked with the app in background #874 (comment)

  • App closed
  • Receive a push notification
  • Open the app by tapping the push notification
  • Move the app to background (home or back button)
  • Open from app icon
  • Notifications.events().registerNotificationOpened is going to run again

I can help testing, but I'm no Android dev to work on a fix.

I think you need to open an activity directly to support opening a notification when app is closed.
Here is the PR that show how they fixed it for the Notifee library invertase/notifee#301

@stale stale bot removed the 🏚 stale label Nov 23, 2022
@anisimov74
Copy link
Contributor

anisimov74 commented Nov 25, 2022

We had the same or at least similar issues - the main activity was restarting when notification is clicked, and the notification payload data was wrapped in additional pushNotification object. This fixed it in our case

react-native-notifications+4.3.1.patch

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..4c00e69 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();
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) {

You can apply this patch using patch-package

I can confirm that the patch works for me.

RN 0.68.3
compileSdkVersion = 31
targetSdkVersion = 31
react-native-notifications 4.3.3

Targeting SDK to 33 didn't help.

@jamesholcomb
Copy link

@anisimov74 How did you get a 4.3.1+patch file to correctly patch against 4.3.3? I get

**ERROR** Failed to apply patch for package react-native-notifications at path

    node_modules/react-native-notifications

@anisimov74
Copy link
Contributor

@anisimov74 How did you get a 4.3.1+patch file to correctly patch against 4.3.3? I get

**ERROR** Failed to apply patch for package react-native-notifications at path

    node_modules/react-native-notifications

@jamesholcomb

  1. Switch off postinstall script if any
  2. Install patch-package (in my case it's a dev dep)
  3. Install the latest version of rnn
  4. Make all mentioned changes in node_modules/react-native-notifications
  5. Run yarn patch-package react-native-notifications

@anisimov74
Copy link
Contributor

As mentioned above, #872 is also related. I solve the problem on my side.

@blolo
Copy link

blolo commented Dec 15, 2022

any luck , RN 66.1 and 4.3.3 for react-native-notifications. Is there a working patch that allows notifications to work when android app is fully terminated ?

@arthurhts
Copy link

@petarstamenkov solved for me v4.3.3

@tsalama
Copy link

tsalama commented Dec 27, 2022

I'm on 4.3.3. My app targets API level 33 though, which might be the cause of my issues (?):

Everything works fine for me <= Android 11 on emulator and real device. For Android 12 and 13 I receive the FCM notifications on the emulator but clicking them does nothing. Works perfectly fine on Android 11 and below and triggers all the handlers as expected.

Anyone have any idea what I could be doing wrong? Been banging my head against the wall the past week trying all the different patches above etc. Would appreciate some guidance.

Much appreciated!

@bensie
Copy link

bensie commented Dec 30, 2022

@Desintegrator
Copy link

Desintegrator commented Feb 8, 2023

For those who searching for solution of getInitialNotification -> null problem on Android (when you open closed app by tapping on notification):

in my case, the problem was that i have separate Activity for splash screen with intent-filters in it
As I suppose these causes that splash activity intercepts notification and MainActivity cannot get it.

To solve it you can remove splash activity from manifest and make splash on RN side or use something like react-native-bootsplash

@stale
Copy link

stale bot commented Mar 12, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Mar 12, 2023
@bhandanyan-nomad
Copy link

bhandanyan-nomad commented Mar 20, 2023

A combination of #874 (comment) and #906 (comment) fixed my notification handling issues.

RN 0.68.5
compileSdkVersion = 31
targetSdkVersion = 31
react-native-notifications 4.3.3

EDIT: we have an issue on android api v8 with something in our patch causing a crash

@stale stale bot removed the 🏚 stale label Mar 20, 2023
@korzonkiee
Copy link

A combination of #874 (comment) and #906 (comment) fixed my notification handling issues.

RN 0.68.5 compileSdkVersion = 31 targetSdkVersion = 31 react-native-notifications 4.3.3

@bhandanyan-nomad would you mind sharing a fork with the changes?

@korzonkiee
Copy link

korzonkiee commented Mar 21, 2023

I managed to get it to work with the patch below. I tested it on physical devices running on Android 13 and Android 9.

react-native-notifications+4.3.3.patch

diff --git a/node_modules/react-native-notifications/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java b/node_modules/react-native-notifications/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java
index f9c858b..94ea188 100644
--- a/node_modules/react-native-notifications/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java
+++ b/node_modules/react-native-notifications/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java
@@ -2,8 +2,8 @@
 package com.wix.reactnativenotifications;
 
 import android.content.Context;
-import android.support.annotation.NonNull;
-import android.support.v4.app.NotificationManagerCompat;
+import androidx.annotation.NonNull;
+import androidx.core.app.NotificationManagerCompat;
 
 public abstract class NotificationManagerCompatFacade {
     public static NotificationManagerCompat from(@NonNull Context context) {
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..b0750d3 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();
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 a249c6a..350b0ba 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
@@ -15,6 +15,7 @@ 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;
 import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer;
@@ -66,7 +67,12 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade.
 
     @Override
     public void onActivityStarted(Activity activity) {
-        if (InitialNotificationHolder.getInstance().get() == null) {
+        boolean isReactInitialized = false;
+        if (AppLifecycleFacadeHolder.get() instanceof ReactAppLifecycleFacade) {
+          isReactInitialized = AppLifecycleFacadeHolder.get().isReactInitialized();
+        }
+
+        if (InitialNotificationHolder.getInstance().get() == null && !isReactInitialized) {
             callOnOpenedIfNeed(activity);
         }
     }
@@ -95,8 +101,7 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade.
         Intent intent = activity.getIntent();
         if (NotificationIntentAdapter.canHandleIntent(intent)) {
             Context appContext = mApplication.getApplicationContext();
-            Bundle notificationData = NotificationIntentAdapter.canHandleTrampolineActivity(appContext) ?
-                    intent.getExtras() : NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent);
+            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 70f609a..4b50cbf 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 (canHandleTrampolineActivity(appContext)) {
-            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);
-        } else {
-            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);
-        }
+        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 canHandleTrampolineActivity(Context appContext) {
@@ -32,7 +24,12 @@ public class NotificationIntentAdapter {
     }
 
     public static Bundle extractPendingNotificationDataFromIntent(Intent intent) {
-        return intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME);
+        Bundle notificationBundle = intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME);
+        if (notificationBundle != null) {
+          return notificationBundle;
+        } else {
+          return intent.getExtras();
+        }
     }
 
     public static boolean canHandleIntent(Intent intent) {
diff --git a/node_modules/react-native-notifications/lib/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java b/node_modules/react-native-notifications/lib/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java
index f9c858b..94ea188 100644
--- a/node_modules/react-native-notifications/lib/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java
+++ b/node_modules/react-native-notifications/lib/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java
@@ -2,8 +2,8 @@
 package com.wix.reactnativenotifications;
 
 import android.content.Context;
-import android.support.annotation.NonNull;
-import android.support.v4.app.NotificationManagerCompat;
+import androidx.annotation.NonNull;
+import androidx.core.app.NotificationManagerCompat;
 
 public abstract class NotificationManagerCompatFacade {
     public static NotificationManagerCompat from(@NonNull Context context) {

The key change compared to patch provided by the RocketChat is that I modified the implementation of the extractPendingNotificationDataFromIntent method. It now tries to read the bundle under PUSH_NOTIFICATION_EXTRA_NAME key, but if that's null, the it fallbacks to intent.getExtras(). See below:

public static Bundle extractPendingNotificationDataFromIntent(Intent intent) {
    Bundle notificationBundle = intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME);
    if (notificationBundle != null) {
      return notificationBundle;
    } else {
      return intent.getExtras();
    }
}

EDIT

If anyone would like to use it without dealing with patches, I created a fork with the fix.

@stale
Copy link

stale bot commented May 8, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label May 8, 2023
@claudiozam
Copy link
Author

image

@stale stale bot removed the 🏚 stale label May 8, 2023
@stale
Copy link

stale bot commented Jun 9, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Jun 9, 2023
@stale
Copy link

stale bot commented Jun 17, 2023

The issue has been closed for inactivity.

@DanielEliraz
Copy link
Collaborator

@claudiozam version 5.0.0 was released with the additions suggested here. Can you verify it's OK?

@DanielEliraz DanielEliraz reopened this Jul 20, 2023
@stale stale bot removed 🏚 stale labels Jul 20, 2023
@claudiozam
Copy link
Author

@DanielEliraz thanks for your excellent work. I am not using the library any more in my apps.

Long live and prosperity!!

@stale
Copy link

stale bot commented Sep 16, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Sep 16, 2023
@stale
Copy link

stale bot commented Oct 15, 2023

The issue has been closed for inactivity.

@stale stale bot closed this as completed Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests