how to test a local web application in droid simulator

In August, I blogged about how to use the blackberry simulator because information was so scarce.  I’m happy to say the Android emulator documentation is much better.

My goal

About a month ago, beta testers of  JavaRanch’s JForum implementation told me the iPhone and the Droid had a large blank column on the right side of the screen.  Hence needing an emulator to try to fix it.  (This all happened weeks ago – just didn’t get around to blogging about it.)

Note: I didn’t install the Android Eclipse plugin because I’m not doing BlackBerry development.  If you want the plugin, you can install the toolkit.

Steps to download the simulator

  1. Download the SDK for your platform from the Android download site.
  2. Run “SDK Setup” executable from the download
  3. Choose the required available packages for download.  (I wasn’t sure what I needed so I had downloaded all of them.  You definitely need Android 2.0.) .  This step took a long time to install since it downloaded at 55KB/sec – dialup speeds.  I let it run overnight to completion.  It probably took a few hours.

Steps to initially configure the simulator

  1. See what targets are available
    android-sdk-windows\tools>android list targets
    “Android 2.0” version 5 should be a choice. This is the Droid.  The target looks like:
  2. id: 1 or “android-5”
    Name: Android 2.0
    Type: Platform
    API level: 5
    Revision: 1
    Skins: HVGA (default), QVGA, WQVGA400, WQVGA432, WVGA800, WVGA854
    etc

  3. Create the AVD (Android Virtual Device)
    android-sdk-windows\tools>android create avd -n Droid -t 1

Launching and running

  1. Launch your local Tomcat (or other app server)
  2. Launch the emulator
    android-sdk-windows\tools>emulator -avd Droid
  3. wait a while – it says “Android…” then “ANDROID” in shiny letters
  4. Ignore error message that says “sorry application messaging is not responding”
  5. Test away.  Note that you must use your computer name rather than localhost.  (On windows this is the %COMPUTERNAME% property.)  Thanks to ASP forum for this tip.

Actually using the simulator

Some impressions of using the simulator:

  • It’s great and intuitive.
  • That’s it!  If you read my BlackBerry post, there were a pile of things to get used to.  The Droid just worked.

The goal

The trick is that the Droid and iPhone need to be told the width of the page or they assume it is larger.  It’s an odd effect, but easy to solve by adding the following tag to the header.

<meta name="viewport" content="width = 320" />