NFC tag emulation for Android virtual device (AVD)
Asked Answered
S

1

36

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?

Syst answered 7/3, 2018 at 7:39 Comment(2)
Maybe directly sending the intent is option for reading NFC. This can be probably done through adb CLI.Syst
I suggest to simply mock all the required NFC stuff. Mocking NFC intents can be done without any additional framework, whereas mocking NFC tags might be easier with a Mockito-like framework.Pesce
T
25

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 targeting 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 targeted 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

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

Throne answered 15/3, 2018 at 7:27 Comment(3)
I guess this is it, dead end at least for testing how to write. The read can somehow be imitated by sending the intent, but still the simplest way to go is NFC enabled phone.Syst
@Syst Correct. Also, what I didn't mention in my post is that you can mock NFC intents. See my updated post.Throne
Have you found an adequate solution? I am wondering the same.Regnant

© 2022 - 2024 — McMap. All rights reserved.