J1and1
J1and1

Reputation: 920

Android read NFC tag data

I am currently developing an app which will read NFC tags currently i have written the code to get TAG id what should i do next? How can i read all data if the intent extra namedEXTRA_NDEF_MESSAGES is empty.

the code for reading RFID i have for now is

public void onNewIntent(Intent intent) {
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

        String zin =  tag.getTechList()[0];
        info.setText("TagID: " + bytesToHex(tag.getId())+" Saturs: "+zin);    

 }

I would like to know how to read all data in that NFC tag.

Thank you allready!

Upvotes: 0

Views: 5381

Answers (1)

noni
noni

Reputation: 2947

Depends on your TAG's type. An example for an ultralight mifare

Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
MifareUltralight uTag = MifareUltralight.get(tagFromIntent);
uTag.connect(); //You should enclose this into a try-catch because of probably IOException
byte[] data = uTag.readPages(INDEX_OF_PAGES_YOU_WANT); //This returns 4 consecutive pages from the offset you declared. Each page weights 4 bytes
uTag.close();

Upvotes: 0

Related Questions