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

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.
主站蜘蛛池模板: 西城区| 巧家县| 全南县| 尼木县| 额尔古纳市| 晴隆县| 海口市| 大同市| 阿鲁科尔沁旗| 柞水县| 沁阳市| 台安县| 安远县| 镶黄旗| 社会| 乐平市| 台湾省| 吉隆县| 夏河县| 都昌县| 镇安县| 应用必备| 观塘区| 黄浦区| 贵德县| 喜德县| 双峰县| 禹州市| 永寿县| 友谊县| 凤冈县| 镇坪县| 连南| 尼勒克县| 六盘水市| 潮安县| 城固县| 罗定市| 囊谦县| 广水市| 临高县|