NFC tag emulation for Android virtual device (AVD)

孤人 提交于 2020-07-15 02:42:20

问题


Is there any way to develop NFC tag reading/writing applications without an NFC enabled phone? Is there a way to create an AVD which has NFC enabled? I have searched and found Open NFC exists, but I cannot find much information about it now. Is it already obsolete? Is there any other way to achieve it?


回答1:


Google never implemented support for NFC in the AVD. So there is no official support for NFC in the Android device emulator.

Back in the early days of NFC on Android, Inside Secure developed and published the NFC stack "Open NFC". Despite its name, Open NFC was not as open as its name suggested and was primarily targetting Inside's range of NFC frontends. A nice side-effect of that NFC stack was its emulator integration which resembled the capability of Nokia's NFC virtual device support for their series S40 phones. The public files for the Open NFC project are still available on SourceForge: here. However, the project has long been abandoned (probably due to selling their NFC technology to Intel).

The last version of Open NFC targets Android 4.2.1 (worked with Android 4.2.2), so if that platform was acceptable to you, you could try to setup that AVD environment. A step-by-step guide is available here: Open NFC Simulator Usage (also see here for missing components: Failed to load open-nfc addon in android platform).

The NFC stack on newer Android versions changed significantly (nowadays, the whole Android NFC stack is based on libnfc-nci which initially targetted Broadcom's NFC controllers and implemented the NFC Forum's NFC Controller Interface specification). As a consequence, the implementation of Open NFC is no longer compatible to more recent Android versions.

Note that there is still ways to do at least some limited testing through code (e.g. useful for unit tests) by injecting NFC intents. See

  • How to simulate the tag touch from other application
  • How to mock a Android NFC Tag object for unit testing
  • Is there a way to create an ACTION_NDEF_DISCOVERED intent from code
  • Testing an app by faking NFC tag scan

but note that these methods rely on internas of the Android NFC stack and you might need to go through the code for whatever Android version you are targetting to mock the right information.



来源:https://stackoverflow.com/questions/49146532/nfc-tag-emulation-for-android-virtual-device-avd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!