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.
Steps
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.
Figure 1 – AVD Manager
Figure 2 – Device with dpad and 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.
References
For more on this topic, read the following:
- http://www.androidjavadoc.com/2.3/android/content/res/Configuration.html
Javadoc page for the Configuration class - http://developer.android.com/guide/developing/devices/managing-avds.html
This article explains how to use the AVD Manager. It includes a section on Hardware Options. - http://developer.android.com/guide/developing/devices/index.html
Overview article about the AVD manager. - http://developer.android.com/guide/developing/devices/managing-avds-cmdline.html
You can also use the AVD Manager from the command line.




Recent Comments