Android Package and Manifest File

The Android project, sometimes also referred to as an Android package, is a collection of Java packages. Different Android packages can have the same Java package names, whereas the Android package name must be unique across all applications installed on the Android device.

For the OS to access them, each application must declare its available components in a single AndroidManifest XML file. In addition, this file contains the required permissions and behavior for the application to run. Listing 2.5 shows what it looks like for the "Creating a Project and an Activity" recipe.

Listing 2.5 AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.cookbook.simple_activity" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon"

android:label="@string/app_name"> <activity android:name=".SimpleActivity"

android:label="@string/app_name"> <intent-filter>

<action android:name="android.intent.action. MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>

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

The first line is required and standard across all XML files in Android to specify the encoding.The manifest element defines the Android package name and version.The versionCode is an integer that can be evaluated in programs to determine the upgrade or downgrade relationship.The versionName represents a human readable format that can have major and minor revisions declared.

The application element defines the icon and label the user sees from the Android device menu. The label is a string and should be short enough to display under the icon on a user's device. Generally the name can be up to two words of ten characters each without being cut off.

The activity element defines the main activity that is launched when the application is started and the name shown in the title bar when the activity is active. Here, the Java package name needs to be specified, which is com.cookbook.simple_activity. SimpleActivity in this case. Because the Java package name is usually the same as the Android package name, the shorthand notation is often used: .SimpleActivity. However, it is best to remember that the Android package and Java package are distinct.

The intent-filter element informs the Android system of the capabilities of the component. It can have multiple action, category, or data elements for this purpose. This is seen as it is utilized in different recipes.

The uses-sdk element defines the application programming interface (API) level required to run this application. In general, the API level is specified as follows:

<uses-sdk android:minSdkVersion="integer"

android:targetSdkVersion="integer" android:maxSdkVersion="integer" />

Because the Android OS is constructed to be forward compatible, the maxSdkVersion is highly discouraged and not even adhered on devices with Android 2.0.1 or later. Specifying the targetSdkVersion is not required, but allows devices of the same SDK version to disable compatibility settings that might speed up operation.The minSdkVersion should always be specified to ensure the application does not crash when run on a platform that does not support the required features in the application. Always choose the lowest API level possible when specifying this.

The AndroidManifest can also contain permission settings needed to run the application. More complete details about the options are provided in later chapters, but this suffices to cover the recipes in this chapter.

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook


Post a comment