Android Document  SDK old PDF 파일
Android Emulator
작성자
작성일 2008-03-07 (금) 22:38
ㆍ추천: 0  ㆍ조회: 8203      
IP: 221.xxx.120

Android Emulator

The Android SDK includes a mobile device emulator — a virtual device that runs on your computer.
The emulator lets you prototype, develop, and test Android applications without using a physical device.
The Android emulator mimics all of the typical functions and behaviors of a mobile device, except that
it can not receive or place phone calls. As shown at right, the emulator provides a variety of navigation
and control keys, which you can "press" using your mouse or keyboard to generate events for your
application. It also provides a screen in which your application is displayed, together with any other
Android applications running.
 
To help you model and test your application, the emulator lets your application use the services of the
Android platform to invoke other applications, access the network, play audio and video, store and retrieve
data, notify the user, and render graphical transitions and themes.
 
The emulator also includes a variety of debug capabilities, such as a console from which you can log
kernel output, simulate application interrupts (such as arriving SMS messages or phone calls), and
simulate latency effects and dropouts on the data channel.
 
The sections below provide more information about the emulator and how to use it when developing
your applications.

Contents

Starting and Stopping the Emulator
Controlling the Emulator
Emulator Startup Options
Using the Emulator Console
Port Redirections
Network Status
Network Delay Emulation
Network Speed Emulation
Telephony Emulation
SMS Emulation
Using Emulator Skins
Running Multiple Instances of the Emulator
Installing Applications on the Emulator
SD Card Emulation
Creating a Disk Image
Copying Files to a Disk Image
Loading the Disk Image at Emulator Startup
Troubleshooting Emulator Problems
Emulator Limitations

Starting and Stopping the Emulator

To start the emulator, change to the tools/ folder of the SDK and enter emulator or ./emulator.
This initializes the Android system and you will see the emulator window appear on your screen.
To stop the emulator, close the emulator window.

Controlling the Emulator

You can use emulator startup options and console commands to control the behaviors and characteristics
of the emulated environment. Once the emulator is running, you can control it by using use your mouse
pointer or keyboard keys to "press" the simulated device keys.
 
The table below summarizes the mappings between the emulator keys and and the keys of your keyboard.
Emulator Key Keyboard Key
Back ESC
Menu F1 or PgUp
Star F2 or PgDn
Call F3
End Call F4
---- F5, F6 unassigned
Power button F7
Disable/enable all networking F8
Start tracing F9 (only with -trace flag)
Stop tracing F10 (only with -trace flag)
Home HOME
DPad left/up/right/down Keypad 4/8/6/2
DPad center click Keypad 5
Rotate skin Keypad 7/9
Volume up/down Keypad +/-
Onion alpha increase/decrease Keypad * / /
Toggle Unicode/raw key mode Ctrl-K

Emulator Startup Options

The emulator supports a variety of options that you can specify when launching the emulator, to control
its appearance or behavior. Here's the command-line usage for launching the emulator with options:
emulator [-option [value]] ... [-qemu args]
The table below summarizes the available options.
Category Option Description Comments
Help -help Print a list of all emulator commands.  
Data -data <file> Use <file> as the working user-data disk image. If -data is not used, the emulator looks for a file named "userdata.img" in ~/.android (on Linux/Mac) or C:documents and Settings<user>Local SettingsApplication DataAndroid (on Windows). If you use -data <file> but <file> does not exist, the emulator creates a file at that location.
See Running Multiple Emulator Instances for information about how to use -data to let multiple emulator instances preserve their user data across sessions.
-ramdisk <file> Use <file> as the ramdisk image. Default value is <system>/ramdisk.img
-sdcard <file> Use <file> as the SD card image. Default value is <system>/sdcard.img
-wipe-data Delete all data on the user-data disk image (see -data) before starting.  
Debug -console Enable console shell on the current terminal.  
-debug-kernel Send kernel output to the console.  
-logcat <logtags> Enable logcat output with given tags. If the environment variable ANDROID_LOG_TAGS is defined and not empty, its value will be used to enable logcat output by default.
-trace <name> Enable code profiling (press F9 to start), written to a specified file.  
-verbose Enable verbose output.  
-verbose-keys Enable verbose key-press messages.  
-verbose-proxy Enable verbose proxy debug messages.  
Media -mic <device or file> Use device or WAV file for audio input.  
-noaudio Disable Android audio support.  
-radio <device> Redirect radio modem interface to a host character device.  
-useaudio Enable Android audio support. Enabled by default.
Network -netdelay <delay> Set network latency emulation to <delay>. Default value is none. See the table in Network Delay Emulation for supported <delay> values.
-netfast Shortcut for -netspeed full -netdelay none  
-netspeed <speed> Set network speed emulation to <speed>. Default value is full. See the table in Network Speed Emulation for supported <speed> values.
-http-proxy <proxy> Make all TCP connections through a specified HTTP/HTTPS proxy The value of <proxy> can be one of the following:
http://<server>:<port>
http://<username>:<password>@<server>:<port>
The http:// prefix can be omitted. If the -http-proxy <proxy> command is not supplied, the emulator looks up the http_proxy environment variable and automatically uses any value matching the <proxy> format described above.
System -image <file> Use <file> as the system image. Default is <system>/system.img
-kernel <file> Use <file> as the emulated kernel.  
-nojni Disable JNI checks in the Dalvik runtime.  
-qemu Pass arguments to qemu.  
-qemu -h Display qemu help.
-system <dir> Search system, ramdisk and user data images in <dir>.  
UI -flashkeys Flash key presses on the device skin.  
-raw-keys Disable Unicode keyboard reverse-mapping.  
-noskin Don't use any emulator skin.  
-onion <image> Use overlay image over screen. No support for JPEG. Only PNG is supported.
-onion-alpha <percent> Specify onion skin translucency value (as percent). Default is 50.
-skin <skinID> Start the emulator with the specified skin. The SDK includes a choice of four skins:
  • HVGA-L (480x320, landscape)
  • HVGA-P (320x480, portrait) (default)
  • QVGA-L (320x240, landscape)
  • QVGA-P (240x320, portrait)
  • -skindir <dir> Search for emulator skins in <dir>.  

    Using the Emulator Console

    Each running emulator instance includes a console facility that lets you dynamically query and control
    the simulated device environment. For example, you can use the console to dynamically manage port
    redirections and network characteristics and simulate telephony events. To access the console and enter
    commands, you use telnet to connect to the console's port number.
     
    To connect to the console of any running emulator instance at any time, use this command:
    telnet localhost <console-port>
    An emulator instance occupies a pair of adjacent ports: a console port and a debug port. The port numbers
    differ by 1, with the debug port having the higher port number. The console of the first emulator instance
    running on a given machine uses port 5554 and the debug port uses port 5555. Subsequent instances use
    port numbers increasing by two — for example, 5556/5557, 5558/5559, and so on. Up to 16 concurrent
    emulator instances can run a console facility.
     
    To connect to the emulator console, you must specify a valid console port. If multiple emulator instances
    are running, you need to determine the console port of the emulator instance you want to connect to.
    To find out the console port of an emulator instance, you can start it with the -verbose option and look in
    the debug output for the line beginning "emulator console running on port number". Alternatively, you can
    use the adb command adb devices, to see a list of emulator instances and the debug ports they are using.
    Here's an example of the output:
    $ adb devices
    List of devices attached 
    1  emulator-tcp-5555  device  0
    2  emulator-tcp-5557  device  0
    3  emulator-tcp-5559  device  0
    The console port for each instance is always 1 less than the debug port listed. For example, in the case
    of the emulator instance listed above as 2  emulator-tcp-5557  device  0, the console port would be 5556.

    Note: The emulator listens for connections on ports 5554-5587, from any computer. In a future release,

    the emulator will accept connections only from localhost, but until then, you should use a firewall to block

    external connections to your development machine on those ports.


    Once you are connected to the console, you can then enter help [command] to see a list of console
    commands and learn about specific commands.
     
    To exit the console session, use quit or exit.
    The sections below describe the major functional areas of the console.

    Port Redirection

    You can use the console to add and remove port redirections while the emulator is running. After connecting
    to the console, you can manage port redirections in this way:
    redir <list|add|del> 
    The redir command supports the subcommands listed in the table below.
    Subcommand Description Comments
    list List the current port redirections.  
    add <protocol>:<host-port>:<guest-port> Add a new port redirection.
  • <protocol> must be either "tcp" or "udp"
  • <host-port> is the port number to open on the host
  • <guest-port> is the port number to route data to on the emulator/device
  • del <protocol>:<host-port> Delete a port redirection. See above for meanings of <protocol> and <host-port>.

    Network Status

    You can use the console to check the network status and current delay and speed characteristics. To do so,
    connect to the console and use the netstatus command. Here's an example of the command and its output.
    network status
    

    Network Delay Emulation

    The emulator lets you simulate various network latency levels, so that you can test your applicaton in an
    environment more typical of the actual conditions in which it will run. You can set a latency level or range
    at emulator startup or you can use the console to change the latency dynamically, while the application is
    running in the emulator.
     
    To set latency at emulator startup, use the -netdelay emulator option with a supported <delay> value, as
    listed in the table below. Here are some examples:
    emulator -netdelay gprs
    emulator -netdelay 40 100
    To make dynamic changes to network delay while the emulator is running, connect to the console and
    use the netdelay command with a supported <delay> value from the table below.
    network delay gprs
    The format of network is one of the following (numbers are milliseconds):
    Value Description Comments
    gprs GPRS (min 150, max 550)
    edge EDGE/EGPRS (min 80, max 400)
    umts UMTS/3G (min 35, max 200)
    none No latency (min 0, max 0)
    <num> Emulate an exact latency (milliseconds).  
    <min>:<max> Emulate an specified latency range (min, max milliseconds).  

    Network Speed Emulation

    The emulator also lets you simulate various network transfer rates. You can set a transfer rate or range
    at emulator startup or you can use the console to change the rate dynamically, while the application is
    running in the emulator.
    To set the network speed at emulator startup, use the -netspeed emulator option with a supported <speed>
    value, as listed in the table below. Here are some examples:
    emulator -netspeed gsm
    emulator -netspeed 14.4 80
    To make dynamic changes to network speed while the emulator is running, connect to the console and
    use the netspeed command with a supported <speed> value from the table below.
    network speed 14.4 80
    The format of network <speed> is one of the following (numbers are kilobits/sec):
    Value Description Comments
    gsm GSM/CSD (Up: 14.4, down: 14.4)
    hscsd HSCSD (Up: 14.4, down: 43.2)
    gprs GPRS (Up: 40.0, down: 80.0)
    edge EDGE/EGPRS (Up: 118.4, down: 236.8)
    umts UMTS/3G (Up: 128.0, down: 1920.0)
    hsdpa HSDPA (Up: 348.0, down: 14400.0)
    full no limit (Up: 0.0, down: 0.0)
    <num> Set an exact rate used for both upload and download.
    <up>:<down> Set exact rates for upload and download separately.

    Telephony Emulation

    The Android emulator includes its own GSM emulated modem that lets you simulate telephony functions
    in the emulator. For example, you can simulate inbound phone calls and establish/terminate data
    connections. The Android system handles simulated calls exactly as it would actual calls. The emulator
    does not support call audio in this release.
     
    You can use the console to access the emulator's telephony functions. After connecting to the console,
    you can use
    gsm <call|cancel|data|voice|status> 
    to invoke telephony functions.
    The gsm command supports the subcommands listed in the table below.
    Subcommand Description Comments
    call <phonenumber> Simulate an inbound phone call from <phonenumber>.  
    cancel <phonenumber> Cancel an inbound phone call from <phonenumber>.  
    voice <state> Change the state of the GPRS voice connection to <state>. Supported <state> values are:
  • unregistered -- No network available
  • home -- On local network, non-roaming
  • roaming -- On roaming network
  • searching -- Searching networks
  • denied -- Emergency calls only
  • off -- Same as 'unregistered'
  • on -- Same as 'home'
  • data <state> Change the state of the GPRS data connection to <state>. Supported <state> values are:
  • unregistered -- No network available
  • home -- On local network, non-roaming
  • roaming -- On roaming network
  • searching -- Searching networks
  • denied -- Emergency calls only
  • off -- Same as 'unregistered'
  • on -- same as 'home'
  • status Report the current GSM voice/data state. Values are those described for the voice and data commands.

    SMS Emulation

    The Android emulator console lets you generate an SMS message and direct it to an emulator instance.
    Once you connect to an emulator instance, you can generate an emulated incoming SMS using this
    command:
    sms send <senderPhoneNumber> <textmessage>
    where <senderPhoneNumber> contains an arbitrary numeric string.
    The console forwards the SMS message to the Android framework, which passes it through to an
    application that handles that message type.

    Using Emulator Skins

    You can run the emulator with any of four default skins, as described in the table below. To specify a skin,
    use -skin <skinID> when starting the emulator.
     
    For example:
    emulator -skin HVGA-L
    Note that you must enter the <skinID> in uppercase letters (if your development computer is case-sensitive).
    skinID Description Skin
    HVGA-L 480x320, landscape
    HVGA-P 320x480, portrait (default)
    QVGA-L 320x240, landscape
    QVGA-P 240x320, portrait

    Running Multiple Emulator Instances

    You can run multiple instances of the emulator concurrently, if necessary. Each emulator instance uses
    separate user-data memory and a different console port. This lets you manage each instance in isolation.
    However, if you will run multiple emulator instances, note that there are limitations on the capability of each
    instance to maintain its persistent user data — user settings and installed applications — across sessions.
    Specifically:
    • By default, only the first-launched emulator instance can preserve user data across sessions.
      When a session closes, the emulator stores the user data to a file — by default, it stores the data
      in the file ~/.android/userdata.img (on Linux and Mac) or C:documents and Settings<user>Local SettingsApplication DataAndroiduserdata.img (on Windows) in your development computer.
    • Emulator instances that you start after the first instance (that are running concurrently) also store
      user data during a session, but they do not preserve it for the next session, unless you have
      specified a file to which the data should be stored.
    To run multiple emulator instances and let each maintain user data across sessions, start the instances
    with the -data option (see Startup Options) and supply the path to a user-data file.

    Installing Applications on the Emulator

    To install applications on the emulator, you use the adb utility.
    Note that the emulator preserves user settings and installed applications across restarts. By default, the
    emulator saves the user data in a file on your development computer. On Linux and Mac, the emulator
    stores the data in ~/.android/userdata.img. On Windows, the emulator stores the data in C:documents and Settings<user>Local SettingsApplication DataAndroiduserdata.img.. The emulator uses the contents
    of the userdata.img file as the data/ folder.

    SD Card Emulation

    You can create a disk image and then load it to the emulator at startup, to simulate the presence of a
    user's SD card in the device. The sections below describe how to create the disk image, how to copy
    files to it, and how to load it in the emulator at startup.
    Note that you can only load disk image at emulator startup. Similarly, you can not remove a simulated
    SD card from a running emulator. However, you can browse, send files to, and copy/remove files from
    a simulated SD card either with adb or the emulator.
    The emulator supports emulated SDHC cards, so you can create an SD card image of any size up to
    128 gigabytes.

    Creating a Disk Image

    You can use the mksdcard tool, included in the SDK, to create a FAT32 disk image that you can load
    in the emulator at startup. You can access mksdcard in the tools/ directory of the SDK and create a disk
    image like this:
    mksdcard <size> <file>
    For more information, see Other Tools.

    Copying Files to a Disk Image

    Once you have created the disk image, you can copy files to it prior to loading it in the emulator. To copy
    files, you can mount the image as a loop device and then copy the files to it, or you can use the mtools
    utility mcopy to copy the files directly to the image. The mtools package is available for Linux, Mac, and
    Windows.

    Loading the Disk Image at Emulator Startup

    To load FAT32 disk image in the emulator, start the emulator with the -sdcard flag and specify the name
    and path of your image (relative to the current working directory):
    emulator -sdcard <filepath>

    Troubleshooting Emulator Problems

    The adb utility sees the emulator as an actual physical device. For this reason, you might have to use
    the -d flag with some common adb commands, such as install. The -d flag lets you specify which
    of several connected devices to use as the target of a command. If you don't specify -d, the emulator
    will target the first device in its list. For more information about adb, see Android Debug Bridge.
     
    For emulators running on Mac OS X, if you see an error "Warning: No DNS servers found" when starting
    the emulator, check to see whether you have an /etc/resolv.conf file. If not, please run the following line
    in a command window:
    ln -s /private/var/run/resolv.conf /etc/resolv.conf
    See Frequently Asked Questions for more troubleshooting information.

    Emulator Limitations

    In this release, the limitations of the emulator include:
    • No support for placing or receiving actual phone calls. You can simulate phone calls
      (placed and received) through the emulator console, however.
    • No support for USB connections
    • No support for camera/video capture (input).
    • No support for audio input (capture). Output (playback) is supported.
    • No support for device-attached headphones
    • No support for determining connected state
    • No support for determining battery charge level and AC charging state
    • No support for determining SD card insert/eject
    • No support for Bluetooth
    이름아이콘 태꿍
    2009-02-22 12:43
    잘 보았습니다.
       
     
    덧글 쓰기 0
    3500
    ※ 회원등급 레벨 0 이상 읽기가 가능한 게시판입니다.