java 如何使用java创建简单的NFC程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11895523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create simple NFC program using java?
提问by pricillia
I'm a newbie learning java and nfc. Actually I really need some help about my homework "NFC programming". I try this tutorial http://open-nfc.org/wp/editions/sdk-edition/creating-a-java-example/and I still get this error msg:
我是学习java和nfc的新手。其实我真的需要一些关于我的作业“NFC编程”的帮助。我尝试了本教程http://open-nfc.org/wp/editions/sdk-edition/creating-a-java-example/ 但我仍然收到此错误消息:
Start failed !
NfcException : Error while starting the NFC Manager - Caused by NFC error DRIVER
at org.opennfc.NfcManager.start(Unknown Source)
at org.opennfc.NfcManager.getInstance(Unknown Source)
at example.Example.main(Example.java:26)
Exception in thread "main" java.lang.IllegalStateException
at org.opennfc.NfcManager.stop(Unknown Source)
at example.Example.main(Example.java:36)
Actually, what I want to run is this example code by open-nfc
实际上,我想运行的是 open-nfc 的示例代码
NfcManager mgt = NfcManager.getInstance(null);
try {
System.out.println(mgt.getProperty("open_nfc.version"));
System.out.println(mgt.getProperty("nfcc.firmware_version"));
} finally {
try {
mgt.stop();
} catch(NfcException e) {
System.out.println("Error :" + e.getMessage());
}
}
I've already start the connection center, nfc simulator, and server porting. And I have a device QPROX QP3000, already connected to my PC. I'm using eclipse juno and windows 7.
我已经启动了连接中心、nfc 模拟器和服务器移植。我有一个设备 QPROX QP3000,已经连接到我的 PC。我正在使用 eclipse juno 和 windows 7。
回答by Esteve
The line calling NfcManager.getInstance(null)
fails.
Are you sure that NfcManager.getInstance() requires a null
pareameter?
线路呼叫NfcManager.getInstance(null)
失败。你确定 NfcManager.getInstance() 需要一个null
参数吗?
After that, calling mgt.stop()
fails again with an java.lang.IllegalStateException
, maybe because it's not started.
之后,调用mgt.stop()
再次失败java.lang.IllegalStateException
,可能是因为它没有启动。
回答by Rajendra Khabiya
I have found a great article here(http://code.tutsplus.com/tutorials/reading-nfc-tags-with-android--mobile-17278) through which i learned how to communicate and make payments via NFC chips. Go through this and i hope it will solve your problem.
我在这里找到了一篇很棒的文章( http://code.tutsplus.com/tutorials/reading-nfc-tags-with-android--mobile-17278),通过它我学会了如何通过 NFC 芯片进行通信和付款。通过这个,我希望它会解决你的问题。
回答by pav
The documentation for NfcManager http://developer.android.com/reference/android/nfc/NfcManager.htmlmentions calling getSystemService(NFC_SERVICE) to create the NfcManager. Also the answer to an earlier stack overflow question How to check whether NFC is enabled or not in android?gives a simple example code snippet. Hope this helps.
NfcManager http://developer.android.com/reference/android/nfc/NfcManager.html的文档提到调用 getSystemService(NFC_SERVICE) 来创建 NfcManager。也是早期堆栈溢出问题的答案如何检查 NFC 是否在 android 中启用?给出了一个简单的示例代码片段。希望这可以帮助。