我从此链接 ( Mifare Ultralight C Lock ) 获得了参考,将 Mifare Ultralight 标签上的所有页面设为只读。
我可以在 Android 上成功地在 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;
}