安卓 英文 外文文献翻译 Android API级别_第1页
安卓 英文 外文文献翻译 Android API级别_第2页
安卓 英文 外文文献翻译 Android API级别_第3页
安卓 英文 外文文献翻译 Android API级别_第4页
安卓 英文 外文文献翻译 Android API级别_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、android api级别当你开发你的android应用程序时,了解该平台api变更管理的基本方法和概念是很有帮助的。同样的,知道api级别标识以及该标识如何保障你的应用与实际硬件设备相兼容对于开发及后续的发布、维护都是有益的。本节内容告诉你api级别的知识,以及它如何影响你开发和使用的应用。关于如何使用“以api级别进行过滤”来使用api参考手册,从本文末尾的文档过滤(filtering the documentation)中可以得到更多信息。api级别是什么?api级别是一个整数值,它唯一标识了一个具体版本的android平台,及其框架的api的版本。android平台提供了一套框架api

2、,使得应用程序可以与系统底层进行交互。该框架api由以下模块组成: 一组核心的包和类 清单(manifest)文件的xml元素和属性声明 资源文件的xml元素和属性声明及访问形式 各类意图(intents) 应用程序可以请求的各类授权,以及系统中包含的授权执行每个android平台的后续版本会包括它提供的更新的android应用程序框架的api。该框架的api的更新设计,使高版本的api与早期版本兼容。也就是说,在新版本api中大多数都是新增功能,和引进新的或替代的功能。作为api的部分升级,老的替换的部分已过时,但不会从新版本中删除,使得已有的应用程序仍然可以使用它们。在极少数情况下,旧版本

3、api的部分可能被修改或删除,通常这种变化是为了保障api的稳定性及应用程序或系统的安全。所有其他早期版本的api将不做修改的保留。一个android平台提供的框架api,被指定一个整数标识符,称为“api级别”。每一个版本的android平台只支持有一个api级别,虽然该支持是隐含地包括了所有早期的api级别(一直到api级别1级)。android平台的最初版本提供的框架api级别是1级,随后的版本依次递增。下表说明了具体平台版本和支持的api级别的对应关系。平台版本api级别android 3.011android 2.3.310android 2.39android 2.28androi

4、d 2.17android 2.0.16android 2.05android 1.64android 1.53android 1.12android 1.01在android中使用api级别api级别标识为保证用户和应用程序开发者的最佳体验,起了关键作用: 它让android平台可以描述它支持的框架api的最高版本 它让应用程序可以描述它需要的框架api版本 它使得系统可以在硬件设备上安装应用程序时能够检查版本是否匹配,使得版本不兼容的应用程序不会被错误安装在设备之上.每个版本的android平台都在其内部存储了自己的api级别标识。应用程序可以用框架api提供的清单文件元素来描述该应用程序

5、可以运行的最小和最大api级别,以及应用程序开发者设计期望运行的平台版本。三种属性分别描述如下: android:minsdkversion指明该应用程序可以运行的api最低版本。默认是“1”。 android:targetsdkversion指明该应用程序设计时期望运行的目标api版本。在某些情况下,这允许应用程序使用目标api级别下定义的清单元素或行为,而不是只限于使用最低api级别定义的内容。 android:maxsdkversion指明该应用程序可以运行的最高api级别。重要声明:使用该属性之前请阅读文档。比如,要指明一个应用程序能够运行的最低api级别,应当在该应用程序的清单文件的

6、元素中加入android:minsdkversion属性。android:minsdkversion的值是一个正整数,对应的是该应用程序能够运行的最低平台的api级别标识。用户尝试安装一个应用程序,或者在系统升级后重验证应用程序的时候,android系统首先会检查应用程序的清单文件中的属性,将其与系统内部api级别对比。系统只有在满足下列情况时才允许进行应用程序安装: 如果声明了android:minsdkversion属性,其属性值必须小于或等于该系统的api级别对应的整数值。如果未声明,系统会默认该应用程序运行需要的最低api级别是1。 如果声明了android:maxsdkversion

7、属性,其属性值必须等于或大于该系统的api级对应的整数值。如果未声明,系统会默认该应用程序没有最高api级别限制。请通过阅读文档以获得系统如何处理该属性的更多信息。应用程序清单文件中声明该属性后,元素看起来应类似于下面的例子: .这样做的主要原因是,应用程序会通过android:minisdkversion声明的api级别来告知系统该应用程序使用的api是指定引入的api级别。假如没有这种属性声明,一个应用程序如果因为某些不知名的原因被安装在低级别api系统之上,那么该应用程序会在运行时因为尝试访问不存在的api而崩溃。为此,android系统通过不允许应用程序被安装在不满足其最低api级别要

8、求的目标硬件上来防止此类结果发生。例如,android.appwidget类包是在api级别3中开始引入的。如果一个应用程序使用了这个api,就必须通过指明android:minsdkversion属性为3来声明运行的最低要求。于是,该应用程序就可以在android 1.5(api级别3级)、android 1.6 (api级别4级)等平台上安装,但是在android 1.1 (api级别2级)和android 1.0平台(api级别1级)上却是无法安装的。欲知关于如何声明应用程序api级别需求的更多信息,请阅读文档中关于清单文件的章节。开发者需要考虑的内容本节属于应用程序开发者需要了解的内容

9、。应用程序的向前兼容性android应用程序一般向前兼容于android平台的新版本。这是因为几乎所有的框架api变更都是添加性质的,一个以某种版本的api开发的应用程序是向前兼容与后续android系统及高版本api。应用程序应当可以运行于高版本的平台,除非使用了未来因某种原因移除的api。向前兼容性的特性如此重要,是因为很多的android驱动的设备能够使用ota远程下载技术进行系统更新。用户开始时能够很好的安装和使用你开发的应用程序,后来进行了ota升级到新版本的android平台。一旦升级完毕,你的应用程序将运行在一个新的版本环境下,而这个环境应当包含了你的应用程序所需的api和系统功

10、能。某些情况下,api背后的变化,例如系统底层的变化,可能会影响到你的应用程序运行在新的环境下。为此,作为应用程序开发人员,应当了解应用程序在不同系统环境下将会有如何的外观和行为。android sdk包含了多个平台版本,开发人员可以下载下来,用于测试自己的应用程序在不同版本下的运行情况。每个版本的平台都提供了兼容的系统镜像,你可以将应用程序运行在对应的android虚拟设备(模拟器)上进行测试。应用程序的向后兼容性android应用程序不一定向后兼容于那些比这些应用程序开发环境低的平台环境。android平台的每个新版本包含了新的框架api,例如新的平台功能,或者替代部分已有的api。应用程

11、序在新平台上可以访问这些新的api,就像之前提到的,在后续更新的版本中,这些新功能api也是可以继续使用。相反的,因为早期版本的平台不会包含新的api功能,使用了新api的应用程序在那些旧平台上是无法运行的。虽然一个android平台设备不太可能降级到以前的版本,但是需要了解的是:实际生活中可能会有很多设备运行的是较旧的平台版本。即使在设备接收到ota远程下载升级,有些人仍然可能会滞后甚至可能不会收到更新。平台版本和api级别的选择当你开发应用程序时,你需要选择一个平台用于编译该应用程序。通常,你应该在你的应用程序可以支持的最低版本的平台上进行编译。你可以通过寻找最低的可以支持你的应用程序编译

12、的平台方式来决定你将会支持的最低平台版本。一旦你确定了支持的最低版本后,你就可以创建对应版本的avd模拟器来全面测试你的应用程序。你需要注意的是不要忘记在应用程序清单文件中申明android:minsdkversion属性,并赋上正确的api级别标识。声明最低api级别如果你开发的应用程序使用了最新平台上引入的api或平台特性,你就需要将android:minsdkversion属性赋最新平台的api级别标识。这将保证用户只能在他们的设备与你的应用程序平台版本兼容情况下安装。反过来说,这样能够保证你的应用程序在他们的设备上表现正常。如果你用了最新的api或平台特性,但是没有申明android:

13、minsdkversion属性,那么你的应用程序在最新平台上运行是没有稳定,但是在早期版本的平台上是会出错的。在后一种情况,应用程序在尝试访问旧平台上不存在的api时会崩溃。针对高版本的api级别测试编译完你的应用程序,你应当在支持的最低版本平台上详细测试应用程序的表现。可以通过创建对应平台的avd模拟器进行测试。此外,要保证向前兼容性,你应当在你的应用程序可能运行的更高平台版本上进行运行和测试。android sdk包含了多个平台版本供开发者使用,其中包括了最新的版本,并且提供了升级工具使得开发者可以获取其他的版本。要使用升级工具,可以通过android命令行方式,该工具位于/tools路径

14、下。你可以用敲入android指令运行该升级工具,而不用指定任何参数。你也可以简单地通过双击windows下的android.bat或os x/linux下的android文件来启动升级工具。在adt工具界面,你可以通过菜单的windowandroid sdk and avd manager来访问升级工具。要想将你的应用程序在不同平台版本的模拟器上运行,需要创建对应的avd设备。关于avd的更多信息,请参见creating and managing virtual devices。如果你用物理设备进行测试,确保清楚运行的具体平台版本。通过本文开始部分的映射表格可以知道平台版本对应的api级别标

15、识。使用临时的api级别某些情况下,有可能会发布“早期预览(early look)”版的android平台sdk。在此平台版本上开发使用的api将不会是最终发布版,平台的api级别标识数字就不会指定。你必须在程序清单文件中使用临时的api级别进行标识,以便建立对应的平台应用。临时api级别不是一个整数,而是一个表示未发布的平台版本的字符串代号。“早期预览”版本的api级别在发布说明中会申明,该代号是大小写敏感的。临时api级别标识的用途是保护开发者和设备使用者免于无意中发布或安装在“早期预览”平台版本上开发的应用程序,这些应用程序可能在最终的发布系统上运行不稳定。临时api级别标识仅仅在使用“

16、早期预览”版本的sdk下有效,并且只能运行应用程序于模拟器之中。实际的android设备上是无法安装使用临时api级别标识的应用程序的。在最终版本平台发布后,你必须将程序清单文件中用到的临时api级别标识替换成最终平台的实际api级别整数值。通过api级别进行文档内容过滤android开发者站点上的参考文档的每个页面的右上方提供了“filter by api level”控件。你可以用这个控件来仅仅显示你应用程序相关的那部分api文档,可以通过应用程序清单文件中的android:minsdkversion属性值进行过滤。要使用过滤功能,可以通过页面搜索框下面的选择框来启用过滤功能。比如设定“f

17、ilter by api level”控件内容与你应用程序申明的相同。注意:在选定级别之后引入的心api会以灰色显示,并且内容被隐藏,因为你的应用程序是无法访问这些新功能。api级别过滤方法不会提供每个api级别中新添加的功能视图,仅仅展现对应api级别的整个内容,其中去除了后续新版本中的内容。如果你不想过滤api文档了,只需要关闭该选择框的特性。api级别过滤默认是关闭的,因此你可以看到整个框架api的全貌,而不管具体的api级别。还要注意的是个别的api元素申明了该api参考文档在哪一级引入的。这通过在每个文档页面正文部分的右上角的“since ”进行声明该包和类的引入信息。类成员的api

18、级别在其详细描述文件头部的右边进行描述。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

19、 on which it may 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 a

20、pi level?api level 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

21、 packages and classes 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 succe

22、ssive version of 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 re

23、placement functionality. 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 e

24、nsure api robustness 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 o

25、ne api level, although 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 pl

26、atform.platform 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 appl

27、ication developers: 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 a

28、pplications are 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 p

29、referred api level 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

30、to run. in some 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.

31、important:please 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

32、 the integer corresponding 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 applicati

33、ons manifest and 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 as

34、sumes that the application 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 informat

35、ion about how the 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 leve

36、l specified. if 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

37、higher than that 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 an

38、droid 1.5 (api level 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 se

39、ctions below provide 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 additiv

40、e, an android application 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 case

41、s where the application 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

42、 new version of 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

43、, may affect your 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,

44、the android sdk 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 platfor

45、m older than the 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 n

46、ew platform and, 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

47、 android-powered 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

48、 a significant amount 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 pl

49、atform that your 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 t

50、est your application. 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

51、 should set theandroid: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 pro

52、perly on their devices.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

53、 case, the application 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, cre

54、ate an avd that uses 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

55、can use, including the 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

56、options. you can also 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 versio

57、n that you want to test. 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 provisional api levelin some cases, an early look android sdk platform may be available. to let you begin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论