I'm trying to make an Android application to write NFC tags. To see how to do that, I've downloaded an example. However, the example does not work. It says it can't authenticate. That can only mean that it uses an incorrect key for this type of card. The strange thing is, even the KEY_DEFAULT
and KEY_MIFARE_APPLICATION_DIRECTORY
keys are not working on my blank cards. Did Mifare change the keys in any way?
EDIT: here's my code.
/* Authenticate the MAD Sector, sector 1, with key A */
succes = mClassic.authenticateSectorWithKeyA(
1, key);
if (succes) {
/* Authentication succeeded */
/*
* This will read a 16-byte block in this sector
* It is an I/O operation and will block until complete.
* It must not be called from the main application thread.
**/
b.append(mClassic.readBlock(1), 0, 16);
b.append(mClassic.readBlock(2), 0, 16);
b.append(mClassic.readBlock(3), 0, 16);
data = b.toByteArray();
}
/* Authentication failed */
else
sb.append("Authentication failed");
mClassic.close();
}
I've tried it with the following keys already:
MifareClassic.KEY_DEFAULT
MifareClassic.KEY_MIFARE_APPLICATION_DIRECTORY
00 00 00 00 00 00
ff ff ff ff ff ff
all to no avail..
I am not familiar with the Ubiqconn Tablet PC. First thing I would do is to check whether the NFC implementation in the device actually supports MIFARE. In your main activity's onCreate()
add:
public void onCreate(Bundle bundle) {
...
if (!getPackageManager().hasSystemFeature("com.nxp.mifare")) {
Toast.makeText(this, "No MIFARE support!", Toast.LENGTH_LONG).show();
}
}