简体   繁体   中英

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. 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.

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

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. 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

But you must understand that all NFC interactions are driven by Tag detection when the Tag is physically moved in to range. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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