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?