emulation – Emulating density of 320 dpi on android emulator-ThrowExceptions

Exception or error:

We’re trying to emulate devices with the new density of 320 dpi in Android 2.3 –
such as Archos 101,
and we can’t seem to be able to define an emulator with such density,
even after downloading the latest 2.3 sdk.

I would really appreciate some ideas on this one 🙂

Many thanks!

How to solve:

That is quite simple.

Modify the attribute hw.lcd.density=320 at avd config file:
/Users/yourUserName/.android/avd/CustomDevice_API_19.avd/config.ini, and reboot your virtual device. I’m already test it, and it works to me!

Warnning:
Make sure you set the correct density, otherwise you will receive an error: qemu: available lcd densities are: 120, 160, 213, 240, 280, 320, 360, 400, 420, 480, 560, 640

BTW my Android SDK Tools version is 25.2.5.

###

In the AVD manager if you choose a Built-in skin then the Abstracted LCD density is ignored and it will set the density as described here:

Emulator Skins (from http://developer.android.com/tools/revisions/platforms.html)

The downloadable platform includes the following emulator skins:

  • QVGA (240×320, low density, small screen)
  • WQVGA400 (240×400, low density, normal screen)
  • WQVGA432 (240×432, low density, normal screen)
  • HVGA (320×480, medium density, normal screen)
  • WVGA800 (480×800, high density, normal screen)
  • WVGA854 (480×854 high density, normal screen)
  • WXGA720 (1280×720, extra-high density, normal screen)
  • WSVGA (1024×600, medium density, large screen)
  • WXGA800-7in (1280×800, high density, large screen) new
  • WXGA800 (1280×800, medium density, xlarge screen)

If you wish to set your own Abstracted LCD density you’ll need to define your own resolution manually by clicking the Resolution radio button.

Here’s some code you can use to test this:

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int density = metrics.densityDpi;
    if (density == DisplayMetrics.DENSITY_HIGH) {
        Toast.makeText(this, "DENSITY_HIGH... Density is " + String.valueOf(density),  Toast.LENGTH_LONG).show();
    }
    else if (density == DisplayMetrics.DENSITY_MEDIUM) {
        Toast.makeText(this, "DENSITY_MEDIUM... Density is " + String.valueOf(density),  Toast.LENGTH_LONG).show();
    }
    else if (density == DisplayMetrics.DENSITY_LOW) {
        Toast.makeText(this, "DENSITY_LOW... Density is " + String.valueOf(density),  Toast.LENGTH_LONG).show();
    }
    else {
        Toast.makeText(this, "Density is neither HIGH, MEDIUM OR LOW.  Density is " + String.valueOf(density),  Toast.LENGTH_LONG).show();
    }

###

You can always define a custom density and resolution for your virtual devices.

If you are using Eclipse go to Window - Android SDK and AVD Manager, there hit the New button, enter a name and select the SDK version, hit the Resolution option down in the Skin section and set the resolution you need. In the Hardware section edit the default option ABstracted LCD Density to your desired value and hit the Create AVD button.

When you hit the Start button in the AVD Manager then you get a popup window where you can select Scale display to real size. There you have to set the devices real screen size and your monitors dpi. You can hit the question mark to the right of that input field and let the calculator calculate it for you based on your monitors size.

###

From what I understand Android categorises the screen size and density so I think it treats 240dpi the same as 320dpi, i.e. it’s high density. There is also a next option up which is extra high density. I found this information in the Android developer reference see http://developer.android.com/guide/topics/fundamentals.html and the section towards the bottom called Declaring application requirements. I may be totally wrong but thought it worth a shout.

Leave a Reply

Your email address will not be published. Required fields are marked *