0

I am getting this exception:

android.nfc.TagLostException: Tag was lost.

at android.nfc.TransceiveResult.getResponseOrThrow(TransceiveResult.java:48)

at android.nfc.tech.BasicTagTechnology.transceive(BasicTagTechnology.java:151)

at android.nfc.tech.MifareClassic.authenticate(MifareClassic.java:395)

at android.nfc.tech.MifareClassic.authenticateSectorWithKeyA(MifareClassic.java:339)

at com.example.MyTag.a(MyTag.java:870)

at com.example.MyTag.fastRead(MyTag.java:368)

This is my code:

Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
MifareClassic mifareClassic = MifareClassic.get(tag);
if (MY_TAG_TIMEOUT_MILLIS != -1) mifareClassic.setTimeout(MY_TAG_TIMEOUT_MILLIS); // have tried -1, 200, 500, 1000, 2000, 3000, 4000 and 5000
if (!mifareClassic.isConnected()) mifareClassic.connect();
mifareClassic.authenticateSectorWithKeyA(15, MifareClassic.KEY_DEFAULT); // This line is causing the exception

We're getting the problem with tags which I think may not be genuine NXP.

Have tried the suggestion from this answer but it hasn't helped.

Have looked at the MifareClassic.java source code but that hasn't given me any clues.

Any idea what the underlying problem is and how to solve?

Community
  • 1
  • 1
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
  • Are you sure that the card is a MIFARE Classic 1K or 4K (i.e. not a Mini), that the sector is accessible with key A, and that key A equals `FF FF FF FF FF FF` (KEY_DEFAULT)? – Michael Roland Nov 18 '17 at 21:15
  • It's definitely 1K and each sector has the `KEY_DEFAULT` key, but I'm not sure about the authenticity of the chips as the ones I was testing with (which I'm told is from the same batch) were showing up in NXP's TagInfo app as *Unknown Manufacturer* / *Cloned IC*. – ban-geoengineering Nov 20 '17 at 19:46

1 Answers1

0

In my case, the problem occurs because you need to make the card stay in the range for a few seconds. If you take it away after you just read the card, you get this exception.

Sahin
  • 1,032
  • 14
  • 23