我是 NFC Android 新手,在设置密码后,我一直试图在 NTAG213 中写入数天,
但它失败了,我不知道会发生什么,任何人都可以帮助我更新有关代码的更多信息
// write PACK:
mifareUltralight
.writePage(
pageOffset: 44, data: Uint8List.fromList([pack[0], pack[1], 0, 0]))
.then((value) {
setState(() {
messageTXT = 'write PACK';
});
});
// write PWD:
mifareUltralight
.writePage(
pageOffset: 43,
data: Uint8List.fromList([pwd[0], pwd[1], pwd[2], pwd[3]]))
.then((value) {
setState(() {
messageTXT = 'write PWD';
});
});
//set PROT
bool prot =
false; // false = PWD_AUTH for write only, true = PWD_AUTH for read and write
int authlim = 0;
// value between 0 and 7
mifareUltralight
.transceive(
data: Uint8List.fromList([
0xA2, // WRITE
42, // page address
((object[0] & 0x078) | (prot ? 0x080 : 0x000) | (authlim & 0x007)),
object[1], object[2], object[3]
]))
.then((value) {
setState(() {
messageTXT = 'PWD_AUTH for write only0';
});
});
// set AUTH0
int auth0 = 0x00;
// value between 0 and 7
mifareUltralight
.writePage(
pageOffset: 41,
data: Uint8List.fromList([
object1[0], // keep old value for byte 0
object1[1], // keep old value for byte 1
object1[2],
auth0
]))
.then((value) {
setState(() {
messageTXT = 'PWD_AUTH for write only2';
});
});
}
mifareUltralight
.transceive(
data: Uint8List.fromList([0x1B, pwd[0], pwd[1], pwd[2], pwd[3]]))
.then((value) {
if ((value != null) && (value.length >= 2)) {
Ndef ndef = Ndef.from(tag);
try {
NdefMessage message = NdefMessage([
NdefRecord.createUri(Uri.parse(url)),
]);
ndef.write(message).then((value) {
print('write success');
});
} catch (e) {
print(e.toString());
}
}
});