Android Learning Note (37): Use the configuration class to get and listen to device information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.