简体   繁体   中英

Android: android:targetSdkVersion and android:maxSdkVersion

如何使用android:targetSdkVersionandroid:maxSdkVersion xml属性?

The attributes android:minSdkVersion, android:maxSdkVersion let you specify the range of devices your app will support which will be used by Google to filter its content.

Say you have Android version 11 ie Honeycomb on you device and I make an app and I specify android:minVersion = "14" (ie ICS ), then my app will not be shown in your device's Play Store , similarly the android:maxVersion serves the same purpose.

The attribute android:targetSdkVersion is used by the developers to specify the platform they are targeting the most, lets say 70% of Android device users have version 10 ie Gingerbread on their phones so it will be a better option for the developer to test the app on 2.3 devices and specify android:targetSdkVersion to the same.

<uses-sdk android:minSdkVersion="integer" 
          android:targetSdkVersion="integer"
          android:maxSdkVersion="integer" />

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.

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.

android:targetSdkVersion 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).

android:maxSdkVersion An integer designating the maximum API Level on which the application is designed to run.

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.

More in Details

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eample.tut"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />****
<uses-permission android:name="android.permission.INTERNET"/>
<application
....
</application>
</manifest>

Just to add to what Alexis wrote, these XML tags are how the Google Play Store knows which devices your application can deploy to. It will also affect which levels of the API you can use during development. If you're ever wondering exactly how far back you should support, check out the pie graph on the Android Dashboard page to see the breakdown of current devices.

In your android manifest write (example):

<uses-sdk
        android:maxSdkVersion="16"
        android:minSdkVersion="10"
        android:targetSdkVersion="10" />

See this for more informations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM