Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NFC tag emulation for Android virtual device (AVD)

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?

like image 420
Zveratko Avatar asked Mar 07 '18 07:03

Zveratko


People also ask

Can you emulate an NFC tag Android?

It's not emulating a card instead an NFC reader/writer device. Hence, you can't emulate a tag in this mode. Peer-to-peer: the phone can read and pass back ndef messages.

What is AVD used for?

An Android Virtual Device (AVD) is a configuration that defines the characteristics of an Android phone, tablet, Wear OS, Android TV, or Automotive OS device that you want to simulate in the Android Emulator. The Device Manager is an interface you can launch from Android Studio that helps you create and manage AVDs.

What is card emulation mode in NFC?

Card Emulation is an NFC mode in which an NFC device acts like a passive NFC tag such that the NFC tag can be interacted with by a different NFC device in reader/writer mode. “Tag” emulation would be a better name as the NFC device is emulating a NFC tag, but NFC has its roots in the Smart Card space.

What are NFC and HCE?

NFC is what allows for contactless payments, where you simply tap the card to a point-of-sale terminal rather than inserting it and entering a PIN. The difference with HCE is that you don't need your physical credit card – just your phone. HCE is not the first mobile payments solution that uses NFC.


1 Answers

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.

like image 176
Michael Roland Avatar answered Sep 21 '22 07:09

Michael Roland