如何使用 NFC Android 读取 MifareClassic 卡?
我正在使用 NFC Android 编程,我想读取 Mifare Classic 卡。有人知道如何读取此类卡的扇区吗?
我的问题是 transceive()
方法。我不知道如何用它来读取扇区 例如读取扇区1。
身份验证方法返回true,这意味着身份验证已完成。身份验证后,扇区应该准备好进行任何 IO 操作,但每当我使用 readBlock() 方法或 transceive() 方法时,我都会收到 IOException(“收发失败”) 异常。 我找不到任何使用 Mifare Classic 的示例,所以我想知道是否可以使用此 API 读取 Mifare Classic。
亲切的问候。
I am working with NFC Android programming and I want to read Mifare Classic cards. Does anybody know how to read the sectors off such a card?
My problem is the transceive()
method. I don't know how to use it to read a sector
for example to read sector 1.
Authentication method returns true which means that authentication is done. After authentication, sector should be ready for any IO action but whenever i use readBlock() method or transceive() method, I get exception with IOException("transceive failed").
I can not find any example which uses the Mifare Classic, so i want to know if it is possible to read the Mifare Classic with this API or not.
Kind Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
肯定可以使用此 API 读取 Mifare Classic - 我们有可以执行此操作的应用程序。
如果您只想读取卡,则不需要直接使用
transceive()
- 只需使用readBlock()
便捷方法即可。一个常见的陷阱是身份验证是在扇区级别完成的,而读取是在块级别完成的。在 Mifare Classic 上,一个扇区由多个块组成。不幸的是,即使在同一张卡上,每个扇区的块数也可能不同。
使用 MifareClassic.sectorToBlock(sector) 检索您进行身份验证的扇区的第一个起始块。然后,您可以读取该扇区的所有块。可以使用 MifareClassic.getBlockCountInSector(sector) 检索扇区中的块数。
如果还是不行,可以贴一下代码吗?
It is for sure possible to read Mifare Classic with this API - we have applications that do it.
You shouldn't need to use
transceive()
directly if you just want to read the card - just use thereadBlock()
convenience method.A common pitfall is that authentication is done on the sector level, whereas reading is done on a block level. On Mifare Classic, a sector is comprised of several blocks. Unfortunately, the number of blocks per sector may vary, even on the same card.
Use
MifareClassic.sectorToBlock(sector)
to retrieve the first starting block of the sector that you authenticated for. Then, you may read all blocks of that sector. The number of blocks in a sector can be retrieved withMifareClassic.getBlockCountInSector(sector)
.If it still doesn't work, can you post some code?