I've made an app from examples, for writing NFC codes on Android. My tags are NXP NTAG216.
But I have a problem: After writing tags with my app, NXP's TagWriter app shows the data as "unknown content" like this:
However, when I write the value as "Plain Text" using NXP TagWriter, I get:
Here is my code for onNewIntent:
@Override
protected void onNewIntent(Intent intent) {
// Tag writing mode
String zawartosc = "Data from field";
if (mWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
NdefRecord record = NdefRecord.createMime(zawartosc, zawartosc.getBytes(Charset.forName("UTF-8")));
NdefMessage message = new NdefMessage(new NdefRecord[]{record});
if (writeTag(message, detectedTag)) {
Toast.makeText(this, "Success", Toast.LENGTH_LONG)
.show();
}
}
}
And for writing the tag:
public boolean writeTag(NdefMessage message, Tag tag) {
int size = message.toByteArray().length;
try {
Ndef ndef = Ndef.get(tag);
if (ndef != null) {
ndef.connect();
if (!ndef.isWritable()) {
Toast.makeText(getApplicationContext(),
"Unwritable",
Toast.LENGTH_SHORT).show();
return false;
}
if (ndef.getMaxSize() < size) {
Toast.makeText(getApplicationContext(),
"Text is too short",
Toast.LENGTH_SHORT).show();
return false;
}
ndef.writeNdefMessage(message);
return true;
} else {
NdefFormatable format = NdefFormatable.get(tag);
if (format != null) {
try {
format.connect();
format.format(message);
return true;
} catch (IOException e) {
return false;
}
} else {
return false;
}
}
} catch (Exception e) {
return false;
}
}
Is there a way to somehow change the content type to the same that NXP TagWriter writes? I have a problem with reading the code properly later when it's an unknown type.