I have an app that reads the payload of an NDEF record on MIFARE Ultralight tags.
The payload packed into an NDEF Text record and the text value is in the following format:
1,10,200,Arthur smith
So there always 3 commas that separate the 3 numbers and the name.
I use NXP TagWriter to format the tag and my app can read the payload correctly. The problem is that the company I work for has used a separate company to format the tags for us. Now, when my app scans these tags there is a problem. The payload then reads:
d1,10,200,Arthur smith
This causes my app not to process the tag.
The NXP app can successfully read the tag and if I reformat the tag with the same data using NXP TagWriter then my app will correctly read the tag.
It seems that there is a 'd' in front of the payload when it comes from the formatting company that only my app can see.
Has anyone any ideas of what the 'd' is and how I can fix this?
Here is the code I use to read the payload:
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(i.getAction()) || NfcAdapter.ACTION_TAG_DISCOVERED.equals(i.getAction())) {
if(NfcScannerApplication.isCanScanNfcTag() == true){
messages = i.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
if (messages != null) {
//setContentView(R.layout.successfulnfc);
NfcScannerApplication.startNfcTimer();
//Toast.makeText(this, "NFC timer set", Toast.LENGTH_LONG).show();
Log.e(TAG, "Found " + messages.length + " NDEF messages"); // is almost always just one
vibrate(); // signal found messages :-)
// parse to records
for (int i = 0; i < messages.length; i++) {
List<Record> records = null;
try {
records = new Message((NdefMessage)messages[i]);
} catch (FormatException e) {
e.printStackTrace();
}
Log.e(TAG, "Found " + records.size() + " records in message " + i);
for(int k = 0; k < records.size(); k++) {
Log.e(TAG, " Record #" + k + " is of class " + records.get(k).getClass().getSimpleName());
Record record = records.get(k);
NdefRecord ndefRecord = record.getNdefRecord();
byte[] arr = ndefRecord.getPayload();
String payload = new String(arr);
if(payload.length() > 0){
payload = payload.substring(3, payload.length());
Log.e(TAG, "payload = " + payload);
int counter = 0;
for( int z = 0; z < payload.length(); z++ ) {
if( payload.charAt(z) == ',' ) {
counter++;
}
}
if(counter == 3){
//Toast.makeText(this, "comma count = 3 ", Toast.LENGTH_SHORT).show();
String[] splitPayload = payload.split(",");
String tagType = splitPayload[0];
String tagCompany = splitPayload[1];
String tagClientID = splitPayload[2];
String tagClientName = splitPayload[3];