How To Check For Various Types Of Android Devices

This note explains how to get started with testing your Android app’s handling of the various types of hardware on Android phones and devices, like a touch screen, a directional pad (dpad), camera, etc.

Chances are good that you only have one, maybe two phones. What do you do to check that your app works on all the various types of phones and devices? Use the Android emulator, which allows you to set up different device configurations for testing.


First use the Android AVD Manager to set up a variety of devices with different hardware configurations. If you are not familiar with the AVD Manager, read the overview page and the hardware options section.

For my current Android work, my AVD Manager looks like the following. Figure 1 shows a list of six devices. Figure 2 shows one that has a dpad (directional pad) but no touch screen. Figure 3 is for a device without touch and without a dpad.

AVD Manager shows different examples

Figure 1 – AVD Manager

Figure 2 – Device with dpad and no touch

Device with no dpad, no touch

Figure 3 – Device with no dpad and no touch

Once you have your devices ready, it’s time to work on your code. Somewhere in your Activity class, probably in your onCreate method, you’ll need lines like the ones below. To understand this, you should read the javadoc for the Configuration class.

    Resources r = getResources ();
    Configuration config = r.getConfiguration ();
    int navHidden = config.navigationHidden;
    int configValue = navHidden;
    boolean hasTouch = (config.touchscreen == Configuration.TOUCHSCREEN_FINGER)
                       || (config.touchscreen == Configuration.TOUCHSCREEN_STYLUS);
    setHasTouchScreen (hasTouch);
    if (!hasTouch) toast ("To make a move, use keyboard or direction pad (dpad)"
                          +" to select a square. Then click Enter.", true);
    else toast ("To make a move, touch a square. "
                + "Then touch the Make Move button.", true);

I put this in my Activity’s onCreate method. That allows me to know what kind of device I have before I choose the layout and views for the activity.

For this code, which is for a simple game, I use toast to explain how to make a move.

My toast method:

public void toast (String msg, boolean longLength) {
    Toast.makeText (getApplicationContext(), msg,
                    (longLength ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT)).show ();

For a real application, you would want to do better than this, perhaps by providing a screen that explains how to use your app. The good thing is that you can customize the instructions for the specific device the user has.


For more on this topic, read the following:


About Bill Lahti

Bill Lahti is a software engineer building mobile applications and knowledge management solutions. Two of his interests are writing for this blog and building Android apps, with strategy games being an area of particular interest.
This entry was posted in Android and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s