Some possible examples:
- We might want to add some arrow keys to our screen if the used doesn't have a way to navigate.
- We need to know user's locale.
- We are doing a game and we want to provide some in screen controls if the user doesn't have a keyboard.
For this kind of needs Android provides a class called Configuration.
Let's say we want to detect which kind of navigation the user has in his device.
We will get the device's value doing:
getResources().getConfiguration().navigationand then we need to compare it against the different constants in the Configuration class.
public static final int NAVIGATION_UNDEFINED = 0;
public static final int NAVIGATION_NONAV = 1;
public static final int NAVIGATION_DPAD = 2;
public static final int NAVIGATION_TRACKBALL = 3;
public static final int NAVIGATION_WHEEL = 4;
Some examples in different devices:
Motorola Droid: navigation=2 (NAVIGATION_DPAD)
Nexus One: navigation=3 (NAVIGATION_TRACKBALL)
Galaxy S: navigation=1 (NAVIGATION_NONAV)