Forum / MIFARE SDK / INTag213215216.enableCounter(true) not working
Tagged: android, app, interaction counter, MIFARE SDK Lite, uid mirroring
-
I am using Mifare SDK Lite & building an Android application that writes URL to NTAG216 tags.
I want to enable counter & UID mirror as NXP TagWriter does. But it's not working.
Below is my code snippet.
After the tag is encoded, I don't see interaction counter being returned by the URL eg. (https://example.com?c=000001)
Can you help?
//Tag already has some data & writing is password protected
// After writing the URL, password protect the tag again
//
public static boolean writeURITag(String uri, INTag213215216 tag, String password) {
byte pack[] = {0, 0};
byte pw[] = password.getBytes();
try {
tag.getReader().connect();
if (!"".equals(password)) {
tag.authenticatePwd(pw, pack);
tag.clear();
}
tag.enableCounter(true);
com.nxp.nfclib.ndef.NdefRecord ndefr = createURIRecord(uri);
com.nxp.nfclib.ndef.NdefMessage ndefm = getNdefMessage(ndefr);
tag.writeNDEF(ndefm);
tag.programPWDPack(pw, pack);
tag.enablePasswordProtection(false, tag.getFirstUserpage());
tag.authenticatePwd(pw, pack);
tag.getReader().close();
}
....
//uri eg. google.com
public static com.nxp.nfclib.ndef.NdefRecord createURIRecord(final String uri) {
byte[] uriField = uri.getBytes(Charset.forName("US-ASCII"));
byte[] payload = new byte[uriField.length + 1]; //add 1 for the URI Prefix
payload[0] = 0x04; //prefixes https:// to the URI
System.arraycopy(uriField, 0, payload, 1, uriField.length); //appends URI to payload
return new NdefRecord(
NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, new byte[0], payload);
}
public static com.nxp.nfclib.ndef.NdefMessage getNdefMessage(com.nxp.nfclib.ndef.NdefRecord record) {
return new com.nxp.nfclib.ndef.NdefMessage(new com.nxp.nfclib.ndef.NdefRecord[]{record});
}
+ 0 | - 0
-
AuthorPosts
Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.