Running on a Device

It is fun to interact with your app on an emulator. It is even more fun to interact with your app on physical Android device. In this section, you will set up your system, device, and application to get GeoQuiz running on your hardware device.

First, plug the device into your computer. If you are developing on a Mac, your system should recognize the device right away. On Windows, you may need to install the adb (Android Debug Bridge) driver. If Windows cannot find the adb driver, then download one from the device manufacturer’s website.

Second, enable USB debugging on your Android device. To do this, you need to access the Developer options settings menu, which is not visible by default. To enable developer options, go to SettingsAbout Tablet/Phone. Scroll down and press Build Number seven times in quick succession. After several presses, you will see a message telling you how many steps (presses of the build number) you are from being a developer. When you see You are now a developer!, you can stop. Then you can return to Settings, see Developer options (you may need to expand the Advanced section), and enable USB debugging.

The options vary considerably across devices. If you are having problems enabling your device, visit developer.android.com/​tools/​device.html for more help.

Finally, confirm that your device is recognized by opening the Logcat tool window using its button at the bottom of Android Studio. At the top left of this window, you will see a drop-down list of connected devices (Figure 2.10). You should see your AVD, also known as your emulator, and your hardware device listed.

Figure 2.10  Viewing connected devices

Viewing connected devices

If you are having trouble getting your device recognized, verify that your device is turned on and that the USB debugging option is enabled.

If you are still unable to see your device in the devices view, you can find more help on the Android developers’ site. Start at developer.android.com/​tools/​device.html. You can also visit this book’s forum at forums.bignerdranch.com for more troubleshooting help.

Run GeoQuiz as before. Android Studio will offer a choice between running on the virtual device or the hardware device plugged into your system. Select the hardware device and continue. GeoQuiz will launch on your device.

If Android Studio defaults to your emulator without offering a choice of device to run the app on, recheck the steps above and make sure your device is plugged in. Next, ensure that your run configuration is correct. To modify the run configuration, select the app drop-down list near the top of the window, as shown in Figure 2.11.

Figure 2.11  Run configurations

Run configurations

Choose Edit Configurations... and you will be presented with a new window with details about your run configuration (Figure 2.12).

Figure 2.12  Run configuration properties

Run configuration properties

Select app in the left pane and verify that Deployment Target Options is set to Open Select Deployment Target Dialog and that Use same device for future launches is unchecked. Select OK and rerun the app. You should now be presented with a choice of device to launch the app on.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.205.159.48