0

My Android app works with NFC, it works perfectly in Android 12 and lower but in Android 13, it returns java.lang.SecurityException: Permission Denial: Tag ( ID: 02 84 66 66 D5 05 99 ) is out of date. then crash in isodep.close

I look around and found some google post as link , it is marked as fixed in Android 14 but my maximum target is just Android 13. Does any one can help this?

Anh Luu
  • 176
  • 1
  • 7
  • 1
    Does this answer your question? [SecurityException while ndef.connect() on Android 13](https://stackoverflow.com/questions/75695662/securityexception-while-ndef-connect-on-android-13) – Andrew Jun 08 '23 at 03:57
  • 1
    The fix you linked is for Google to update their documentation to match reality in Android 12L upwards, Just catch the `Exception` and move on and abandon what you are trying to do. Your code will have been notified that a new `Tag` has come in to range to replace this `out of date` Tag. Do whatever you are trying to do to this new Tag Object. – Andrew Jun 08 '23 at 04:03
  • Thanks for answer @Andrew, Can you give some sample logic code in catching the exception? thanks – Anh Luu Jun 08 '23 at 04:07
  • It's the standard Java try/catch, your code should already be catching various other `Exception`s that can be generated by NFC operations, just add this to the list of exceptions caught (or generically catch all exceptions. (Without your code in the question it's hard to answer in any more detail) – Andrew Jun 08 '23 at 04:11
  • I don't think handle in try/catch is the best solution, may be in handle data and intent when communicating on resume prevent crash and continue next method – Anh Luu Jun 08 '23 at 11:08
  • The try/catch is the only solution that will work all of the time to handle this `Exception`. The Tag object can go out of date at any time, but it is more likely to happen when a Tag is coming in to range where the Tag is briefly detected before it is fully detected a second time and the old Tag object is replaced. Changing when the Tag object is used might change the chance of you trying to use the Tag object before it goes out of date but it won't prevent this `SecurityException` ever happening if the timing is just off a fraction. – Andrew Jun 08 '23 at 11:28
  • I fixed the bug @Andrew, just store the tag and reuse to create new connection whenever connecting. The problem is that time of nfc communication is too short and we must make multi Isodep connect to read and write data. – Anh Luu Jun 16 '23 at 09:24

0 Answers0