Skip to content

Foreground Dispatch NDEF intent object has null type and action #80

@drunnells

Description

@drunnells

I recently attempted to bring a 3 year old project that uses ti.nfc up to date by targeting android 33, updating to Titanium SDK 12.1.2.GA and ti.nfc 5.0.0, but ran into problems scanning NDEF tags that are readable with an old build of my project. Here is my e.inent for a read of a ISO 14443-3A NXP-Mifare Classic 1k tag (Tech: NfcA,MifareClassic,Ndef) tag:

[INFO] Intent {
[INFO] url: undefined,
[INFO] type: null,
[INFO] packageName: 'com.something.something',
[INFO] className: 'org.appcelerator.titanium.TiActivity',
[INFO] action: null,
[INFO] flags: 805306368,
[INFO] data: null,
[INFO] _hasJavaListener: undefined,
[INFO] apiName: 'Ti.Android.Intent',
[INFO] bubbleParent: true
[INFO] }

Reading the tag did fire a 'newintent' event, but onNdefDiscovered, onTagDiscovered and onTechDiscovered never caught it, even though my intentFilters never changed. Catching the intents outside of foreground dispatch worked as expected.

Trying multiple combinations of different Titanium SDKs and ti.nfc versions didn't seem to help, so I can't be certain what changed or when. BUT I did find a potential fix here: https://stackoverflow.com/questions/76655730/why-nfc-works-with-pendingintent-flag-mutable-and-not-with-pendingintent-flag-im

Changing the createPendingIntent() in NfcForegroundDispatchFilter's to be FLAG_MUTABLE instead of FLAG_IMMUTABLE, with no other changes, solved my problem and I can read NDEF tags again. The e.intent now looks like:

[INFO] Intent {
[INFO] url: undefined,
[INFO] type: 'text/plain',
[INFO] packageName: 'com.something.something',
[INFO] className: 'org.appcelerator.titanium.TiActivity',
[INFO] action: 'android.nfc.action.NDEF_DISCOVERED',
[INFO] flags: 805306368,
[INFO] data: null,
[INFO] _hasJavaListener: undefined,
[INFO] apiName: 'Ti.Android.Intent',
[INFO] bubbleParent: true
[INFO] }

To be honest, this is a little over my head and I'm not sure if this is the best fix. If anyone is interested, my super minor edit can be found in pull request #79

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions