1、文献翻译Android API LevelsAs you develop your application on Android, its useful to understand the platforms general approach to API change management. Its also important to understand the API Level identifier and the role it plays in ensuring your applications compatibility with devices on which it may
2、 be installed.The sections below provide information about API Level and how it affects your applications.For information about how to use the Filter by API Level control available in the API reference documentation, seeFiltering the documentationat the end of this document.What is API Level?API Lev
3、el is an integer value that uniquely identifies the framework API revision offered by a version of the Android platform.The Android platform provides a framework API that applications can use to interact with the underlying Android system. The framework API consists of: A core set of packages and cl
4、asses A set of XML elements and attributes for declaring a manifest file A set of XML elements and attributes for declaring and accessing resources A set of Intents A set of permissions that applications can request, as well as permission enforcements included in the systemEach successive version of
5、 the Android platform can include updates to the Android application framework API that it delivers.Updates to the framework API are designed so that the new API remains compatible with earlier versions of the API. That is, most changes in the API are additive and introduce new or replacement functi
6、onality. As parts of the API are upgraded, the older replaced parts are deprecated but are not removed, so that existing applications can still use them. In a very small number of cases, parts of the API may be modified or removed, although typically such changes are only needed to ensure API robust
7、ness and application or system security. All other API parts from earlier revisions are carried forward without modification.The framework API that an Android platform delivers is specified using an integer identifier called API Level. Each Android platform version supports exactly one API Level, al
8、though support is implicit for all earlier API Levels (down to API Level 1). The initial release of the Android platform provided API Level 1 and subsequent releases have incremented the API Level.The following table specifies the API Level supported by each version of the Android platform.Platform
9、VersionAPI LevelAndroid 3.011Android 2.3.310Android 2.39Android 2.28Android 2.17Android 2.0.16Android 2.05Android 1.64Android 1.53Android 1.12Android 1.01Uses of API Level in AndroidThe API Level identifier serves a key role in ensuring the best possible experience for users and application develope
10、rs: It lets the Android platform describe the maximum framework API revision that it supports It lets applications describe the framework API revision that they require It lets the system negotiate the installation of applications on the users device, such that version-incompatible applications are
11、not installed.Each Android platform version stores its API Level identifier internally, in the Android system itself.Applications can use a manifest element provided by the framework API to describe the minimum and maximum API Levels under which they are able to run, as well as the preferred API Lev
12、el that they are designed to support. The element offers three key attributes: android:minSdkVersion Specifies the minimum API Level on which the application is able to run. The default value is 1. android:targetSdkVersion Specifies the API Level on which the application is designed to run. In some
13、cases, this allows the application to use manifest elements or behaviors defined in the target API Level, rather than being restricted to using only those defined for the minimum API Level. android:maxSdkVersion Specifies the maximum API Level on which the application is able to run.Important:Please
14、 read thedocumentation before using this attribute.For example, to specify the minimum system API Level that an application requires in order to run, the application would include in its manifest aelement with aandroid:minSdkVersionattribute. The value ofandroid:minSdkVersionwould be the integer cor
15、responding to the API Level of the earliest version of the Android platform under which the application can run.When the user attempts to install an application, or when revalidating an appplication after a system update, the Android system first checks theattributes in the applications manifest and
16、 compares the values against its own internal API Level. The system allows the installation to begin only if these conditions are met: If aandroid:minSdkVersionattribute is declared, its value must be less than or equal to the systems API Level integer. If not declared, the system assumes that the a
17、pplication requires API Level 1. If aandroid:maxSdkVersionattribute is declared, its value must be equal to or greater than the systems API Level integer. If not declared, the system assumes that the application has no maximum API Level. Please read thedocumentation for more information about how th
18、e system handles this attribute.When declared in an applications manifest, aelement might look like this: .The principal reason that an application would declare an API Level inandroid:minSdkVersionis to tell the Android system that it is using APIs that wereintroducedin the API Level specified. If
19、the application were to be somehow installed on a platform with a lower API Level, then it would crash at run-time when it tried to access APIs that dont exist. The system prevents such an outcome by not allowing the application to be installed if the lowest API Level it requires is higher than that
20、 of the platform version on the target device.For example, theandroid.appwidgetpackage was introduced with API Level 3. If an application uses that API, it must declare aandroid:minSdkVersionattribute with a value of 3. The application will then be installable on platforms such as Android 1.5 (API L
21、evel 3) and Android 1.6 (API Level 4), but not on the Android 1.1 (API Level 2) and Android 1.0 platforms (API Level 1).For more information about how to specify an applications API Level requirements, see thesection of the manifest file documentation.Development ConsiderationsThe sections below pro
22、vide information related to API level that you should consider when developing your application.Application forward compatibilityAndroid applications are generally forward-compatible with new versions of the Android platform.Because almost all changes to the framework API are additive, an Android ap
23、plication developed using any given version of the API (as specified by its API Level) is forward-compatible with later versions of the Android platform and higher API levels. The application should be able to run on all later versions of the Android platform, except in isolated cases where the appl
24、ication uses a part of the API that is later removed for some reason.Forward compatibility is important because many Android-powered devices receive over-the-air (OTA) system updates. The user may install your application and use it successfully, then later receive an OTA update to a new version of
25、the Android platform. Once the update is installed, your application will run in a new run-time version of the environment, but one that has the API and system capabilities that your application depends on.In some cases, changesbelowthe API, such those in the underlying system itself, may affect you
26、r application when it is run in the new environment. For that reason its important for you, as the application developer, to understand how the application will look and behave in each system environment. To help you test your application on various versions of the Android platform, the Android SDK
27、includes multiple platforms that you can download. Each platform includes a compatible system image that you can run in an AVD, to test your application.Application backward compatibilityAndroid applications are not necessarily backward compatible with versions of the Android platform older than the
28、 version against which they were compiled.Each new version of the Android platform can include new framework APIs, such as those that give applications access to new platform capabilities or replace existing API parts. The new APIs are accessible to applications when running on the new platform and,
29、 as mentioned above, also when running on later versions of the platform, as specified by API Level. Conversely, because earlier versions of the platform do not include the new APIs, applications that use the new APIs are unable to run on those platforms.Although its unlikely that an Android-powered
30、 device would be downgraded to a previous version of the platform, its important to realize that there are likely to be many devices in the field that run earlier versions of the platform. Even among devices that receive OTA updates, some might lag and might not receive an update for a significant a
31、mount of time.Selecting a platform version and API LevelWhen you are developing your application, you will need to choose the platform version against which you will compile the application. In general, you should compile your application against the lowest possible version of the platform that your
32、 application can support.You can determine the lowest possible platform version by compiling the application against successively lower build targets. After you determine the lowest version, you should create an AVD using the corresponding platform version (and API Level) and fully test your application. Make sure to declare aa
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1