Search code examples
androidnfcsmartcardndefcontactless-smartcard

Get the data payload of a tag


I have some card which uses NFC (e.g. a student ID card or a debit card). These cards don't use NDEF for store data. How can I get the payloads of these cards?

Currently, I use this code:

if (intent.getAction() != null && NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction()))
{
    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
}

Can anyone spot how can I get the payload of the tag?

The card's technologies are android.nfc.tech.IsoDep and android.nfc.tech.NfcA.


Solution

  • You could get NfcA object as this:

    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    NfcA nfcA = NfcA.get(tag);
    

    After you could communicate with tag by sending APDU's as this:

    byte[] apdu = [...];
    byte response = nfcA.transceive(apdu);