简体   繁体   English

如何在 Android Studio (Java) 上写入 Mifare Ultralight 卡

[英]How to write to a Mifare Ultralight Card on Android Studio (Java)

I've been trying to create an app that writes data to a Mifare Ultralight NFC card but I can't seem to find any documentation that can help me.我一直在尝试创建一个将数据写入 Mifare Ultralight NFC 卡的应用程序,但我似乎找不到任何可以帮助我的文档。 The official documents are very vague.官方文件非常模糊。 I just want to write two pages of data when I press a button but I have no idea how to get the phone to detect the card and write.我只想在按下按钮时写入两页数据,但我不知道如何让手机检测到卡并写入。 I have some experience in Java but I just started using android studio.我在 Java 有一些经验,但我刚开始使用 android 工作室。

Thanks!谢谢!

So I would ignore most guides out there on the internet as they use the older enableForgroundDispatch API which is bad for writing to Tag's所以我会忽略互联网上的大多数指南,因为他们使用较旧的enableForgroundDispatch API 这不利于写入标签

So https://stackoverflow.com/a/64921434/2373819 give you the basics of NFC writing using the newer and better API but for Ndef, whereas you need to use the low level NfcA transceive method to read and write individual memory areas instead of Ndef. So https://stackoverflow.com/a/64921434/2373819 give you the basics of NFC writing using the newer and better API but for Ndef, whereas you need to use the low level NfcA transceive method to read and write individual memory areas instead Ndef。 The datasheet for the Tag give the details of set of bytes to send as commands to achieve this.标签的数据表提供了作为命令发送的字节集的详细信息以实现此目的。

https://stackoverflow.com/a/59397667/2373819 is another example but shows how to use NfcA transceive https://stackoverflow.com/a/59397667/2373819是另一个示例,但显示了如何使用NfcA transceive

But you must understand that all NFC interactions are driven by Tag detection when the Tag is physically moved in to range.但您必须了解,所有 NFC 交互都是在标签物理移动到范围内时由标签检测驱动的。 Thus doing something only on button push is harder.因此,仅在按钮按下时做某事更难。

You need to do either or both of the following.您需要执行以下一项或两项操作。

  1. Push button prompt user to bring the Tag in to range, read/write data.按钮提示用户将标签带入范围,读/写数据。

  2. When Tag comes in to range, store the Tag object and then use it when the button is pushed and handle the error if the Tag has already gone out of range (at which point you could prompt the user to bring the Tag back in to range as per 1)当标签进入范围时,存储标签 object,然后在按下按钮时使用它,如果标签已经超出范围,则处理错误(此时您可以提示用户将标签带回范围根据 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM