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 be
2、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 Level i
3、s 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 classe
4、s 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 the
5、 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 functional
6、ity. 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 robustness
7、 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, althou
8、gh 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 Vers
9、ionAPI 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 developers:
10、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 not
11、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 Level t
12、hat 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 case
13、s, 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 rea
14、d 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 corresp
15、onding 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 com
16、pares 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 appli
17、cation 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 the sy
18、stem 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 the
19、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 of
20、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 Level
21、 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 provide
22、 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 applic
23、ation 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 applicat
24、ion 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 the
25、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 your ap
26、plication 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 incl
27、udes 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 ver
28、sion 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, as
29、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 dev
30、ice 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 amoun
31、t 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 app
32、lication 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
33、. Make sure to declare aandroid:minSdkVersionattribute in the applications manifest and set its value to the API Level of the platform version.Declaring a minimum API LevelIf you build an application that uses APIs or system features introduced in the latest platform version, you should set theandro
34、id:minSdkVersionattribute to the API Level of the latest platform version. This ensures that users will only be able to install your application if their devices are running a compatible version of the Android platform. In turn, this ensures that your application can function properly on their devic
35、es.If your application uses APIs introduced in the latest platform version but doesnotdeclare aandroid:minSdkVersionattribute, then it will run properly on devices running the latest version of the platform, butnoton devices running earlier versions of the platform. In the latter case, the applicati
36、on will crash at runtime when it tries to use APIs that dont exist on the earlier versions.Testing against higher API LevelsAfter compiling your application, you should make sure to test it on the platform specified in the applicationsandroid:minSdkVersionattribute. To do so, create an AVD that uses
37、 the platform version required by your application. Additionally, to ensure forward-compatibility, you should run and test the application on all platforms that use a higher API Level than that used by your application.The Android SDK includes multiple platform versions that you can use, including t
38、he latest version, and provides an updater tool that you can use to download other platform versions as necessary.To access the updater, use theandroidcommand-line tool, located in the /tools directory. You can launch the Updater by using theandroidcommand without specifying any options. You can als
39、o simply double-click the android.bat (Windows) or android (OS X/Linux) file. In ADT, you can also access the updater by selecting WindowAndroid SDK and AVD Manager.To run your application against different platform versions in the emulator, create an AVD for each platform version that you want to t
40、est. For more information about AVDs, seeCreating and Managing Virtual Devices. If you are using a physical device for testing, ensure that you know the API Level of the Android platform it runs. See the table at the top of this document for a list of platform versions and their API Levels.Using a P
41、rovisional API LevelIn some cases, an Early Look Android SDK platform may be available. To let you begin developing on the platform although the APIs may not be final, the platforms API Level integer will not be specified. You must instead use the platformsprovisional API Levelin your application ma
42、nifest, in order to build applications against the platform. A provisional API Level is not an integer, but a string matching the codename of the unreleased platform version. The provisional API Level will be specified in the release notes for the Early Look SDK release notes and is case-sensitive.T
43、he use of a provisional API Level is designed to protect developers and device users from inadvertently publishing or installing applications based on the Early Look framework API, which may not run properly on actual devices running the final system image.The provisional API Level will only be vali
44、d while using the Early Look SDK and can only be used to run applications in the emulator. An application using the provisional API Level can never be installed on an Android device. At the final release of the platform, you must replace any instances of the provisional API Level in your application
45、 manifest with the final platforms actual API Level integer.Filtering the Reference Documentation by API LevelReference documentation pages on the Android Developers site offer a Filter by API Level control in the top-right area of each page. You can use the control to show documentation only for pa
46、rts of the API that are actually accessible to your application, based on the API Level that it specifies in theandroid:minSdkVersionattribute of its manifest file.To use filtering, select the checkbox to enable filtering, just below the page search box. Then set the Filter by API Level control to t
47、he same API Level as specified by your application. Notice that APIs introduced in a later API Level are then grayed out and their content is masked, since they would not be accessible to your application.Filtering by API Level in the documentation does not provide a view of what is new or introduce
48、d in each API Level it simply provides a way to view the entire API associated with a given API Level, while excluding API elements introduced in later API Levels.If you decide that you dont want to filter the API documentation, just disable the feature using the checkbox. By default, API Level filtering is disabled, so that you can view the full framework API, regardless of API Level.Also note that the reference documentation for individual AP
版权声明:以上文章中所选用的图片及文字来源于网络以及用户投稿,由于未联系到知识产权人或未发现有关知识产权的登记,如有知识产权人并不愿意我们使用,如有侵权请立即联系:2622162128@qq.com ,我们立即下架或删除。
Copyright© 2022-2024 www.wodocx.com ,All Rights Reserved |陕ICP备19002583号-1
陕公网安备 61072602000132号 违法和不良信息举报:0916-4228922