amplify-js: Receiving Notifications in Android 31+ fails because of PendingIntent Flag in RNPushNotificationHelper

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Push Notifications

Amplify Categories

notifications

Environment information

Device: Samsung Galaxy S21 Android 12 TargetSdk 31

Describe the bug

If I receive a notification in Android 12 (version 31 and above) while the app is in the background I get an exception and the app fails to display the notification.

08-23 10:08:55.709 13341 13341 I RNPushNotificationHelper: sendNotification: Intent { cmp=com.aurora_beta/com.amazonaws.amplify.pushnotification.modules.RNPushNotificationBroadcastReceiver (has extras) }

08-23 10:08:55.713 13341 13341 E RNPushNotificationHelper: java.lang.IllegalArgumentException: com.aurora_beta: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.

Expected behavior

Pinpoint notifications work fine on Android 12.

Reproduction steps

Additional information and screenshots

Works when Flag of PendingIntent in RNPushNotificationHelper is set to FLAG_IMMUTABLE or FLAG_MUTABLE https://github.com/aws-amplify/aws-sdk-android/pull/2729

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 30 (9 by maintainers)

Most upvoted comments

Any update on a fix?

Thank you @ChrisLFieldsII, while we are still working on the root cause of this issue, the docs were updated today (12/9) to show the updates with android:exported, I appreciate the comment helping others

@tannerabread Verified the patch works fine on Android 12(API 31).

Thanks for contribution @ChrisLFieldsII

When can we expect this?

Hi @ChrisLFieldsII - Yes mine is MainActivity.java and unfortunately the additonal changes to MainActivity.java actually break our build. I suspect your using Expo whereas we are not.

Anyways the main issue I am facing now seems to be more of an intermittent receiving of the PN’s at the O/S level but I suspect it might be some AWS limits on the sandboxed Pinpoint applications vs PROD that limit sends per day (they certainly do for emails) so I’m going to carry on testing in PROD as we have some test devices and user accounts I can play with.

At first I though it was an Android 9 issue but soon worked out it wasn’t as the android 9 emulator did end up receiving some and then on another test an Android 9 physical device also got one (but one only) but certainly right now its VERY intermittent.

My only change to your patch was to put back in the conditional check on !isForeground as we have a seperate Appsync in app notification when the app is open

What fun this is 😉

Hello everyone, we are aware of this issue, and we have some refactoring work for our push notifications category that we believe will resolve these issues with the newer versions of Android.

@tannerabread I’ve reverted all git patches, changes to MainActivity.java, removed all node modules, updated package.json with mentioned versions 5.0.14, successfully received push notification on my android device. Thanks

@cshfang My appologies, I interpreted it wrong. Thanks for details

@tannerabread Thank You a lot for Your response. It is first time I have response in this repo, so quick, so valuable. For some reason token was not set to store either. I took it from ReactNative.getToken module, unofficially but it worked for me ( updateEndpoit with sub, token and optOut)

I tested again on Android 9 device emulator and what I found was that initially no PN came thru so I went and heated up lunch and 5 mins later when I got back they had arrived. Android 12 device emulator seems to either receive them immediately from google servers or process them immediately and send on to app

I also have implemented @ChrisLFieldsII patch to resolve the issue. Great work and thanks for helping out the community!!

I went through a lot trying to get amplify pushnotification to work w/ android 12.

i left my patch on this issue here

Once you get past this IMMUTABILITY flag error, you then (on android 12/targetSdk 31) end up running into another error due to a notification trampoline.

It will not show in local dev though!!! Beware. You have to toggle this behavior on which most devs will not be aware of and wonder why it works locally but PMs say it doesnt work when the app is built XD