enter image description here I am newbie java programmer working on a NFC reader project. I've been trying to read the content of a NFC card in Android but I can't get it to work. I can only retrieve the UID of the NFC card. I went through documentation for NFC in Android and also some tutorials but I don't really understand it. I've searched a lot but I didn't a clear solution or article about reading Mifare Classic 1K text records. How can I achieve that? Really I don't know anything so please excuse me if the question is a little bit unclear. I'm using the NFC tools desktop app to write text records(screenshot below) I will appreciate any help. Thanks in advance
Here the code snippet I am using to fetch records after getting the intent on android
private void readFromIntent(Intent intent) {
System.out.println("Came huered ");
String action = intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
Parcelable[] rawMessages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
NdefMessage[] messages ;
if (rawMessages != null) {
messages = new NdefMessage[rawMessages.length];
for (int i = 0; i < rawMessages.length; i++) {
messages[i] = (NdefMessage) rawMessages[i];
NdefRecord [] records = messages[i].getRecords();
System.out.println("RECORDS "+records);
//if you are sure you have text then you don't need to test TNF
for(NdefRecord record: records){
processRecord(record);
}
}
}
}
}
public void processRecord(NdefRecord record) {
short tnf = record.getTnf();
switch (tnf) {
case NdefRecord.TNF_MIME_MEDIA: {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (record.toMimeType().equals("MIME/Type")) {
// handle this as you want
System.out.println("HEREEEE");
} else {
//Record is not our MIME
}
}
}
// you can write more cases
default: {
//unsupported NDEF Record
}
}
}