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

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

Open
drunnells opened this issue Aug 29, 2023 · 1 comment
Open

Comments

@drunnells
Copy link

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

@m1ga
Copy link
Contributor

m1ga commented Sep 9, 2023

I was testing https://github.com/tidev/ti.nfc/tree/master/android/example/TagForeground/app with and without your PR and both returned the same values for me

[INFO]  {
[INFO]  action: 'android.nfc.action.NDEF_DISCOVERED',
[INFO]  messages: [
[INFO]  NdefMessage {
[INFO]  records: [Array],
[INFO]  _hasJavaListener: undefined,
[INFO]  apiName: 'Ti.Proxy',
[INFO]  bubbleParent: true
[INFO]  }
[INFO]  ],
[INFO]  tag: NfcTag {
[INFO]  techList: [ 'android.nfc.tech.NfcV', 'android.nfc.tech.Ndef' ],
[INFO]  id: '1628464C000104E0',
[INFO]  _hasJavaListener: undefined,
[INFO]  apiName: 'Ti.Proxy',
[INFO]  bubbleParent: true
[INFO]  }
[INFO]  }

That said: I don't have a real test app and different tags. But the change to MUTABLE shouldn't be hurting the module or other users. So I'll vote for including it

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

No branches or pull requests

2 participants