Receiving Notifications in Android 31+ fails because of PendingIntent Flag in RNPushNotificationHelper
See original GitHub issueBefore opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
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
-
Followed Setup Instructions https://docs.amplify.aws/lib/push-notifications/getting-started/q/platform/js/
-
Attempted to send a new notification with the pinpoint test-messaging service
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
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:19 (4 by maintainers)
Top Results From Across the Web
How to resolve "Missing PendingIntent mutability flag" lint ...
I tried this using -alpha04 and still receiving the error. I only have 1 PendingIntent for my application and not able move forward...
Read more >PendingIntent - Android Developers
Flag indicating that if the described PendingIntent already exists, ... so the PendingIntent you receive from an application could actually be one it ......
Read more >Push notifications causing a crash when targeting Android API ...
I am using the latest Backendless SDK v6.3.4 and targeting Android SDK 31. When the device receives a push notification message the ...
Read more >Android 12 PendingIntent Crash Error : r/cn1 - Reddit
for app in background to receive push notification in android 12 without ... Follow steps to build for SDK 31 and replace your...
Read more >Android 12, PendingIntent Mutability, and Geofences
Apps that target Android 12 (SDK31) must now specify a mutability flag for any pending intents. The documentation and the errors in Android...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@tannerabread Verified the patch works fine on Android 12(API 31).
Thanks for contribution @ChrisLFieldsII
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 😉