Android simulator ndroid SDK comes with a mobile device Simulator-it is a virtual device that can run on your computer. the android modulo allows you to preview, develop, and test Android applications without using physical devices.
The android simulator can simulate the typical functions and behaviors of all mobile devices except for answering and making calls. as shown in the figure on the right, the android simulator provides a large number of navigation and control keys. You can click these keys with the mouse or keyboard to generate events for your application. at the same time, it also has a screen for displaying the Android app and your own app.
To facilitate simulation and testing of applications, the android simulator allows your applications to call other sequences, access the network, play audio and video, save and ** data, notify users, and render image transitions and scenarios through the Android platform service.
The android simulator also has powerful debugging capabilities, such as logging the console output by the kernel, simulating program interruptions (such as receiving text messages or making phone calls), and simulating the latency and loss of data channels.
The following sections provide detailed information about simulators and how to use simulators in developing applications.
Download (130.48 KB)
Enable and disable Simulators
To start the android simulator, first enter the tools/folder of the SDK, and then enter emulator or./emulator. This operation initializes the Android system and you will see the simulator window on the screen.
To disable the simulator, you only need to close the simulator window.
Operation Simulator
You can use the startup options and console commands of the simulator to control the behaviors and features of the simulated environment. Once the simulator starts, you can press the simulator button on the keyboard and mouse to operate the simulator.
The following table summarizes the ing between the keyboard buttons and keyboard buttons of the simulator.
Simulator press the keyboard
Back ESC
Menu F1 or pgup
Start F2 or pgdn
Call F3
Hanging up F4
-F5, F6 not allocated
Power Button F7
Disable/enable f8.
Start tracing F9 (valid only when-trace flag exists)
Stop track F10 (valid only when-trace flag exists)
Home
Arrow Keys: Left/up/right/down keypad: 4/8/6/2
Arrow key center build keypad 5
Turn down the volume on the keypad (-)
Increase the volume on the keyboard plus sign (+)
Simulator startup options
The android simulator provides many startup options that you can specify when starting the simulator to control its appearance and behavior. The syntax for starting the simulator with a command line is as follows: emulator [-Option [Val]... [-qemu ARGs]
The following table summarizes all valid options.
Type option description comment
Help-help prints all the commands of the simulator in the form of a list
Data-data use <File> as the disk image of user data. If no-data exists, the simulator will ~ /. For Android (Linux/MAC) or C: \ Documents and Settings \ <user> \ Local Settings \ Android (Windows), find the file named "userdata. IMG.
If-data <File> is used but <File> does not exist, the simulator creates a file in that location.
-Ramdisk <File> uses <File> as the ram image. The default value is <system>/ramdisk. IMG.
-Sdcard <File> uses <File> as the SD card image. The default value is <system>/sdcard. IMG.
-Wipe-clear all data in the user's disk image before data is started (refer to-data)
Debug-Console allows the Current Interruption to use the console Shell
-Debug-kernel sends kernel output to the console
-Logcat <logtags> allows output classification based on the given tag. If the environment variable android_log_tags is defined and is not empty,
The value is used as the default value of logcat.
-Trace <Name> allows code profiling (start with the F9 key)
-Verbose allows detailed output.
-Verbosekeys allows detailed output of key information
Media-MIC <device or File> uses a device or WAV file as the audio output.
-Noa Io disabled Android audio support disabled by default
-Radio <device> redirects the wireless modem interface to the host feature device.
-USEA Io enabled Android audio support is disabled by default
Network-netdelay <delay> sets the delay time for network latency simulation to <delay>. The default value is none. See the supported <delay> values in the network latency simulation table"
-Netfast-netspeed full-netdelay none shortcut
-Netspeed <speed> sets the acceleration value of the network speed simulation to <speed>. The default value is full. See the supported <speed> values in the network speed simulation table"
System-image <File> use <File> as the system image. The default value is <system>/system. IMG.
-Kernel <File> uses <File> as the simulator Kernel
-Nojni
-Qemu: Pass the qemu Parameter
-Qemu-H: displays qemu help information.
-System <dir> Find the system, ram, and user data images in the <dir> directory.
UI-flashkeys the key that flashes on the device skin
-Noskin does not use any simulator skin
-Onion <image> using a cover image on the screen does not support JPEG images. Only PNG images are supported.
-Onion-Alpha <percent> specifies the translucent value (Unit: %) of the onion skin. The default value is 50.
-Skin <skinid> the specified skin startup simulator SDK provides four Skin options:
QVGA-L (320x240, landscape) (default) QVGA-P (240x320, portrait) HVGA-L (480x320, landscape) HVGA-P (320x480, portrait)
-Skindir <dir> Search for skin in the <dir> directory
Use the simulator Console
Every running simulator instance includes a console. You can use the console to dynamically query and control the simulated device environment. For example, you can use the console to dynamically manage port ing and network features, and simulate telephone time. To enter a command in the console, you need to use Telnet to connect to the Console port number.
You can use the following command to connect to any running simulator instance anytime, anywhere: Telnet localhost <port>
Copy the code. Assume that port 5554 is used on the console of the first simulator instance. The port number used by the next instance is 2, for example, 5556, 5558, or ...... . You can use the-verbose option to check the port number used by the simulator instance when starting the simulator. In the debugging output, locate the line "emulator console running on port number. In addition, you can use ADB devices in the command line to view the simulator instance and their port list. Up to 16 simulator instances can run the console simultaneously.
Note: The simulator ** port 5554-5587 is connected from any computer. In future versions, only local connections will be accepted. However, you need to use a firewall to block external connections to the 5554-5587 ports of your devices.
Once you connect to the console, you can enter help [command] to view the command list and the specified command tutorial.
To exit the console session, run the quit or exit command.
The following sections describe the main functional areas of the console.
Port redirection
You can add or delete port redirection during simulator running. After connecting to the console, you can use the following method to manage port redirection: redir <list | add | del> redir
The copy Code supports the sub-commands listed in the following table:
Sub-command description comment
List list current port redirection (Min 150, Max 550)
Add <protocol >:< host-port>: <GST-port> Add new port redirection <protocol> must be "TCP" or "p" Del <protocol>:
Network Conditions
You can use the console to detect network conditions, current latency, and acceleration features. To detect the network status, you must connect to the console and use the netstatus command. The following is an example of command and output. Network Status
Network latency simulation of code Replication
The simulator allows you to simulate multiple network latency levels, so you can test your application in a more realistic environment. You can set the latency level or range when the simulator starts, or you can dynamically modify the latency during the simulator running through the console.
To set latency during startup simulation, use the-netdelay option followed by a valid <delay> value. Here are some examples: emulator-netdelay GPRS
Emulator-netdelay 40 100
To dynamically modify the network latency during the running of the simulator, you need to connect to the console and use the netdelay command, followed by a valid <delay> value. The following table lists valid <delay> value network delay GPRS <delay>
The format of the copy code value is as follows (unit: milliseconds ):
Value description comment
GPRS (Min 150, Max 550)
Edge EDGE/EGPRS (Min 80, Max 400)
UMTS/3G (Min 35, max 200)
None no delay (Min 0, Max 0)
<Num> simulate an accurate latency (in milliseconds)
<Min>: <max> simulate a specified delay range (Min, Max millisecond)
Network speed simulation
The simulator also allows you to simulate multiple network transmission speeds. You can specify the transmission speed or range when the simulator is started, or you can dynamically modify the transmission speed on the console after the simulator is started.
To set the network transmission speed when the simulator starts, use the-netspeed option followed by a valid <speed> value. The following are some examples:
Emulator-netspeed GSM
Emulator-netspeed14.4 80
To copy the code to dynamically change the network transmission speed during simulator running, you need to connect to the console and use the netspeed command, which is followed by a valid <speed> value. The following table lists valid <speed> value network speed 14.4 80.
The format of the copy Code <speed> value is as follows (unit: kb/s ):
Value description comment
GSM/CSD (up: 14.4, down: 14.4)
HSCSD (up: 14.4, down: 43.2)
GPRS (up: 40.0, down: 80.0)
Edge EDGE/EGPRS (up: 118.4, down: 236.8)
UMTS/3G (up: 128.0, down: 1920.0)
HSDPA (up: 348.0, down: 14400.0)
Full unlimited (up: 0.0, down: 0.0)
<Num> set an accurate speed for both upstream and downstream public.
<Up>: <down> set an accurate speed for the upstream and downstream data respectively.
Telephone function simulation
The android simulator has its own GSM module that allows you to simulate the phone function on the simulator. For example, you can simulate incoming calls and establish/terminate data connections. The phone call simulation in the Android system is the same as the actual situation. This version currently does not support phone recording.
You can access the phone function of the simulator through the console. After connecting to the console, you can use GSM <CALL | data | voice>
Copy the code to call the call function.
The GSM command supports the sub-commands listed in the following table.
Sub-command description comment
Call <phonenumber> simulate a call from a phone number <phonenumber>
Voice <State> modifies the GPRS voice connection status to <State> valid <State> value:
Unregistered-no available network home-in the region network, no roaming-in the roaming network searching-find network denied-only use emergency call off-the same as 'unregistered' on-the same as 'home'
Data <State> changes the status of the GPRS data connection to <State>. Valid <State> values:
Unregistered-no available network home-in the region network, no roaming-in the roaming network searching-find network denied-only use emergency call off-the same as 'unregistered' on-the same as 'home'
Use simulator skin
You can have the simulator use one of the four skins described in the following table. To specify the skin, use the-skin <skinid> option in the startup simulator.
Example: emulator-skin HVGA-L
Note: <skinid> must be capitalized (If your development device is sensitive ).
Skin ID description
QVGA-L 320x240, landscape (default)
QVGA-P 240x320, portrait Screen
HVGA-L 480x320, landscape
HVGA-P 320x480, portrait Screen
Run multiple simulator instances
If necessary, you can run multiple simulator instances at the same time. Each simulator instance uses independent user data memory and different Console ports. This allows you to manage each simulator instance independently.
However, if you want to run multiple simulator instances, note that the capability of each instance to store persistent user data across sessions-applications set and installed by users-is limited. The details are as follows:
Only the first simulator instance can save user data according to the session. By default, it stores user data on the development device ~ /. Android/userdata. IMG (on Linux and Mac) or C: \ Documents and Settings \ <user> \ Local Settings \ Android \ userdata. IMG (on Windows) file. You can use the-data option when starting the simulator to control the storage (and loading) Location of user data (see startup options ).
The simulator instances started after the first instance (in parallel) also save user data during the session, but they do not save it for the next session. These instances store data in temporary files. When the instance exits, the corresponding temporary files will be deleted.
Install the application on the simulator
To install the application on the simulator, you must use the ADB tool.
Note: The simulator saves user settings and installed programs by restarting. By default, the simulator saves data in a file of the development device. In Linux and Mac operating systems, the simulator uploads user data in ~ /. Android/userdata. IMG. In Windows, the simulator saves data in c: \ Documents ents and Settings \ <user> \ Local Settings \ Android \ userdata. IMG. The simulator uses the content of userdata. imgfile as the data/directory.
SD card Simulation
You can create a disk image and load it when the simulator starts to simulate the user's SD card on the device. The following sections describe how to create a disk image, copy a file to a disk image, and load a mirror when the simulator starts.
Note: The disk image can only be loaded when the simulator is started. Similarly, the SD card cannot be removed when the simulator is running. However, you can browse, send, copy, and delete files on the simulated SD card through the ADB or simulator.
Note that the size of the simulated SD card cannot exceed 2 GB.
Create a disk image
You can use the mksdcard tool in the SDK to create a FAT32 disk image that can be loaded when the simulator starts. You can find mksdcard in the tools/directory of the SDK, and run the following command to check the disk image: mksdcard <size> <File>
Example:
Mksdcard 512 m sd. IMG // This will generate a m SD. imgfile in the tools directory
Start a simulator with an SD card:
Emulator-AVD G2-sdcard SD. IMG // G2 is the AVD name previously set
For more information about copying code, see other tools.
Copy a file to a disk image
Once you create a disk image, you can copy the file to the image before the simulator loads it. To copy a file, you can load the image as a cyclic device and copy the file to it. Alternatively, you can use mcopy in the mtools toolkit to directly copy the file to the image. The mtools package can be used in Linux, Mac, and windows.
Load the disk image when the simulator starts
To load a disk in the FAT32 format in the simulator, enable the simulator with the-sdcard flag and specify the image name and path (relative to the current working directory): emulator-sdcard <filepath>
Copy code troubleshooting
The ADB tool regards the simulator as a real physical device. Therefore, you need to add the-D mark when using the ADB command, such as install. -D mark allows you to specify which device to use as the Command target among multiple connected devices. If-D is not specified, the simulator selects the first device in the list. For more information about ADB, see Android debug bridge.
For simulators running on Mac OS X, if you encounter the "Warning: No DNS servers found" error when starting the simulator, check whether the/etc/resolv. conf file exists. If not, run the following command in the Command window: ln-S/private/var/run/resolv. CONF/etc/resolv. conf
For more information about how to copy the code, see FAQs.
Limitations of Simulators
This version of the simulator has the following restrictions:
Calls and calls are not supported. However, you can simulate calls (incoming and outgoing calls) on the console)
USB connection not supported
Camera/video capturing not supported
Audio input (capture) is not supported, but output (replay) is supported)
Extended headphones not supported
Unable to determine the connection status
Unable to determine battery level and AC charging status
Unable to determine the SD card insertion/pop-up
Bluetooth is not supported