官术网_书友最值得收藏!

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:

  1. Open the NFCBook folder and navigate to the Android SDK folder.
  2. Start SDK Manager and navigate to Tools | Manage AVDs….
  3. On the Android Virtual Device Manager window, click on New to open the creation wizard.
  4. 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.
    How to do it…
  5. Click on OK and start the AVD you created.
  6. Once the AVD finishes booting, open the application drawer and open the Settings Open NFC application, as shown in the following screenshot:
    How to do it…
  7. Configure the parameters as shown in the following screenshot:
    How to do it…
  8. 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:

  1. Download and install VirtualBox from https://www.virtualbox.org/.
  2. Download the VirtualBox appliance from the Download section on the Open NFC website.
  3. In VirtualBox, go to File-Import Appliance and import the downloaded one from Open NFC.
  4. Start the virtual machine and go to View-Switch to Scale Mode to fit the window to your screen.
主站蜘蛛池模板: 云浮市| 乐陵市| 图们市| 璧山县| 浑源县| 和顺县| 镇江市| 郸城县| 华亭县| 紫金县| 长兴县| 北碚区| 称多县| 小金县| 温州市| 嵊州市| 大姚县| 洞头县| 察哈| 彰化市| 金乡县| 和林格尔县| 河西区| 修武县| 雅安市| 西丰县| 三江| 新宁县| 韶关市| 长葛市| 高尔夫| 洛南县| 邵阳县| 娄烦县| 屯昌县| 太仆寺旗| 莫力| 新乐市| 岳池县| 凤冈县| 甘南县|