Skip to content
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

Fix Android 12 PendingIntent #2130

Merged
merged 1 commit into from
Aug 30, 2021
Merged

Fix Android 12 PendingIntent #2130

merged 1 commit into from
Aug 30, 2021

Conversation

cristianoccazinsp
Copy link
Contributor

Fix Android 12 (SDK 31) notifications due to missing PendingIntent flags.

Fixes #2129

I've tested this on a Pixel 5 with Android 12 and a RN app compiled with SDK 31. However, I've only tested local notifications, but I expect that the change should work across all notifications as it is very simple.

Fix Android 12 (SDK 31) notifications due to missing PendingIntent flags.
@Dallas62 Dallas62 changed the base branch from master to dev August 30, 2021 21:24
@Dallas62 Dallas62 merged commit 381889d into zo0r:dev Aug 30, 2021
@Dallas62
Copy link
Collaborator

Hi @cristianoccazinsp
Thanks for your contributions !

@cristianoccazinsp
Copy link
Contributor Author

cristianoccazinsp commented Sep 1, 2021

Dallas62 added a commit that referenced this pull request Sep 2, 2021
@Dallas62
Copy link
Collaborator

Dallas62 commented Oct 1, 2021

Hi @cristianoccazinsp
This change affect some functionalities: #2152
Since I don't have time to investigate, do you have an idea ?

@cristianoccazinsp
Copy link
Contributor Author

@Dallas62 I think the issue may be related to using PendingIntent.FLAG_IMMUTABLE instead of FLAG_MUTABLE. I don't currently have code that uses #2152 code, but perhaps @redexp or @TongManhCong can help testing the change.

@Dallas62
Copy link
Collaborator

Dallas62 commented Oct 1, 2021

@redexp @TongManhCong

You can try to change :
https://github.com/zo0r/react-native-push-notification/blob/master/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java#L536

by:

                    int flags = PendingIntent.FLAG_UPDATE_CURRENT;

                    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                      if(action.equals("ReplyInput")) {
                        flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE;
                      }
                      else {
                        flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
                      }
                    }

Regards

@cristianoccazinsp
Copy link
Contributor Author

That seems like an even more reasonable fix, checking for reply input as well.

What are the side effects of marking an intent as mutable?

@ammarahm-ed
Copy link

ammarahm-ed commented Oct 14, 2021

The current fix has broken ReplyInput. reply_text is not returned by onAction because PendingIntent.FLAG_IMMUTABLE is set.

@Dallas62 PendingIntent.FLAG_MUTABLE was added in SDK 31. I think we will need a separate check for SDK 31.

azundo pushed a commit to azundo/react-native-push-notification that referenced this pull request Nov 3, 2022
azundo pushed a commit to azundo/react-native-push-notification that referenced this pull request Nov 3, 2022
elburu pushed a commit to elburu/react-native-push-notification that referenced this pull request Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android 12: Notifications will no work/crash with SDK 31
3 participants