Skip to content
Related Articles

Related Articles

Application Manifest File in Android

View Discussion
Improve Article
Save Article
  • Last Updated : 04 Aug, 2022
View Discussion
Improve Article
Save Article

Every project in Android includes a Manifest XML file, which is AndroidManifest.xml, located in the root directory of its project hierarchy. The manifest file is an important part of our app because it defines the structure and metadata of our application, its components, and its requirements. This file includes nodes for each of the Activities, Services, Content Providers, and Broadcast Receiver that make the application, and using Intent Filters and Permissions determines how they coordinate with each other and other applications.

The manifest file also specifies the application metadata, which includes its icon, version number, themes, etc., and additional top-level nodes can specify any required permissions, unit tests, and define hardware, screen, or platform requirements. The manifest comprises a root manifest tag with a package attribute set to the project’s package. It should also include an xmls:android attribute that will supply several system attributes used within the file. We use the versionCode attribute is used to define the current application version in the form of an integer that increments itself with the iteration of the version due to update. Also, the versionName attribute is used to specify a public version that will be displayed to the users.

We can also specify whether our app should install on an SD card of the internal memory using the installLocation attribute. A typical manifest file looks as:

XML




<?xml version="1.0" encoding="utf-8"?>
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.geeksforgeeks"
    android:versionCode="1"
    android:versionName="1.0"
    android:installLocation="preferExternal">
    
      <uses-sdk  
        android:minSdkVersion="18"  
        android:targetSdkVersion="27" />
  
    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
  
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
  
</manifest>

A manifest file includes the nodes that define the application components, security settings, test classes, and requirements that make up the application. Some of the manifest sub-node tags that are mainly used are:

1. manifest

The main component of the AndroidManifest.xml file is known as manifest. Additionally, the package field describes the activity class’s package name. It must contain an <application> element with the xmlns:android and package attribute specified.

XML




<?xml version="1.0" encoding="utf-8"?>
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.geeksforgeeks">
  
    <!-- manifest nodes -->
  
    <applicataion>
  
    </applicataion>
  
</manifest>

2. uses-sdk

It is used to define a minimum and maximum SDK version by means of an API Level integer that must be available on a device so that our application functions properly, and the target SDK for which it has been designed using a combination of minSdkVersion, maxSdkVersion, and targetSdkVersion attributes, respectively. It is contained within the <manifest> element.

XML




<uses-sdk  
    android:minSdkVersion="18"  
    android:targetSdkVersion="27" />

3. uses-permission

It outlines a system permission that must be granted by the user for the app to function properly and is contained within the <manifest> element. When an application is installed (on Android 5.1 and lower devices or Android 6.0 and higher), the user must grant the application permissions.

XML




<uses-permission
    android:name="android.permission.CAMERA"
    android:maxSdkVersion="18" />

4. application

A manifest can contain only one application node. It uses attributes to specify the metadata for your application (including its title, icon, and theme). During development, we should include a debuggable attribute set to true to enable debugging, then be sure to disable it for your release builds. The application node also acts as a container for the Activity, Service, Content Provider, and Broadcast Receiver nodes that specify the application components. The name of our custom application class can be specified using the android:name attribute. 

XML




<application
    android:name=".GeeksForGeeks"
    android:allowBackup="true"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@drawable/gfgIcon"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@android:style/Theme.Light"
    android:debuggable="true"
    tools:targetApi="31">
          
    <!-- application nodes -->
  
</application>

5. uses-library

It defines a shared library against which the application must be linked. This element instructs the system to add the library’s code to the package’s class loader. It is contained within the <application> element.

XML




<uses-library
    android:name="android.test.runner"
    android:required="true" />

6. activity

The Activity sub-element of an application refers to an activity that needs to be specified in the AndroidManifest.xml file. It has various characteristics, like label, name, theme, launchMode, and others. In the manifest file, all elements must be represented by <activity>. Any activity that is not declared there won’t run and won’t be visible to the system. It is contained within the <application> element.

XML




<activity
    android:name=".MainActivity"
    android:exported="true">
</activity>

7. intent-filter

It is the sub-element of activity that specifies the type of intent to which the activity, service, or broadcast receiver can send a response. It allows the component to receive intents of a certain type while filtering out those that are not useful for the component. The intent filter must contain at least one <action> element.

XML




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

8. action

It adds an action for the intent-filter. It is contained within the <intent-filter> element.

XML




<action android:name="android.intent.action.MAIN" />

9. category

It adds a category name to an intent-filter. It is contained within the <intent-filter> element.

XML




<category android:name="android.intent.category.LAUNCHER" />

10. uses-configuration

The uses-configuration components are used to specify the combination of input mechanisms that are supported by our application. It is useful for games that require particular input controls. 

XML




<uses-configuration
    android:reqTouchScreen=”finger”
    android:reqNavigation=”trackball”
    android:reqHardKeyboard=”true”
    android:reqKeyboardType=”qwerty”/>
  
<uses-configuration
    android:reqTouchScreen=”finger”
    android:reqNavigation=”trackball”
    android:reqHardKeyboard=”true”
    android:reqKeyboardType=”twelvekey”/>

11. uses-features

It is used to specify which hardware features your application requires. This will prevent our application from being installed on a device that does not include a required piece of hardware such as NFC hardware, as follows: 

XML




<uses-feature android:name=”android.hardware.nfc” />

12. permission

It is used to create permissions to restrict access to shared application components. We can also use the existing platform permissions for this purpose or define your own permissions in the manifest. 

XML




<permission 
    android: name=”com.paad.DETONATE_DEVICE”
    android:protectionLevel=“dangerous”
    android:label=”Self Destruct”
    android:description=”@string/detonate_description”>
</permission>


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!