简体   繁体   English

NFC与NFC工具,创建NDEF应用程序

[英]NFC with NFC-Tools, Creating NDEF Application

I am attempting to do what I would have guessed would be pretty simple, but as it turns out is not. 我试图做我猜想会很简单的事情,但事实证明并非如此。 I have an ACR122 NFC reader and a bunch of Mifare Classic and Mifare Ultralight tags, and all I want to do is read and write a mime-type and a short text string to each card from a Java application. 我有一个ACR122 NFC阅读器和一堆Mifare Classic和Mifare Ultralight标签,我想要做的就是从Java应用程序读取和写入每个卡的mime类型和短文本字符串。 Here's what I've got working so far: 这是我到目前为止所做的工作:

  • I can connect to my reader and listen for tags 我可以连接到我的读者并听取标签
  • I can detect which type of tag is on the reader 我可以检测到阅读器上的标签类型
  • On the Mifare Classic tags I can loop through all of the data on the tag (after programming the tag from my phone) and build an ascii string, but most of the data is "junk" data 在Mifare Classic标签上,我可以遍历标签上的所有数据(在从手机编程标签之后)并构建一个ascii字符串,但大多数数据都是“垃圾”数据
  • I can determine whether or not there is an Application directory on the tag. 我可以确定标签上是否有Application目录。

Here's my code for doing that: 这是我的代码:

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: 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, I seem to be at a loss as for how to actually create and interact with an application. 从这里开始,我似乎不知道如何实际创建应用程序并与之交互。 Once I can create the application and write Record objects to it, I should be able to write the data I need using the TextMimeRecord type, I just don't know how to get there. 一旦我可以创建应用程序并将Record对象写入其中,我应该能够使用TextMimeRecord类型编写我需要的数据,我只是不知道如何到达那里。 Any thoughts? 有什么想法吗?

::Addendum:: Apparently there is no nfc-tools tag, and there probably should be. ::附录::显然没有nfc-tools标签,可能应该有。 Would someone with enough rep be kind enough to create one and retag my question to include it? 有足够代表的人是否会善于创建一个并重新提出我的问题以包含它?

::Second Addendum:: Also, I am willing to ditch NFC-Tools if someone can point me in the direction of a library that works for what I need, is well documented, and will run in a Windows environment. ::第二个附录::此外,如果有人可以指向我的工作方向,并且有很好的文档记录,并且将在Windows环境中运行,我愿意放弃NFC工具。

Did you checked this library ? 你查过这个图书馆了吗? It is well written, how ever has poor documentation. 它编写得很好,文档很差。 Actually no more than JavaDoc. 实际上只不过是JavaDoc。

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

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