From 63f903b999f708a49bf718b978869b7873dee911 Mon Sep 17 00:00:00 2001 From: Sachin Agarwal Date: Wed, 23 Feb 2022 13:46:36 +0530 Subject: [PATCH] Fix Android 12 - FLAG_IMMUTABLE or FLAG_MUTABLE The plugin works perfectly in all devices except for Andorid 12. I get following error ``` Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent ``` I see the problem is in `createPendingIntent` Method ``` private void createPendingIntent() { if (pendingIntent == null) { Activity activity = getActivity(); Intent intent = new Intent(activity, activity.getClass()); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); pendingIntent = PendingIntent.getActivity(activity, 0, intent, 0); // Problem in the last param here } } ``` This PR solves the problem by just adding the requried flag which also works for lower android versions --- src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java b/src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java index e8256d83..198a7bc5 100644 --- a/src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java +++ b/src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java @@ -483,7 +483,7 @@ private void createPendingIntent() { Activity activity = getActivity(); Intent intent = new Intent(activity, activity.getClass()); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); - pendingIntent = PendingIntent.getActivity(activity, 0, intent, 0); + pendingIntent = PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_IMMUTABLE); } }