Skip to content

Use pending intent flag for Android 12 - #2

Open
tylervz wants to merge 6 commits into
JohnCocks:masterfrom
tylervz:android-fix
Open

Use pending intent flag for Android 12#2
tylervz wants to merge 6 commits into
JohnCocks:masterfrom
tylervz:android-fix

Conversation

@tylervz

@tylervz tylervz commented Aug 29, 2022

Copy link
Copy Markdown

Fix app crashes on Android 12 and above. Android 12 is known to crash on launch if the Intent flag is not explicitly set to MUTABLE or IMMUTABLE.

My work is copied from this PR:
chariotsolutions#477

The MUTABLE flag is used which is the default flag for a PendingIntent activity.

https://developer.android.com/reference/android/app/PendingIntent#FLAG_MUTABLE
"Up until Build.VERSION_CODES.R, PendingIntents are assumed to be mutable by default, unless FLAG_IMMUTABLE is set. Starting with Build.VERSION_CODES.S, it will be required to explicitly specify the mutability of PendingIntents on creation with either FLAG_IMMUTABLE or FLAG_MUTABLE"

I do not have a physical device running Android 12 so I can't personally confirm that reading NFC tags works with these changes. My app is no longer crashing with this branch on the Android 12 emulator.

@Paradox7208

Copy link
Copy Markdown

@tylervz I am glad my PR helped you out. I have tested my own changes on a physical Samsung Galaxy S21 running Android 12 and I am able to scan NFC tags inside my app.

I don't have a demo I can show you at the moment because the app I applied this fix to, belongs to the company I work for.

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.

2 participants