Changes

Jump to: navigation, search

Testing Android Studio Apps on a Physical Android Device

No change in size, 13:37, 18 July 2014
no edit summary
1. Open the Settings app on the device and select the About tablet or About phone option.
2. On the About screen, scroll down to the Build number field (Figure 46-1) and tap on it seven times until a message appears indicating that developer mode has been enabled.
[[Image:android_about_screen.png|The Build Number on the About screen of an Android 4.4 device]]
Figure 46-1
3. Return to the main Settings screen and note the appearance of a new option titled Developer options. Select this option and locate the setting on the developer screen entitled USB debugging. Enable the checkbox next to this item as illustrated in Figure 46-2 to enable the adb debugging connection.
[[Image:android_enable_usb_debugging.png|Enabling USB debugging on an Android 4.4 device]]
Figure 46-2
4. Swipe downward from the top of the screen to display the notifications panel (Figure 46-3) and note that the device is currently connected as a media device.
[[Image:android_media_device_connection.png|Android device connected notification]]
Figure 46-3
5. Select the media device notification entry and on the resulting panel (Figure 46-4) change the connection type to Camera (PTP).
[[Image:android_connect_as_camera_ptp.png|Configuring an Android device as a PTP camera device]]
Figure 46-4
</pre>
If the device is listed as offline, go to the Android device and check for the presence of the dialog shown in Figure 46-9 seeking permission to Allow USB debugging. Enable the checkbox next to the option that reads Always allow from this computer, before clicking on OK. Repeating the adb devices command should now list the device as being available:
<pre>
When an Android device is attached to a Windows system it is configured as a Portable Device. In order for the device to connect to ADB it must be configured as an Android ADB Composite Device.
First, connect the Android device to the computer system if it is not currently connected. Next, display the Control Panel and select Device Manager. In the resulting dialog, check for a category entitled Other Devices. Unfold this category and check to see if the Android device is listed (in the case of Figure 4 6-5, a Nexus 7 has been detected):
[[Image:android_windows_other_devices.png|A Nexus 7 device connected to a Window system in the wrong mode]]
Figure 46-5
Right-click on the device name and select Update Driver Software from the menu. Select the option to Browse my computer for driver software and in the next dialog, keep the Include subfolder option selected and click on the Browse… button. Navigate to the location into which the USB drivers were installed. In the case of the Google USB driver, this will be in the sdk\extras\google\usb_driver subfolder of the Android Studio installation directory (the location of which can be found in the SDK Manager). Once located, click on OK to select the driver folder followed by Next to initiate the installation.
During the installation, a Windows Security prompt will appear seeking permission to install the driver as illustrated in Figure 46-6. When this dialog appears, click on the Install button to proceed.
[[Image:installing_google_usb_driver.png|Installing the Google USB drivers]]
Figure 46-6
[[Image:google_usb_driver_installed.png|Google Windows USB Driver installed]]
Figure 46-7
Return to the Device Manager and note that the device is no longer listed under Other Devices and is now categorized as an Android Composite ADB Interface. Figure 46-8, for example, shows the device entry for a Nexus 7 tablet using the Google USB driver.
[[Image:android_android_composite_adb_device.png|Android device connected to Windows as an Android Composite ADB Interface]]
Figure 46-8
</pre>
If the device is listed as offline or unauthorized, go to the device display and check for the dialog shown in Figure 46-9 seeking permission to Allow USB debugging.
[[Image:android_allow_debugging.png|Allowing USB debugging on the Android device]]
Figure 46-9
Assuming that the adb configuration has been successful on your chosen development platform, the next step is to try running the test application created in the chapter entitled Creating an Example Android App in Android Studio on the device.
Launch Android Studio, open the AndroidSample project and, once the project has loaded, click on the run button located in the Android Studio toolbar (Figure 46-10).
[[Image:android_Studio_toolabr_run.png|The Android Studio toolbar Run button]]
Figure 46-10
Assuming that the project has not previously been configured to run automatically in an emulator environment, the Choose Device dialog will appear with the connected Android device listed as a currently running device. Figure 4 6-11, for example, lists a Nexus 7 device as a suitable target for installing and executing the application.
[[Image:android_studio_choose_device_physical.png|Choosing a physical device in the Android Studio device chooser]]
Figure 46-11

Navigation menu