Android SDK Getting Started Guide||Chapter 11 Virtual and Physical Devices

Chapter 11 Virtual and Physical Devices

In the previous article, everyone has already understood the basic elements of the Android project, and has been exposed to the design of the user interface and the data storage solution. Next, we'll explore how to run and interact with your applications on physical and virtual devices. In the next article in the series, we will explain step by step how to make the application run on physical devices and emulators. In today's tutorial, I will take you to learn how to set up physical and virtual devices in Eclipse.

When you develop Android applications that will be released to the public, you must test your products in physical machines and simulators in advance. On the simulator side, we can configure the virtual device to have various hardware and software functions. Although the effect of this processing may not be as reliable as on a variety of physical devices, it is enough to help us understand the differences between the device at hand and the Android devices that may be contacted externally. Certain hardware and software features are not available in the emulator, but you can still test most features in your first app.

1. Hardware equipment

first step

When you develop an Android application, you should first pay attention to how the results run on the physical hardware device. In addition to actually giving us the look, feel, and user functionality of our applications, hardware devices are also our only way to test certain features, such as phone calls. If you happen to have a hardware device at hand during the development process, you can also configure the simulator to have exactly the same hardware and software functions, so that you can run tests while developing.

Let's first connect the hardware device with Eclipse. The USB interface that connects Android devices and computers is familiar to everyone. We may need to enable USB debugging on the device. The specific steps are to open the device's settings screen, select "Developer Options", "Level Settings" or "Applications", and then select "Develop". Then check the USB debugging item. If the device you are using is running Android 4.2 or higher, you may need to set the developer options to display properly. Open "About phone" and tap "Build number" multiple times (seven times) in the list before returning to the previous screen.

Tip: You may also need to let your system automatically detect the Android device when it is connected; yes, in most cases this detection will be performed by default, but we still need to be on guard. If your Windows system cannot detect the corresponding device, please
download
and install the USB driver. If you are using Linux and are having trouble detecting your device, you may want to use the udev file and see the device manufacturer listed in it. If you still can't figure it out, please
click here
to view the corresponding instructions in the official Android Developer Guide.

second step

Once the system detects the Android device we are connected to, we can interact with it in Eclipse. In the next tutorial, we will explain in detail how to handle these tasks, so please feel free to look forward to it. Now we just need to switch to the DDMS view. In Eclipse, select "Window", "Open View" and then "DDMS". You should see your connected device in the device view on the left side of the screen. In addition, you will also see messages starting to pop up in the LogCat view, indicating that processing of the device is in progress.

Next, please take a moment to select your device in the device view and carefully view its contents through the file browsing view. We will see each file and folder saved on the device. As you can see, these views allow us to do whatever we want with the connected device, including running, testing, and debugging our own applications on it. You can also use various buttons in the device view, including a screenshot button - when you're ready, you may want to capture a few moments to use as introductory material for your app.

2. Virtual device

first step

Now let's see how to create a virtual device. In Eclipse, select "Window" and click "Android Virtual Device Manager (AVD Manager)" to open it. Two tabs will be displayed in the AVD Manager, one for displaying the virtual devices we created and started, and the other for managing reusable device definitions. In the future development process, you may need to create your own AVD through configuration to test certain functions of the application; but as an initial study, we will find that it is obviously faster and more efficient to directly use the existing device definition. convenient. Now switch to the "Device Definition" tab.

You will see a list of device definitions in the AVD Manager. In this way, we can save the device configuration for future reuse. You can also create your own device definition by clicking the "New Device" button. After clicking, we will see the interface as shown below.

11.1new_device

Here, you can fully configure the hardware and software of the virtual device, including screen size, resolution, sensor, camera, input method, pixel density, buttons, etc. After creating a new device, the configuration appears in the list of existing definitions. You should try to give your configuration definitions a meaningful name so that we can find them in the list more easily. But for now, let's use the existing definition to test the application in hand, and click "Cancel" to exit the current interface.

second step

You can use an existing device definition in two ways: directly copy the current device definition and modify its properties, or directly create a virtual device instance based on the existing definition. Select a device in the list and click Clone.

11.2clone_device

Each input box in the Clone Device window will be automatically populated to match the selected definition. The configuration of the existing device is basically consistent with our requirements, so all device attributes can be retained. Just click "Clone Device". A copy of the device definition will appear in the list.

11.3clone_device_list

As you can see, we can clearly determine which are the default solutions and which are customized solutions through the color difference between the Android device definition and the user device definition. You can only edit user definitions, so select the cloned device you just created in the list and click "Edit."

11.4edit_device

Now we can edit various properties of the device. After completion, click "Edit Device" to apply the configuration plan. Now you can create AVD instances based on the device definitions in the list.

third step

As long as you create an AVD based on the current device definition and run it in the emulator, you can see that one of the device definitions starts to take effect. Select a device definition from the list and click "Create AVD". In the window, we can configure the instance or simply keep all settings in the definition. Regarding the specific situation of the AVD option list, you can  click here  to view the relevant instructions in the Android Developer Guide. Now click "OK" to create the AVD.

11.5create_avd

Eclipse will switch back to the Android Virtual Devices tab, where our new device will appear. After selecting the new AVD, click "Start" to put it into operation.

11.6created_devices

Click "Launch" in the pop-up window, and Eclipse will start running the emulator equipped with our custom AVD. The device may take a few minutes to complete booting. Once the device is running, you can close the AVD Manager.

the fourth step

Under appropriate conditions, the emulator displays a virtual version controlled by the device hardware. You can interact with it through mouse clicks. In addition, the simulator also supports a variety of keyboard shortcut combinations, which can greatly simplify our daily operations after getting used to them - for example, the "Home" key on the device corresponds to the "Home" key on the keyboard. You can  click here  to view the list of emulator shortcut keys listed in the Android Developer Guide.

11.7device_display

Depending on the AVD you created, we may need to press F2 or click "OK" to unlock the screen. As you can see, the simulator behaves exactly like a physical device. Now please take a moment to explore the virtual device, check out the application menu, and launch a few applications to try.

11.8explore_device

Launch the browser application in the virtual device from the front. Click the navigation bar and enter the URL you want to visit. Everyone can use a computer keyboard as an input device. The emulator automatically uses an available internet connection on any computer so we can evaluate its web connectivity capabilities when testing the application.

11.9device_browser

the fifth step

Now keep the AVD running, switch back to Eclipse and open the DDMS view again. You will see that your virtual device has appeared in the list in the device view, and the connected physical device will also be displayed next to it. Eclipse will display a list of all processes currently running on the device. After selecting a process, we can use multiple function buttons in the device view to process it. Please take a moment to observe this interface carefully now. They will become a good helper for us in debugging applications in the future.

11.10avd_ddms

Summarize

Now we are familiar with the entire process of using hardware or simulated devices in Eclipse. In the next tutorial, we will officially start running the application on devices from Eclipse. In subsequent articles, we will also discuss Android common components and Activity cycles to help everyone clarify the direction of future learning. After you have developed a few applications, you may also be willing to go back and review this series of tutorials. I hope these articles can serve as guidance and reference for friends in the process of application creation and device interaction.

Guess you like

Origin blog.csdn.net/m0_69824302/article/details/132766576