Android API guide Translation (official) device compatibility compatibility 1.2

Source: Internet
Author: User

Please correct me if you can't translate the wrong place. Regularly update an article every two days, welcome attention.
1.2Device compatibility
1.2 Device compatibility

Android is designed to run on many different types of devices, from phones to tablets and televisions. As a developer, the range of devices provides a huge potential audience for your app. In order for your apps to be successful on all these devices, it should tolerate some feature variability and provide a fle Xible user interface that adapts to different screen configurations.
Android is designed to work on a variety of devices, including mobile phones, tablets, and televisions. For a developer, such a wide range of devices gives you a huge potential for the user community of the applications you develop. To be able to run successfully on all devices, your application should be able to tolerate some hardware differences and provide a flexible user interface to accommodate various screen parameters.
To facilitate your effort toward this goal, Android provides a dynamic app framework in which you can provide configuratio N-specific app resources in the static files (such as different XML layouts for different screen sizes). Android then loads the appropriate resources based in the current device configuration. So with some forethought to your app design and some additional app resources, you can publish a single application Packag E (APK) that provides an optimized user experience on a variety of devices.
To help you get compatibility, Android provides a dynamic application framework that you can use to give configurable application resources (such as different XML layout files that correspond to various screen sizes) in a static file. Android will load the appropriate resources based on the configuration of the current device. Therefore, by pre-design and some application resources, you can publish only one application package (APK) to provide the best user experience for a variety of devices.
If necessary, however, you can specify your app ' s feature requirements and control which types of devices can install your App from Google Play Store. This page explains how can control which devices has access to your apps, and how to prepare your apps to make sure T Hey reach the right audience. For more information about what you can do your app adapt to different devices, read supporting different devices.
However, if necessary, you can also set the device requirements for your application and limit the types of devices installed through the Google Play Store. This article explains how you can restrict the devices that are accessible to your application and how to prepare to ensure that your application is installed on the right device.


What Does "Compatibility" Mean?
Meaning of "compatibility"
________________________________________
As you read more on Android development, you'll probably encounter the term "compatibility" in various situations. There is types of Compatibility:device compatibility and app compatibility.
With an in-depth understanding of Android development, you may encounter the term "compatibility" in many cases. Compatibility is divided into two types: device compatibility and application compatibility.


Because Android is an open source project, any hardware manufacturer can build a device that runs the Android operating sy Stem. Yet, a device is "Android compatible" only if it can correctly run apps written for the Android execution environment. The exact details of the Android execution environment is defined by the Android compatibility program and each device mu St Pass the Compatibility Test Suite (CTS) in order to be considered compatible.
Because Android is an open-source operating system, any hardware manufacturer can use Android production devices. However, only programs that work correctly for Android executable environments are "Android compatible" devices. The exact definition of the Android executable environment is given in the Android compatibility program and all devices must pass the test of the Compatibility Test pack (CTS).



As an app developer, you don ' t need to worry about whether a device is Android compatible, because only devices that's a Ndroid compatible include Google Play Store. So you can rest assured this users who install the your app from Google Play Store is using an Android compatible device.
As a developer, you don't have to worry about whether your device is Android compatible, because only Android-compatible devices will use the Google Play Store. So you can rest assured that users who install apps from the Google Play Store are using Android-compatible devices.
However, need to consider whether your app are compatible with each potential device configuration. Because Android runs on a wide range of device configurations, some features is not available on all devices. For example, some devices is not include a compass sensor. If your app ' s core functionality requires the use of a compass sensor and then your app is compatible only with devices that Include a compass sensor.
However, you still need to consider application compatibility on all possible device configurations. Because there are many devices that may run Android, some features are not available to all devices. For example, some devices may not contain a compass (sensor). If the core function requires a compass, then the application can only be applied to devices with a compass.


Controlling Your App ' s availability to Devices
Control device compatibility for Applications
________________________________________
Android supports a variety of features your app can leverage through platform APIs. Some Features is hardware-based (such as a compass sensor), Some is software-based (such as app widgets), and Some are D Ependent on the platform version. Not every device supports every feature, so could need to control your app's availability to devices based on your app ' s Required features.
Android offers a wealth of features that your application can use with platform APIs to get the most out of them. Some features are hardware-based (such as compass sensors), some are software-based (such as widgets), and others depend on the platform version. Because not all devices support all features, you may want to control the application's scope for the device based on functional requirements.


To achieve the largest user-base possible for your apps, you should strive to support as many device configurations as poss Ible using a single APK. In the most situations, you can do so by disabling optional features at runtime and providing apps resources with alternatives For different configurations (such as different layouts for different screen sizes). If necessary, however, you can restrict your app's availability to devices through Google Play Store based on the Followin G Device Characteristics:
? Device Features
? Platform version
? Screen configuration
To get the app to win as many user groups as possible, you're trying to get your apk to support the widest possible range of devices. You can do this in most cases by disabling certain optional features at run time, or by providing alternative resources depending on the configuration (for example, different Layout for various screen sizes). If necessary, you can limit the scope of your application from the Google Play Store in the following ways:
? Device configuration
? System version
? Screen parameters
?
Device Features
Device configuration
In order for manage your app's availability based on device features, Android defines feature IDs for any hardware or software feature that May is available on all devices. For instance, the feature ID for the compass sensor was feature_sensor_compass and the feature ID for app widgets is Featur E_app_widgets.
To be able to control the application scope according to different device configurations, Android defines a feature ID for each hardware or software feature that is not supported by all devices. For example, the feature ID of the compass sensor is feature_sensor_compass, and the Widget's attribute ID is feature_app_widgets.


If necessary, you can prevent the users from installing your apps when their devices don ' t provide a given feature by declaring It has a <uses-feature> element in your app ' s manifest file.
If necessary, you can prevent users from installing applications on devices that do not provide a given feature by declaring them in the < Uses-feature > element of the Manifest file.
For example, if your app does do sense on a device that lacks a compass sensor, you can declare the compass sensor a s required with the following manifest tag:
For example, if your application is not available on a device that lacks a compass sensor, you can declare the compass sensor as required using the following manifest tag:


<manifest ... >
<uses-feature android:name= "Android.hardware.sensor.compass"
Android:required= "true"/>
...
</manifest>
Google Play Store compares the features your app requires to the features available on each user's device to determine whe Ther your app is compatible with each device. If the device does not provide all the features your app requires, the user cannot install your app.
The Google Play Store will compare the requirements of the application with the configuration of the user's device to determine the compatibility of the application. If the device does not meet all of the requirements, users will not be able to install your application.
However, if your app ' s primary functionality does not require a device feature, you should set the RequiredAttribute to "F Alse "and check for the device feature at runtime. If The app is feature-available on the current device, gracefully degrade the corresponding app feature. For example, you can query whether a feature are available by calling Hassystemfeature () like this:
However, if the primary function of the application is not to require a device, you should set the Required property to "false" and check the availability of the device configuration yourself at run time. If the current device does not provide the configuration required by the application, downgrade the relevant requirements smoothly. For example, you can query the available configurations by calling Hassystemfeature () as follows:


Packagemanager pm = Getpackagemanager ();
if (!pm.hassystemfeature (Packagemanager.feature_sensor_compass)) {
This device does not has a compass, turn off the compass feature
Disablecompassfeature ();
}
Note:some system permissions implicitly require the availability of a device feature. For example, if your app requests permission to access to BLUETOOTH, this implicitly requires the Feature_bluetooth device Feature. You can disable filtering based on this feature and make your apps available to devices without Bluetooth by setting the RE quired attribute to ' false ' in the <uses-feature> tag. For more information on implicitly required device features, read Permissions that imply Feature Requirements.
Note: Some system permissions implicitly require a device's hardware. For example, if an application requests access to Bluetooth, the device requirements for feature_bluetooth are implied. By setting the Required property in the < Uses-feature > tag to "false", you can turn off the filter associated with it so that the application can be used on devices that do not have Bluetooth.


Platform Version Platform versions
Different devices may run Different versions of the Android platform, such as Android 4.0 or Android 4.4. Each successive platform version often adds new APIs isn't available in the previous version. to indicate which set of APIs is available, each platform version specifies a API level. For instance, Android 1.0 are API Level 1 and Android 4.4 are API level 19.
Different devices may run different versions of the Android operating system, such as Android 4.0 or Android 4.4. Higher versions tend to add some APIs to the lower version of the system. To facilitate the identification of the currently available set of APIs, each platform version is defined as an API level. For example, Android 1.0 is API level 1,android 4.4 is API level 19.
The API level allows-declare the minimum version with which your app is compatible, using the <uses-sdk> mani Fest tag and its minsdkversion attribute.
For example, the Calendar Provider APIs were added with Android 4.0 (API level 14). If your app cannot function without these APIs, you should declare API level as your app ' s minimum supported version Li Ke this:
With manifest tags < uses-sdk > and its minsdkversion properties, you can use the API level to declare the minimum system version that your application is compatible with.
For example, the Calendar Provider API was introduced from Android 4.0 (API level 14). If no such API application is available, you should declare the minimum supported version as API Level 14:


<manifest ... >
&LT;USES-SDK android:minsdkversion= "android:targetsdkversion="/>
...
</manifest>
The Minsdkversion attribute declares the minimum version with which your app is compatible and the Targetsdkversion Attri Bute declares the highest version on which you ' ve optimized your app.
The Minsdkversion property declares the minimum system version that the application is compatible with, and the Targetsdkversion attribute declares the highest system version that the application runs optimally.
Each successive version of Android provides compatibility for apps this were built using the APIs from previous platform V Ersions, so your app should all is compitible with a future versions of Android while using the documented Android APIs.
Newer versions of the Android system are compatible with applications compiled by the lower version of the API, so the application should be compatible with future versions of Android as long as the APIs are exposed.


Note:the targetsdkversion attribute does not prevent your apps from being installed on platform versions that is higher T Han the specified value, but it's important because it indicates to the system whether your app should inherit behavior C Hanges in newer versions. If you don't update the targetsdkversion to the latest version, the system assumes that your app requires some Backward-co Mpatibility behaviors when running on the latest version. For example, among the behavior changes on Android 4.4, alarms created with Thealarmmanager APIs is now inexact by Defaul T-the system can batch app alarms and preserve system power, but the system would retain the previous API behavior for y Our app if your target API level is lower than "19".


Note: The Targetsdkversion property does not prevent an application from being installed on a later version of the platform, but it is important for the system to know whether the application will apply a higher version of the feature change. If you do not change targetsdkversion to the latest version, if you are running on the latest version of the platform, the system assumes that some of the backward compatibility features are still required by the application. For example, in the feature changes of Android 4.4, the Alarm reminder time created using the Alarmmanager API is no longer accurate, so the system can process Alarm in batches to conserve power. However, if the target API level of the application is less than 19, then the previous API features will still be inherited by the system.


However, if your app uses APIs added in a to recent platform version, but does not require them for its primary function Ality, should check the API level at runtime and gracefully degrade the corresponding features when the API level is T OO Low. In this case, set the minsdkversion to the lowest value possible for your app's primary functionality, then compare the CU Rrent system's version, Sdk_int, to one of the codename constants in Build.version_codes this corresponds to the API level yo U want to check. For example:
However, if the application uses the latest version of the API, but the principal function does not need to be used, you should check the API level at runtime and reduce the need for system features smoothly when the API version is too low. In this case, set the minsdkversion to the minimum version required by the program principal feature, and compare the current system version Sdk_int with the code constants for the API level required by the program, which are given in build.version_codes. For example:


if (Build.VERSION.SDK_INT < build.version_codes. Honeycomb) {
Running on something older than API level one, so disable
The Drag/drop features that use Clipboardmanager APIs
Disabledraganddrop ();
}
Screen Configuration screens Parameters
Android runs on devices of various sizes, from phones to tablets and TVs. In order to categorize devices by their screen type, Android defines, and characteristics for each device:screen size (the Physical size of the screen) and screens density (the physical density of the pixels on the screen, known as DPI). To simplify the different configurations, Android generalizes these variants into groups that make them easier to target:
? Four generalized sizes:small, normal, large, and XLarge.
? and several generalized densities:mdpi (medium), hdpi (hdpi), xhdpi (Extra high), xxhdpi (Extra-extra High), and others.
Android can run on devices of all sizes, from phones and tablets to televisions. To categorize the screens for these devices, Android defines two types of parameters: Screen size (physical size) and screen density (which shows the physical density of the dots, called dpi). To simplify the description of the various configurations, Android generalizes These parameters to several, which is also easy to use:
? The dimensions are summarized in four types: small, normal, large and xlarge.
? The screen density is summarized as follows: MDPI (medium), hdpi (hdpi), xhdpi (superelevation), xxhdpi (ultra-high) and so on.
?
By default, your app. compatible with all screens sizes and densities, because the system makes the appropriate adjustmen TS to your UI layout and image resources as necessary for each screen. However, should optimize the user experience for each screen configuration by adding specialized layouts for different Screen sizes and optimized bitmap images for common screen densities.
By default, the application is compatible with all screen sizes and densities, because the UI layout and picture resources are adjusted as appropriate for the actual screen parameters. However, to provide the best user experience, you should add Layout for the various screen sizes according to the screen parameters, as well as bitmap resources optimized for common screen densities.





Controlling Your app ' s availability for business reasons control the commercial compatibility of applications
________________________________________
In addition to restricting your app's availability based on device characteristics, it's possible you could need to restrict Your app ' s availability for business or legal reasons. For instance, a app, displays train schedules for the London underground are unlikely to being useful to users outside th e-Kingdom. For this type of situation, Google Play Store provides filtering options in the developer console L Your app ' s availability for non-technical reasons such as the user's locale or wireless carrier.
Filtering for technical compatibility (such as required hardware) are always based on information contained with In your APK file. But filtering for non-technical reasons (such as geographic locale) are always handled in the Google Play developer Console .
In addition to considering the features of the device, it is possible for commercial or legal reasons to limit the application scope. For example, applications that display the London Metro timetable are not very useful for users outside the UK. In this case, Google Play Store provides developers with the appropriate filters to control the scope of application for non-technical reasons, which can be either a user location or a wireless carrier.
Technical compatibility filtering (such as hardware requirements) is based on your APK file. But the filtering of non-technical factors (such as geographical location) is controlled by the developer interface of Google Play.

Android API guide Translation (official) device compatibility compatibility 1.2

Related Article

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.