【通译】(69)uses-sdk元素
【翻译】(69)uses-sdk元素
see
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
原文见
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
-------------------------------
<uses-sdk>
uses-sdk元素
-------------------------------
* syntax:
* 语法:
-------------------------------
<uses-sdk android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
-------------------------------
* contained in:
* 被包含在:
<manifest>
* description:
* 描述:
Lets you express an application's compatibility with one or more versions of the Android platform, by means of an API Level integer. The API Level expressed by an application will be compared to the API Level of a given Android system, which may vary among different Android devices.
让你表达一个应用程序和Android平台的一个或多个版本的兼容性,通过一个API级别整数。应用程序表达的API级别将和一个给定的Android系统的API级别比较,而它可能在不同的Android设备之间有区别。
Despite its name, this element is used to specify the API Level, not the version number of the SDK (software development kit) or Android platform. The API Level is always a single integer. You cannot derive the API Level from its associated Android version number (for example, it is not the same as the major version or the sum of the major and minor versions).
虽然这个元素的名称,它被用于指定API级别,并不是SDK(软件开发工具箱)的版本号或Android平台。API级别总是一个单一的整数。你不可以从它关联的Android版本号中派生出API级别(例如,它不同于主版本号或主次版本号的和)。
For more information, read about Android API Levels and Versioning Your Applications.
想获得更多信息,请阅读关于Android API级别以及版本化你的应用程序。
-------------------------------
Android Market and <uses-sdk> attributes
Android市场和<uses-sdk>属性
Android Market filters the applications that are visible to users, so that users can only see and download applications that are compatible with their devices. One of the ways Market filters applications is by Android version-compatibility. To do this, Market checks the <uses-sdk> attributes in each application's manifest to establish its version-compatibility range, then shows or hides the application based on a comparison with the API Level of the user's Android system version. For more information, see Market Filters.
Android市场过滤对于用户可见的应用程序,使用户只可以看到和下载兼容它们设备的应用程序。市场过滤应用程序的其中一种方式是通过Android的版本兼容性。为了做到这点,市场检查每个应用程序的清单中的<uses-sdk>属性以建立它的版本兼容性范围,然后展示或隐藏应用程序,基于对用户的Android系统版本的API级别的比较。想获得更多信息,参见市场过滤器。
-------------------------------
* attributes:
* 属性:
* android:minSdkVersion
An integer designating the minimum API Level required for the application to run. The Android system will prevent the user from installing the application if the system's API Level is lower than the value specified in this attribute. You should always declare this attribute.
一个整数,它指示应用程序运行所必需的最小API级别。Android系统将阻止用户安装该应用程序,如果系统的API级别低于这个属性中指定的值。你应该总是声明此属性。
-------------------------------
Caution: If you do not declare this attribute, the system assumes a default value of "1", which indicates that your application is compatible with all versions of Android. If your application is not compatible with all versions (for instance, it uses APIs introduced in API Level 3) and you have not declared the proper minSdkVersion, then when installed on a system with an API Level less than 3, the application will crash during runtime when attempting to access the unavailable APIs. For this reason, be certain to declare the appropriate API Level in the minSdkVersion attribute.
警告:如果你不声明此属性,那么系统假设默认值为"1",它指示你的程序兼容所有Android版本。如果你的应用程序不兼容所有版本(例如,它使用API级别3中引入的API)并且你不曾声明合适的minSdkVersion,那么当安装在带有小于3的API级别的系统上时,应用程序将在运行时期间崩溃,当它尝试访问不可用的API时。因此,请确保在minSdkVersion属性中声明合适的API级别。
-------------------------------
* android:targetSdkVersion
An integer designating the API Level that the application targets. If not set, the default value equals that given to minSdkVersion.
一个整数,指示应用程序目标定为的API级别。如果未被设置,那么默认值等于给予minSdkVersion的值。
This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).
这个属性告诉系统你已经针对该目标版本测试过并且该系统不应该使能任何兼容行为以维持你的应用对目标版本的向后兼容性。该应用程序仍然可以运行在较旧的版本(低至minSdkVersion)。
As Android evolves with each new version, some behaviors and even appearances might change. However, if the API level of the platform is higher than the version declared by your app's targetSdkVersion, the system may enable compatibility behaviors to ensure that your app continues to work the way you expect. You can disable such compatibility behaviors by specifying targetSdkVersion to match the API level of the platform on which it's running. For example, setting this value to "11" or higher allows the system to apply a new default theme (Holo) to your app when running on Android 3.0 or higher and also disables screen compatibility mode when running on larger screens (because support for API level 11 implicitly supports larger screens).
当Android伴随每个新版本进化时,一些行为甚至外观可能会改变。然而,如果平台的API级别高于你的应用的targetSdkVersion声明的版本,那么系统可以使能兼容行为以确保你的应用继续以你期望的方式工作。你可以屏蔽这种兼容行为,通过指定targetSdkVersion以匹配它正在运行在的平台的API级别。例如,设置这个值为"11"或更高,会允许系统应用一个新的默认主题(Holo)到你的应用,当运行在Android 3.0或更高,而且还屏蔽屏幕兼容性模式,当它运行在较大的屏幕(因为对API级别11的支持隐式地支持较大的屏幕)。
There are many compatibility behaviors that the system may enable based on the value you set for this attribute. Several of these behaviors are described by the corresponding platform versions in the Build.VERSION_CODES reference.
存在系统可能使能的许多兼容行为,基于你为这个属性设置的值。这些行为中的一些被Build.VERSION_CODES参考中对应的平台版本描述。
To maintain your application along with each Android release, you should increase the value of this attribute to match the latest API level, then thoroughly test your application on the corresponding platform version.
为了维护你的应用程序和每个Android发布版在一起,你应该递增此属性的值以匹配最新的API级别,然后彻底地在对应的平台版本上测试你的应用程序。
Introduced in: API Level 4
引入:API级别4
* android:maxSdkVersion
An integer designating the maximum API Level on which the application is designed to run.
一个整数,指出该应用程序被设计运行所在的最大API级别。
In Android 1.5, 1.6, 2.0, and 2.0.1, the system checks the value of this attribute when installing an application and when re-validating the application after a system update. In either case, if the application's maxSdkVersion attribute is lower than the API Level used by the system itself, then the system will not allow the application to be installed. In the case of re-validation after system update, this effectively removes your application from the device.
在Android 1.5,1.6,2.0,和2.0.1,系统检查这个属性的值,在安装一个应用程序和在一次系统更新后重新验证该应用程序的时候。在其中一种情况下,如果该应用程序的maxSdkVersion属性低于系统自身使用的API级别时,那么系统将不允许应用程序被安装。在系统更新后的重新验证的情况下,它有效地从设备中移除你的应用程序。
To illustrate how this attribute can affect your application after system updates, consider the following example:
为了描述这个属性如何可以在系统更新后影响你的应用程序,请考虑以下示例:
An application declaring maxSdkVersion="5" in its manifest is published on Android Market. A user whose device is running Android 1.6 (API Level 4) downloads and installs the app. After a few weeks, the user receives an over-the-air system update to Android 2.0 (API Level 5). After the update is installed, the system checks the application's maxSdkVersion and successfully re-validates it. The application functions as normal. However, some time later, the device receives another system update, this time to Android 2.0.1 (API Level 6). After the update, the system can no longer re-validate the application because the system's own API Level (6) is now higher than the maximum supported by the application (5). The system prevents the application from being visible to the user, in effect removing it from the device.
一个在它的清单中声明maxSdkVersion="5"的应用程序被发布在Android市场上。一位用户,他的设备正在运行Android 1.6(API级别4),下载并安装该应用。在几星期后,用户收到一个到Android 2.0的空中系统更新(API级别5)。在更新后被安装后,系统检查应用程序的maxSdkVersion并成功地重新验证它。应用程序正常地起作用。然而,一段时间后,设备收到另一个系统更新,这次是升到Android 2.0.1(API级别6)。在更新后,系统可能不再重新验证该应用程序,因为系统自己的API级别(6)现在高于应用程序支持的最大值(5)。系统阻止应用程序对用户可见,事实上从设备中移除它。
-------------------------------
Warning: Declaring this attribute is not recommended. First, there is no need to set the attribute as means of blocking deployment of your application onto new versions of the Android platform as they are released. By design, new versions of the platform are fully backward-compatible. Your application should work properly on new versions, provided it uses only standard APIs and follows development best practices. Second, note that in some cases, declaring the attribute can result in your application being removed from users' devices after a system update to a higher API Level. Most devices on which your application is likely to be installed will receive periodic system updates over the air, so you should consider their effect on your application before setting this attribute.
警告:不建议声明此属性。首先,没有必要设置该属性作为阻碍你的应用程序安装到新版本的Android平台上的方式,当它们被发布时。设计上,新版本的平台完全是向后兼容的。你的应用程序应该在新版本上工作正常,假设它只使用标准API并且遵循开发的最佳实践。其次,注意在一些情况下,声明该属性可以导致在系统升级到一个较高API级别之后你的应用程序从用户设备中被移除。你的应用程序可能打算被安装在的大多数设备将通过无线网络收到周期性系统更新,所以在设置这个属性前你应该考虑它们对你的应用程序的影响。
-------------------------------
Introduced in: API Level 4
引入:API级别4
-------------------------------
Future versions of Android (beyond Android 2.0.1) will no longer check or enforce the maxSdkVersion attribute during installation or re-validation. Android Market will continue to use the attribute as a filter, however, when presenting users with applications available for download.
Android的未来版本(在Android 2.0.1之后)将不再在安装或重新验证期间检查或实施maxSdkVersion属性。然而,Android市场将继续使用该属性作为一个过滤器,当把可用于下载的应用程序展示给用户时。
-------------------------------
* introduced in:
* 引入:
API Level 1
API级别1
Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.
除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。
Android 4.0 r1 - 14 Feb 2012 21:12
-------------------------------
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)
(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:
* ソフトウェア技術ドキュメントを勝手に翻訳
http://www.techdoctranslator.com/android
* Ley's Blog
http://leybreeze.com/blog/
* 农民伯伯
http://www.cnblogs.com/over140/
* Android中文翻译组
http://androidbox.sinaapp.com/
)