确定app的系统API level,在mainfest中设置minSdkVersiontargetSdkVersion;对app进行版本控制,在mainfest中设置versionCodeversionName

Supporting Different Platform Versions

Tip: In order to provide the best features and functionality across several Android versions, you should use the Android Support Library in your app, which allows you to use several recent platform APIs on older versions.

To allow your app to take advantage of these changes and ensure that your app fits the style of each user's device, you should set thetargetSdkVersion value to match the latest Android version available.

参考文献:What API level should I target?

Tips:

  • Set android:minSdkVersion to the minimum API level you support.

  • Set android:targetSdkVersion to the highest API level you tested your app on.

  • Do not use android:maxSdkVersion.

  • Set your build target to whatever (I recommend the same as your android:targetSdkVersion), it does not affect the final APK.

  • Wrap calls to new APIs in an if where you check the API level.

  • Test your apps!

<uses-sdk>

<mainfest>

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

   integer -- the value of API level

minSdkVersion(Required): the minimum API level. If not set, the default API level is "1".

If the application were to be somehow installed on a platform with a lower API Level(less than the minSdkVersion value), then it would crash at run-time when it tried to access APIs that don't exist. And the app would not be installed if this value is higher than that of hte platform version on the target device.

targetSdkVersion(Recommended): The API level the application is designed to run and it allows the app to use manifest elements or behaviors defined in the target API level. If not set, the integer value equals to minSdkVersion and only the minimum API level is used.

maxSdkVersion(Not recommended): If the API level is greater than this value, the app will not be installed. And after a system update, its value must be equal or greater than the system's API Level interger.

Check System Version at Runtime

private void setUpActionBar() {
   
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
   
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
       
ActionBar actionBar = getActionBar();
        actionBar
.setDisplayHomeAsUpEnabled(true);
   
}
}

Note:还可以在XML中使用新版本的attributes,如果版本不支持,低版本的Android仅仅ignore某个attribute。

API Level

    某个版本的 Android platform 提供的 framework API revision, through framework API app can interact with underlying Android system.

 The framework API consists of:

  • A core set of 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 system

wKioL1QS73qxkGOpAAE4_l7DzTw072.jpg

Android applications are generally forward-compatible with new versions of the Android platform.

Filtering the Reference Documentation by API Level

By default, API Level filtering is disabled, so that you can view the full framework API, regardless of API Level.

To use filtering, select the checkbox to enable filtering, just below the page search box. Then set the "Filter by API Level" control to the 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 introduced 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.

Versioning Your Applications-- Android APP 版本控制

android:versionCode — An integer value that represents the version of the application code, relative to other versions. Applications and publishing services should not display this version value to users.

android:versionName — A string value(<major>.<minor>.<point>) that represents the release version of the application code, as it should be shown to users. Publishing services may extract

the android:versionName value for display to users.

eg.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     
package="com.example.package.name"
     
android:versionCode="2"
     
android:versionName="1.1">
   
<application android:icon="@drawable/icon" android:label="@string/app_name">
        ...
   
</application>
</manifest>