Configuring an NFC-enabled testing AVD
We will create and configure an AVD based on the Open NFC Android Edition image. This virtual device will be able to exchange data between the NFC Simulator tool and therefore allows us to test our applications.
Getting ready
The following are the settings required for this recipe:
- Make sure Open NFC Android Edition is properly configured in the Android SDK—refer to the Configuring the Open NFC Android add-on into your Android SDK recipe
- Make sure you have downloaded Open NFC SDK Edition—refer to the Downloading Open NFC SDK Edition recipe
- It's assumed that the Open NFC SDK Edition Core has been downloaded and extracted to the
NFCBook
folder in your home directory
How to do it…
We are going to use the Android Virtual Device Manager tool to create a device capable of simulating the NFC feature as follows:
- Open the
NFCBook
folder and navigate to the Android SDK folder. - Start SDK Manager and navigate to Tools | Manage AVDs….
- On the Android Virtual Device Manager window, click on New to open the creation wizard.
- Configure the parameters as shown in the following screenshot. The Target parameter must be Open NFC Android Edition, and the RAM should be set to a maximum value of 768 to prevent the AVD from failing to start. Also, Device should be set to a standard device and not to Galaxy Nexus or other such specific devices.
- Click on OK and start the AVD you created.
- Once the AVD finishes booting, open the application drawer and open the Settings Open NFC application, as shown in the following screenshot:
- Configure the parameters as shown in the following screenshot:
- Shut down the AVD.
How it works…
When we created the AVD, its target was the modified Android system image; so, when the AVD starts, it also starts the NFC Controller Simulator.
By default, the AVD is configured for the MicroRead controller and NFC is not enabled. We needed to change the configuration to simulator. So, we set the 10.0.2.2 IP address, which is a special alias that represents our machine, and then finally enable NFC.
There's more…
If you have a slower/older PC, or don't like to wait an infinite amount of time for the AVD to start, or you simply do not like the native simulator, there is a pretty neat alternative. Open NFC provides a VirtualBox appliance, which allows us to run Android in a virtual machine. It's a much faster and smoother alternative, and no extra configuration is needed.
We need to download an open source virtualization software and create a working Android virtual machine as follows:
- Download and install VirtualBox from https://www.virtualbox.org/.
- Download the VirtualBox appliance from the Download section on the Open NFC website.
- In VirtualBox, go to File-Import Appliance and import the downloaded one from Open NFC.
- Start the virtual machine and go to View-Switch to Scale Mode to fit the window to your screen.