nfcim/flutter_nfc_kit

Android 13+ SecurityException when writing tags

yvesPresent opened this issue · 2 comments

When attempting to write NFC Tag with NDefRecords (whatever kind), i receive that exception on Android 13+

PlatformException(503, Tag already removed, Permission Denial Tag ( ID: xxxx) is out of date, null)

this would be liked to a change in Android 12L / 13+ :

revtel/react-native-nfc-manager#629
SecurityException is thrown when trying to check whether a tag can be made read-only.

That would be linked to native method call (kotlin) "writeNdef"
https://github.com/nfcim/flutter_nfc_kit/blob/master/android/src/main/kotlin/im/nfc/flutter_nfc_kit/FlutterNfcKitPlugin.kt

"if (!ndef.isWritable) {"
which would cause issues on Android 13+

There is also that StackOverflow answer which say we should call isWritable on a particular event callback : onResume.
https://stackoverflow.com/a/75741753

I'm no native Android developper, i've simply gathered as much information as i could on that issue.

Thanks for pointing this out! But seems there's not much we can do on our side, because:

  1. Flutter does not use conventional Android lifetime.
  2. Android limits the use of stored Tag in its API.

Maybe you can try to do poll - writeNdef without delay. If that works, you might want to reconsider your logic and avoid do time-consuming things in between.

Ok, thanks Harry-Chen.
Indeed after extra tests the issue only occur when debugging and the tag actually moves between pool and write calls.
It does not happen normally when out of debug, so that's ok.

You can close this ticket.
Thank you.