What is Android Studio AVD Emulator?
The Android Virtual Device (AVD) emulator environment bundled with Android Studio 1.x was an uncharacteristically weak point in an otherwise reputable application development environment. Regarded by many developers as slow, inflexible and unreliable, the emulator was long overdue for an overhaul. Fortunately, Android Studio 2 introduced an enhanced emulator environment providing significant improvements in terms of configuration flexibility and overall performance and further enhancements have been made for Android Studio 3.
What is The Emulator Environment?
When launched, the emulator displays an initial splash screen during the loading process. Once loaded, the main emulator window appears containing a representation of the chosen device type (in the case of Figure this is a Nexus 5X device):
Positioned along the right-hand edge of the window is the toolbar providing quick access to the emulator controls and configuration options.
The Emulator Toolbar Options
The emulator toolbar provides access to a range of options relating to the appearance and behavior of the emulator environment
Each button in the toolbar has associated with it a keyboard accelerator which can be identified either by hovering the mouse pointer over the button and waiting for the tooltip to appear, or via the help option of the extended controls panel.
Though many of the options contained within the toolbar are self-explanatory, each option will be covered for the sake of completeness:
•Exit / Minimize – The uppermost ‘x’ button in the toolbar exits the emulator session when selected while the ‘-’ option minimizes the entire window.
•Power – The Power button simulates the hardware power button on a physical Android device. Clicking and releasing this button will lock the device and turn off the screen. Clicking and holding this button will initiate the device “Power off” request sequence.
•Volume Up / Down – Two buttons that control the audio volume of playback within the simulator environment.
•Rotate Left/Right – Rotates the emulated device between portrait and landscape orientations.
•Screenshot – Takes a screenshot of the content currently displayed on the device screen. The captured image is stored at the location specified in the Settings screen of the extended controls panel as outlined later in this chapter.
•Zoom Mode– This button toggles in and out of zoom mode, details of which will be covered later in this chapter.
•Back – Simulates selection of the standard Android “Back” button. As with the Home and Overview buttons outlined below, the same results can be achieved by selecting the actual buttons on the emulator screen.
•Home – Simulates selection of the standard Android “Home” button.
•Overview – Simulates selection of the standard Android “Overview” button which displays the currently running apps on the device.
•Extended Controls – Displays the extended controls panel, allowing for the configuration of options such as simulated location and telephony activity, battery strength, cellular network type and fingerprint identification.
Working in Zoom Mode
The zoom button located in the emulator toolbar switches in and out of zoom mode. When zoom mode is active the toolbar button is depressed and the mouse pointer appears as a magnifying glass when hovering over the device screen. Clicking the left mouse button will cause the display to zoom in relative to the selected point on the screen, with repeated clicking increasing the zoom level. Conversely, clicking the right mouse button decreases the zoom level. Toggling the zoom button off reverts the display to the default size.
Clicking and dragging while in zoom mode will define a rectangular area into which the view will zoom when the mouse button is released.
While in zoom mode the visible area of the screen may be panned using the horizontal and vertical scrollbars located within the emulator window.
Resizing the Emulator Window
The size of the emulator window (and the corresponding representation of the device) can be changed at any time by clicking and dragging on any of the corners or sides of the window.
Extended Control Options
The extended controls toolbar button displays the panel illustrated in Figure 6-3. By default, the location settings will be displayed. Selecting a different category from the left-hand panel will display the corresponding group of controls:
A single location is transmitted to the emulator when the Send button is clicked. The transmission of GPS data points begins once the “play” button located beneath the data table is selected. The speed at which the GPS data points are fed to the emulator can be controlled using the speed menu adjacent to the play button.
How to add Drag and Drop Support in android?
An Android application is packaged into an APK file when it is built. When Android Studio built and ran the AndroidSample app created earlier in this book, for example, the application was compiled and packaged into an APK file. That APK file was then transferred to the emulator and launched.
The Android Studio emulator also supports installation of apps by dragging and dropping the corresponding APK file onto the emulator window. To experience this in action, start the emulator, open Settings and select the Apps & notifications option followed by the App Info option on the subsequent screen. Within the list of installed apps, locate and select the AndroidSample app and, in the app detail screen, uninstall the app from the emulator.
Open the file system navigation tool for your operating system (e.g. Windows Explorer for Windows or Finder for macOS) and navigate to the folder containing the AndroidSample project. Within this folder locate the app/build/outputs/apk/debug subfolder. This folder should contain an APK file named app-debug.apk. Drag this file and drop it onto the emulator window. The dialog shown in (Figure 6-4) will subsequently appear as the APK file is installed.
Once the APK file installation has completed, locate the app on the device and click on it to launch it.
In addition to APK files, any other type of file such as image, video or data files can be installed onto the emulator using this drag and drop feature. Such files are added to the SD card storage area of the emulator where they may subsequently be accessed from within app code.
Configuring Fingerprint Emulation
The emulator allows up to 10 simulated fingerprints to be configured and used to test fingerprint authentication within Android apps. To configure simulated fingerprints begin by launching the emulator, opening the Settings app and selecting the Security & Location option.
Within the Security settings screen, select the Use fingerprint option. On the resulting information screen click on the Next button to proceed to the Fingerprint setup screen. Before fingerprint security can be enabled a backup screen unlocking method (such as a PIN number) must be configured. Click on the Fingerprint + PIN button and, when prompted, choose not to require the PIN on device startup. Enter and confirm a suitable PIN number and complete the PIN entry process by accepting the default notifications option.
Proceed through the remaining screens until the Settings app requests a fingerprint on the sensor. At this point display the extended controls dialog, select the Fingerprint category in the left-hand panel and make sure that Finger 1 is selected in the main settings panel:
Click on the Touch the Sensor button to simulate Finger 1 touching the fingerprint sensor. The emulator will report the successful addition of the fingerprint: