Using the Compatibility Pack - The Android Developer’s Cookbook: Building Applications with the Android SDK, Second Edition (2013)

The Android Developer’s Cookbook: Building Applications with the Android SDK, Second Edition (2013)

B. Using the Compatibility Pack

The compatibility pack, or support library, is a set of classes that have been provided to add support to legacy versions of Android (the minimum API level supported is 4).

Android Support Packages

The support library adds the following packages:

Image android.support.v4.accessibilityservice

Image android.support.v4.app

Image android.support.v4.content

Image android.support.v4.content.pm

Image android.support.v4.database

Image android.support.v4.net

Image android.support.v4.os

Image android.support.v4.util

Image android.support.v4.view

Image android.support.v4.view.accessibility

Image android.support.v4.widget

Table B.1 shows the class that is included in the android.support.v4.accessibilityservice package.

Image

Table B.1 android.support.v4.accessibilityservice

Table B.2 shows the interfaces, classes, and exceptions that are included in the android.support.v4.app package.

Image

Image

Image

Table B.2 android.support.v4.app

Table B.3 shows the interface and classes that are included in the android.support.v4.content package.

Image

Table B.3 android.support.v4.content

Table B.4 shows the class included in the android.support.v4.content.pm package.

Image

Table B.4 android.support.v4.content.pm

Table B.5 shows the class included in the android.support.v4.database package.

Image

Table B.5 android.support.v4.database

Table B.6 shows the classes included in the android.support.v4.net package.

Image

Table B.6 android.support.v4.net

Table B.7 shows the interface and class included in the android.support.v4.os package.

Image

Table B.7 android.support.v4.os

Table B.8 shows the classes included in the android.support.v4.util package.

Image

Table B.8 android.support.v4.util

Table B.9 shows the interfaces and classes included in the android.support.v4.view package.

Image

Image

Table B.9 android.support.v4.view

Table B.10 shows the classes that are included in the android.support.v4.view.accessibility package.

Image

Table B.10 android.support.v4.view.accessibility

Table B.11 shows the interfaces and classes that are included in the android.support.v4.widget package.

Image

Table B.11 android.support.v4.widget

Adding the Support Library to a Project

Adding the support library to a project is a fairly simple and straightforward endeavor. It needs to be downloaded and installed, then added to the build path of the project.

The support library is downloaded through the Android SDK Manager. It can be found in the Extras folder as Android Support Library. When installed, the required .jar files can be found in the SDKInstallationFolder/extras/android/support/VersionNumber/ directory, whereSDKInstallationFolder is where the Android SDK is installed and VersionNumber is the current version of the support library (at the time of this writing, it is called v4).

To add the .jar to an application, create a folder in the project named libs, copy the .jar file into the folder, and add the .jar to the build path.

In Eclipse, refresh the project, open the libs folder, and right-click on the support .jar. From the context menu, choose Build Path → Add to Build Path. When finished, make sure to initiate the support library pieces needed by including them as imports and changing any required include statements to the support versions.