AndroidManifest.xml file in detail


             AndroidManifest.xml is one of the most important components of an Android application. It stores essential information about the application. This file stores the nature of the application.
Working with AndrodManifest.xml is very important.
Some of the important and commonly used things are given below,
Sample manifest file;

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="16" />

    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="" />
android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
<receiver android:name="MyBroadcastReceiver" >
                <action android:name="MyBroadcast" >
            android:authorities="com.compiletimeerror.Sample" />
            android:label="Sample Service" /> 

<manifest> is the root element of the file. This element can occur only once. xmlns and package attributes are mandatory in this element.
xmlns:android attribute is used to specify the android namespace ""
package attribute is used to specify unique package name for the application.
android:versionCode is the internal version number.
android:versionName is the version to be displayed to the users.
<manifest> element may contain other attributes android:sharedUserLabel, android:sharedUserId

<application> is used to declare the application. This element will also occur only once. This element is used to declare the other application components like service, broadcast receivers, activities, etc..
Some of the important properties of this element are;
android:allowBackup : This takes boolean value true/false. This tells whether to allow the application for backup, restore.
android:icon : This takes 'drawable resource' as value. This is the application Icon.
android:label : This takes 'string resource' as value. This is the label of the application.
android:theme : This takes 'resource/theme' as value. This is the style to be used for all the activities of the application.

<application> may contain any of the below sub-elements;
     <uses-library> and lot more...

<activity> is used to declare Activity classes. All the activities used in the application should have <activity> element in the manifest file. If any activity class is not specified in the manifest file, then it will never be used by the application.
Important attribute of this element is android:name
android:name attribute should contain fully qualified name of the activity class.
For example: if you have an activity class called MyActivity inside com.myapp package, then android:name should have "com.myapp.MyActivity" as value.
android:label attribute can be used to display the user readable name for the activity.

The sub element <intent-filter> is used to specify the type of intent to which the activity is going to respond.
intent-filter must contain <action> element. The action element adds action to the intent-filter.
<intent-filter> can also be used inside <service>, <receiver>, <activity-alias> elements.

<receiver> element is used to declare a broadcast receiver. (See this example for broadcast receiver usage). Android broadcastreceiver is a component where you can register for system or application events. You will be notified about the events after registering. The broadcast receiver can also be registered programatically. <receiver> element will also contain <intent-filter>.
android:name attribute must be given with the name of the java class implementing the broadcast receiver.

<provider> element is used to declare content provider component. All the content providers used in the application should be specified in the manifest file.
android:name attribute specifies the name of the java class implementing the content provider.

<service> element is used to declare Service components. Services are the components that do not have visual interface. Services are used in background processes.
android:name attribute is the name of the Service subclass implementing the service. <service> can also contain <intent-filter> sub element.

<activity-alias> element is used to declare an alias for already declared activity. Which means the activity must be declared before creating alias. targetActivity attribute is used to specify the activity name for which we are creating the alias.

<uses-sdk> element is used to specify the api-level value which specifies the application compatibility android versions.
android:minSdkVersion is the minimum required api-level for the application to run.
android:targetSdkVersion is the targetted api-level. If this is not specified then minSdkVersion will be used as default value.

<uses-permission> is contained in <manifest>. This element is used to specify any special permissions required to run this application.
For example; Performing a network operation requires android.permission.INTERNET.
To use the device camera, we need android.permission.CAMERA
Some of the other permissions are;

These are the common elements in AndroidManifest.xml file. Below list is the valid elements that can be used in the manifest file.


1 comment:
Write comments

Popular Posts