简体   繁体   English

如何测试NFC api?

[英]How to test NFC api?

I have a Nexus S with NFC and the Android API and such. 我有一个带NFC的Nexus S和Android API等。

I assume that NFC isn't simulated via the emulator (?). 我假设NFC不是通过仿真器模拟的(?)。

And I only have the one NFC enabled phone. 我只有一部支持NFC的手机。

Can I use RFID cards to test NFC apps I make? 我可以使用RFID卡测试我制作的NFC应用吗? Or will I have to get another NFC enabled phone? 或者我是否必须购买另一部支持NFC的手机?

Thanks 谢谢

This may also be of some help to you. 这也可能对你有所帮助。

FakeTagsActivity — A activity that launches tags as if they had been scanned. FakeTagsActivity - 一种可以像扫描一样启动标记的活动。 This is useful if you don't have access to NFC enabled device or tag. 如果您无法访问支持NFC的设备或标签,则此功能非常有用。

http://developer.android.com/resources/samples/NFCDemo/src/com/example/android/nfc/simulator/FakeTagsActivity.html http://developer.android.com/resources/samples/NFCDemo/src/com/example/android/nfc/simulator/FakeTagsActivity.html

NFC has two different modes: card reading/writing and phone peer-to-peer communication. NFC有两种不同的模式:读卡/写卡和电话点对点通信。 Testing card reading/writing functionality in your NFC app generally requires real cards. NFC应用中的测试卡读/写功能通常需要真实卡。 In some cases, when the card contains a so-called NDEF-formatted message that is automatically read from the card by the Android OS and delivered to your app in an Intent, you could test or simulate this by generating the corresponding Intent yourself. 在某些情况下,当卡包含所谓的NDEF格式的消息,该消息由Android操作系统自动从卡中读取并通过Intent传送到您的应用程序时,您可以通过自己生成相应的Intent来测试或模拟此消息。 In Android, peer-to-peer mode corresponds to Android Beam. 在Android中,点对点模式对应于Android Beam。 Receiving an Android beam message in your app works the same as detecting an NDEF message from a card: Android delivers the NDEF message in an Intent to your app. 在您的应用中接收Android beam消息的工作方式与检测来自卡的NDEF消息相同:Android将Intent中的NDEF消息发送到您的应用。 For all means and purposes, the Intent is virtually the same as the one delivered from a card containing the same message. 出于所有方式和目的,Intent实际上与从包含相同消息的卡交付的Intent相同。 So receiving an Android Beam message can be simulated using a card (assuming the card's memory is large enough to store the message). 因此,可以使用卡模拟接收Android Beam消息(假设卡的内存足够大以存储消息)。 For testing the sending of an Android Beam message, I cannot think of any other way than using a second phone. 为了测试发送Android Beam消息,除了使用第二部手机之外,我想不出任何其他方式。

There is also the Open NFC project, which allows you to run an Android emulator with the Open NFC stack. 还有Open NFC项目,它允许您使用Open NFC堆栈运行Android模拟器。 You can then use the NFC simulator to present any RFID card to the emulator. 然后,您可以使用NFC模拟器将任何RFID卡呈现给模拟器。

I've been using it to test my Android NFC projects. 我一直用它来测试我的Android NFC项目。 However I must say that it's quite a hassle to get it up and running. 但是我必须说,让它运行起来非常麻烦。 I also found the emulator to be unstable and loose the connection with adb. 我还发现模拟器不稳定并且与adb的连接松动。 Anyway you could give it a try: http://open-nfc.org 无论如何你可以尝试一下: http//open-nfc.org

I recommend ordering some tags online to get familiar with the technology. 我建议在线订购一些标签以熟悉该技术。 You probably do not want to do longer session through NFC anyways, so embedding some NDEF messages in tags for a one-shot is a good starting point. 您可能不希望通过NFC进行更长时间的会话,因此将一些NDEF消息嵌入标签中进行一次性拍摄是一个很好的起点。 I also got a lot out of this Android guide. 我也从这个 Android指南中获得了很多。

I have created an NFC Eclipse Plugin which might be interesting to you, it comes with a corresponding (free) Android application which does the actual NFC interfacing and should be good for entry-level NFC developers. 我已经创建了一个可能对你感兴趣的NFC Eclipse插件 ,它附带了一个相应的(免费)Android应用程序,它可以实现NFC接口,并且应该对入门级NFC开发人员有利。

Edit: Plugin now also supports some card readers :-) 编辑:插件现在也支持一些读卡器:-)

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

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