The Android manifest

Posted By on March 21, 2016


Download PDF
Base user interface components in Android
Resources in Android

The components, settings and metadata of an Android application are described in theAndroidManifest.xml file. This file is known as the manifest file or the manifest.

All activities, services and content provider components of the application must be statically declared in this file. Broadcast receiver can be defined statically in the manifest file or dynamically at runtime in the application. This file is read by the Android system during installation of the application. The Android system evaluates this configuration file and determines the capabilities of the application.

The Gradle build system for building and packaging Android application can modify the manifest file. For example, the application version is typically supplied by the Gradle build file.

Android manifest example

The following listing shows an example for a simple Android manifest file.

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

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

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:name="RssApplication"
        android:allowBackup="false"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="RssfeedActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".DetailActivity"
            android:label="Details" >
        </activity>
        <activity android:name="MyPreferenceActivity" >
        </activity>

        <service android:name="RssDownloadService" >
        </service>
    </application>

</manifest>

More details of the Android manifest

1. Version and package

The package attribute defines the base package for the Java objects referred to in this file. If a Java object lies within a different package, it must be declared with the full qualified package name.

Google Play requires that every Android application uses its own unique package name. Therefore it is a good habit to use your reverse domain name here. This will avoid collisions with other Android applications.

android:versionName and android:versionCode specify the version of your application.versionName is what the user sees and can be any string.

versionCode must be an integer. The Android Market determines whether it should perform an update of the applications for the existing installation based on that versionCode. You typically start with “1” and increase this value by one if you roll-out a new version of your application.

2. Application and components

The <application> section allows to define metadata for your application and optionally define an explicit application class. It is also a container for declaring your Android components.

The <activity> tag defines an activity component. The name attribute points to class, which (if not fully qualified) is relative to the package defined in the package attribute.

The intent filter part in the Android manifest file, tells the Android runtime that this activity should be registered as a possible entry point into the application and made available in the launcher of the Android system. The action defines that it (android:name="android.intent.action.MAIN" ) can be started and the category android:name="android.intent.category.LAUNCHER" parameter tells the Android system to add the activity to the launcher.

The @string/app_name value refers to resource files which contain the actual value of the application name. The usage of a resource file makes it easy to provide different resources (e.g., strings, colors, icons) for different devices and makes it easy to translate applications.

Similar to the <activity> tag, you can use the service, receiver and provider to declare other Android components.

3. Minimum and target SDK

The uses-sdk section in the manifest allows you to specify the minSdkVersion andtargetSdkVersion version of your application.

Table 3. Minimum and target version

Value Description
minSdkVersion Define the minimum version of Android your application works on. This attribute is used as a filter in Google Play, i.e., a user cannot install your application on a device with a lower API level than specified in this attribute.
targetSdkVersion Specifies the version on which you tested and developed. If it is not equal to the API version of the Android device, the Android system might apply forward- or backward-compatibility changes. It is good practice to always set this to the latest Android API version to take advantages of changes in the latest Android improvements.

4. Permissions

The Android manifest file must also contain the required permissions for the application. For example, if the application requires network access, it must be specified here.

Your application can declare permissions with the <permission> tag and declare that it required a permision with the <uses-permission> tag.

Certain permissions, like network access, are granted automatically on Android 6.0 or higher systems. Other permissions must be confirmed by the users to become active.

5. Required device configuration

The uses-configuration section in the manifest allows you to specify required input methods for your device. For example, the following snippet would require that the device has a hardware keyboard.

<uses-configuration android:reqHardKeyboard="true"/>

The uses-feature section allows you to specify the required hardware configuration for your device. For example, the following snippet would require that the device has a camera.

<uses-feature android:name="android.hardware.camera" />

6. Installation location

Via the installLocation attribute of your application you can specify if your application can be installed on the external storage of the device. Use auto or preferExternal to permit this.

In reality this option is rarely used, as an application installed on the external storage is stopped once the device is connected to a computer and mounted as USB storage.

Base user interface components in Android
Resources in Android

Download PDF

Posted by Akash Kurup

Founder and C.E.O, World4Engineers Educationist and Entrepreneur by passion. Orator and blogger by hobby

Website: http://world4engineers.com