Java – NFC and NFC tools to create nDef applications
I tried to do what I would guess would be simple, but it turned out not to be I have an acr122 NFC reader and a bunch of Mifare classic and Mifare ultralight tags. All I want to do is read and write the MIME type and short text string of each card from the Java application This is what I have done so far:
>I can connect to my reader and listen to the tag > what type of tag can I detect on the reader > on the Mifare classic tag, I can cycle through all the data on the tag (after the mobile phone programming tag) and build an ascii string, but most of the data is "junk" data > I can determine whether there is an application directory on the tag
This is my code:
Main:
public static void main(String[] args){ TerminalFactory factory = TerminalFactory.getDefault(); List<CardTerminal> terminals; try{ TerminalHandler handler = new TerminalHandler(); terminals = factory.terminals().list(); CardTerminal cardTerminal = terminals.get(0); AcsTerminal terminal = new AcsTerminal(); terminal.setCardTerminal(cardTerminal); handler.addTerminal(terminal); NfcAdapter adapter = new NfcAdapter(handler.getAvailableTerminal(),TerminalMode.INITIATOR); adapter.registerTagListener(new CustomNDEFListener()); adapter.startListening(); system.in.read(); adapter.stopListening(); } catch(IOException e){ } catch(CardException e){ System.out.println("CardException: " + e.getMessage()); } }
CustomNDEFListener:
public class CustomNDEFListener extends AbstractCardTool { @Override public void doWithReaderWriter(MfClassicReaderWriter readerWriter) throws IOException{ NdefMessageDecoder decoder = NdefContext.getNdefMessageDecoder(); MadKeyConfig config = MfConstants.NDEF_KEY_CONfig; if(readerWriter.hasApplicationDirectory()){ System.out.println("Application Directory Found!"); ApplicationDirectory directory = readerWriter.getApplicationDirectory(); } else{ System.out.println("No Application Directory Found,creating one."); readerWriter.createApplicationDirectory(config); } } }
From here on, I seem to be frustrated with how to really create and interact with applications Once I can create an application and write a record object, I should be able to write the data I need using the textmimerecord type. I just don't know how to get there Any ideas?
:: appendix:: obviously there is no NFC tools tag, it may be Are there enough representatives with enough ability to create one and reintegrate it into my question?
:: second appendix:: in addition, if someone can point out the direction of the library I need, and the documents are good and will run in Windows environment, I am willing to communicate with NFC tools
Solution
Have you checked this library? It is well written and poorly documented Actually no more than Javadoc