Uses of API Level in Android

The API Level identifier serves a key role in ensuring the best possible experience for users and application 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 user's device, such that version-incompatible applications 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 — <uses-sdk> — to describe the minimum and maximum API Levels under which they are able to run, as well as the preferred API Level that they are designed to support. The element offers two key attributes:

• android:minSdkVersion — Specifies the minimum API Level on which the application is able to run. The default value is "1".

• android:maxSdkVersion — Specifies the maximum API Level on which the application is able to run.

For example, to specify the minimum system API Level that an application requires in order to run, the application would include in its manifest a <uses-sdk> element with aandroid:minSdkVersion attribute. The value of android:minSdkVersion would be 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, the Android system first checks the <uses-sdk> attributes in the application's manifest and compares them against its own internal API Level. The system allows the installation to begin only if these conditions are met:

• If a android:minSdkVersion attribute is declared, its value must be less than or equal to the system's API Level integer. If not declared, the system assumes that the application requires API Level 1.

• If a android:maxSdkVersion attribute is declared, its value must be equal to or greater than the system's API Level integer. If not declared, the system assumes that the application has no maximum API Level.

When declared in an application's manifest, a <uses-sdk> element might look like this:


<uses-sdk android:minSdkVersion="4" /> </manifest>

The principal reason that an application would declare an API Level in android:minSdkVersion is to tell the Android system that it is using APIs that were introduced in the API Level 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 don't 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 the platform version on the target device.

For example, the android.appwidget package was introduced with API Level 3. If an application uses that API, it must declare a android:minSdkVersion attribute with a value of "3". The application will then be installable on platforms such as Android 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 application's API Level requirements, see the <uses-sdk> section of the manifest file documentation.

0 0

Post a comment