i have succeeded to write informations into my nfc card but now it does not work anymore, here is my code :
public void writeTag(MifareUltralight mifareUlTag) {
try {
mifareUlTag.connect();
String val=getRandomString();
// mifareUlTag.writePage(4, "rfa".getBytes(Charset.forName("US-ASCII")));
// mifareUlTag.writePage(5, "nfc".getBytes(Charset.forName("US-ASCII")));
mifareUlTag.writePage(10, val.getBytes(Charset.forName("US-ASCII")));
//mifareUlTag.writePage(7, " now".getBytes(Charset.forName("US-ASCII")));
} catch (IOException e) {
Log.e(TAG, "IOException while writing MifareUltralight...", e);
} finally {
try {
mifareUlTag.close();
} catch (IOException e) {
Log.e(TAG, "IOException while closing MifareUltralight...", e);
}
}
}
the error that happens is : android.nfc.TagLostException: Tag was lost
the getRandomString
method is a function whiche returns a random string of 3 characters.
my card is working again because i can read his number.