Learn Android Development For Beginners

AndroidManifest.xml

AndroidManifest.xml file describes the functionality and requirement of application to Android. It is the most important file in the android application and every application must have an AndroidManifest.xml file in its root directory.

AndroidManifest
(Figure 4.8.1)

The AndroidManifest.xml file is simple XML file that describes the important information about the application e.g. Activities, Broadcast receivers and content providers etc. to Android.

Sample AndroidManifest.xml

Following is a sample Android manifest file that was created in “My first App” application. If you don’t have that one than create new project in Android Studio and open the AndroidManifest.xml file.

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfirstapp"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.myfirstapp.MainActivity"
            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>

 </manifest>

<manifest> is the root element of the manifest file. The <manifest> element has some attributes e.g. package="com.example.myfirstapp" which is the most import attributes that describes the Java package name for the application and serves as a unique identifier for the application.

<uses-sdk> is the sub-element of the <manifest> that describes the minimum, maximum and targeted SDK version of the Android API. The SDK version specifies the API Level not the version of the android SDK. The API level is always a single integer number that uniquely identifies the framework API revision offered by a version of the Android Application. The Android platform provides a framework API that applications can use to interact with the underlying Android System.

<application> is also the sub-element of the <manifest>. It has attributes that affects all the components e.g. icon, label, permission, theme etc. android:icon describes the icon for all the android application components. android:label works as the default label for all the application components. android:theme describes a common theme for all the android activities.

<application> also has sub elements that describes the system components e.g. Activity, service , uses library etc.

<activity> is the sub-element of the application. It is the subclass of the activity and every activity in the application must be declared in the AndroidManifest.xml file. The <activity> element has many attributes such as label, name, theme, launchMode etc.

The android application can have many activities and you can let the system knows what is the entry point using <intent-filter> element. The “android.intent.action.MAIN” action is a main entry point and the “android.intent.category.LAUNCHER” says that this entry point should be listed in the application launcher.

The Manifest file can contains some other element. You can find description of each element on internet.

What is Android Manifest File.

The AndroidManifest.xml file describes following information.

  • Names the Java Package for the application. The package name serves as a unique identifier for the application.
  • Describes the components of the application e.g. Activities, Broadcast receivers and content providers etc.
  • Declares the Permissions the application requires to access different protected part.
  • Declares the permissions that other application requires to interact with this application.
  • Declares the minimum level of the Android API that the application requires.

Legal element for Manifest.xml File

Following is the list of legal element of manifest file. You cannot add your own element or attribute.

 <action> 
 <activity> 
 <activity-alias> 
 <application> 
 <category> 
 <data> 
 <grant-uri-permission> 
 <instrumentation> 
 <intent-filter> 
 <manifest> 
 <meta-data> 
 <permission> 
 <permission-group> 
 <permission-tree> 
 <provider> 
 <receiver> 
 <service> 
 <supports-screens> 
 <uses-configuration> 
 <uses-feature> 
 <uses-library> 
 <uses-permission> 
 <uses-sdk> 
;