the configuration class is used to describe the information on a mobile device. Sometimes our app needs to get the phone's system information and adjust our app based on the phone's information , so we need to use the Configuration class.
(1) get the Configuration Object
Call the Activity 's method to get the system's Configuration object:
Configuration config = getresources (). GetConfiguration ();
(2) Obtaining device System Information
Once the configuration object is acquired, the device system information can be obtained by directly accessing The common objects of the configuration.
This object allows us to obtain the following configuration information for the system:
public int densitydpi: is A variable parameter of the Android system that provides uniform units (DP) for different screen sizes and resolutions.
Public float Fontscale: The scaling factor for the font.
public int keyboard: The keyboard type associated with the device. The return values are:keyboard_12key,keyboard_nokeys,keyboard_qwerty , and so on.
public int Keyboardhidden: Indicates whether the keyboard is available.
Hardkeyboardhidden_no indicates that the hard keyboard is unavailable, but the soft keyboard is available
Hardkeyboardhidden_yes means the soft and hard keyboard is not available
Public locale locale: Gets the region where the user is currently located.
public int MCC: Gets the country code for the mobile signal.
public int MNC: Gets the network code for the mobile message.
public int navigation: type of Device direction navigation device.
The return value is:
Navigation_dpad:DPAD navigation
Navigation_nonav: No navigation
Navigation_trackball: Trackball navigation
navigation_undefined: Unknown
Navigation_wheel: Wheel navigation
public int Orientation: Gets the orientation of the system screen.
Orientation_landscape: Horizontal screen
Orientation_portrait: Vertical screen
public int touchscreen: Gets the touch mode of the touch screen.
Touchscreen_finger: Touch screen to accept finger
Touchscreen_notouch: No touch screen
Touchscreen_stylus: Touch-pen touch screen
touchscreen_undefined: Unknown
(3) Changes in response to device system information
In order to listen to changes in the system information, we need to rewrite the Activity 's onconfigurationchanged (Configuration newconfig) method, This is a callback-based approach to event handling.
Android Learning Note (37): Use the configuration class to get and listen to device information