2

I'm trying to read NfcA tag in my application. my code is as below. i referred here and some connected SO questions for transceive commands, But I'm keep getting android.nfc.TagLostException: Tag was lost. exception.

Im using Samsung Galaxy S4 for debugging.

Is there any possibility card is not a valid card or any security shield can cause the exception?

NfcA mifare = NfcA.get(tag); // tag "TAG: Tech [android.nfc.tech.NfcA]"
if (mifare != null){
  try {
    mifare.connect();
    mifare.setTimeout(5000);
    if (mifare.isConnected()) {
      int firstBlockNum = 0;
      int lastBlockNum = 42;
      byte[] command = new byte[]{
                        (byte)0x3A,  // FAST_READ
                        (byte)(firstBlockNum & 0x0ff),
                        (byte)(lastBlockNum & 0x0ff)
      };
      byte[] result = mifare.transceive(command);
    } catch (IOException e) {
      Log.e("Error communicating with card: ", e.toString());
    }
  }
}
RDD
  • 145
  • 1
  • 18
  • What tag are you using? Does it support the command that you sent? – Michael Roland Sep 11 '17 at 11:52
  • Chip type: MF4K Chip, Frequency: 13.56MHz , through my code i found that is NfcA type card. The command i found in a SO question for NfcA type card. I'm not sure its right command for my card. – RDD Sep 11 '17 at 12:19
  • 1
    If your card is MIFARE Classic 4K, you can only communicate with it through the MifareClassic card technology. Usually sending commands through NfcA directly is not possible. Also the card does not support that specific command. – Michael Roland Sep 11 '17 at 12:31
  • Michael, does that comment also apply for MIFARE Classic 1K? – ban-geoengineering Nov 17 '17 at 21:30

0 Answers0