chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
703 stars 547 forks source link

Fix Android 12 - FLAG_IMMUTABLE or FLAG_MUTABLE #466

Open SachinAgarwal1337 opened 2 years ago

SachinAgarwal1337 commented 2 years ago

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

Solve the issue I raised https://github.com/chariotsolutions/phonegap-nfc/issues/465

SachinAgarwal1337 commented 2 years ago

@don hey, by any chance can you look at this PR please? It will be very very helpful. Thank you in advance :)

somq commented 2 years ago

I confirm this bug happens on Android 12 and hardcrashes any app with thepluging.
The attached PR fixes it.

In the meantime: package.json

[...]
"dependencies": {
    "phonegap-nfc": "SachinAgarwal1337/phonegap-nfc#patch-1",
[...]
}

(Ping @don)

VasanthCBH commented 1 year ago

I am also confirming on this bug, and it is blocker for using the plugin in Android 12 + (12 or 13 beta). (Ping @don )

MrElectroNick commented 1 year ago

Hi @don, @krimple, @gonzalo123, @doncoleman - any updates on this?

VasanthCBH commented 1 year ago

Hi @don @gonzalo123 @doncoleman - Any update on this?

adnanebrahimi commented 1 year ago

Any Update???