我从这个链接 (Mifare Ultralight C Lock) 得到了参考,以使 Mifare Ultralight 标签上的所有页面都只读。
我能够成功在安卓系统上写入 Mifare Ultralight 标签上的信息。现在,我想要锁定第4到第7页(或者任何特定的页面)。上述链接仅展示如何锁定所有页面。我该如何锁定特定页面?
这段代码锁定了所有页面:
mifare.transceive(new byte[] {
(byte)0xA2, /* CMD = WRITE */
(byte)0x02, /* PAGE = 2 */
(byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF /* DATA = lock pages 3..15*/
});
public static boolean writeOnMifareUltralight(Context _context, Tag tag,String pageData, int i) {
byte[]result;
MifareUltralight mifare = null;
try {
mifare = MifareUltralight.get(tag);
mifare.connect();
mifare.writePage(i, pageData.getBytes(Charset.forName("US-ASCII")));
mifare.transceive(new byte[] {
(byte)0xA2, /* CMD = WRITE */
(byte)0x02, /* PAGE = 2 */
(byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF/* DATA = lock pages 3..15*/
});
} catch (Exception ex) {
ex.printStackTrace();
Log.d("mtw", ex.getMessage());
// return false;
} finally {
try {
mifare.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
return true;
}