Manifest File in Android

In this article, we will proceed with a core and necessary file in any android app. Until now, you would have noticed that whatever apps you develop have an Android Manifest file present as the first file in your source directory.
The Manifest file is crucial for any developer because you define every detail about your application using this file. Manifest files are used to provide information about your application and declare activities, intent-filters and seek permissions from users.
So through this article, we will try to cover each aspect that is important and helpful for any Android developer.

Android Manifest File

The Manifest file, as you know, is one of the core files for your android application. Without the presence of a Manifest file, Gradle won’t be able to build your application. Usually, the Android Studio creates a Manifest file with the basic details of your application. The structure of the AndroidManifest.xml file is as follows:

Code:

<manifest>
   <application>
<activity android:name="com.example.applicationname.MainActivity" >
    	</activity>
   </application>
</manifest>

Android Manifest file stores the following information about your android application.

  • Firstly, the manifest file specifies the package name where the complete source code of your project is located.
  • Then the Manifest file contains the list of permissions that might be essential for the proper running of your application.
  • Now comes the application’s metadata, where the app icon, app label, app theme, etc., are specified.
  • Next comes the list of activities that are present in your application. Inside launcher activity, you will find the intent filter.
  • Finally, the Manifest file contains information about components such as services, broadcast receivers, content providers, and so on.

These pieces of information are pretty essential as they are required when somebody installs your application on their device. Your system uses this information to properly install your application on the user’s device and seek permissions. Finally, the whole structure of a Manifest file looks like below:

Code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.techvidvan.techvidvanmenu">
    
    <uses-permission android:name="android.permission.CAMERA" />
    
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.TechVidvanMenu">
        <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>

Element Tags of Manifest File in Android

After seeing a Manifest File, you would notice several tags present in it. Below we have described each of the element tags in detail.

1. <manifest> – Manifest tag is the root tag and specifies the package name for your application.

2. <application> – The application is the subpart of the Manifest tag, and its job is to specify the general information about the applications such as:

  • Icon
  • Allow Backup
  • App Label
  • App Theme
  • Supports RTL (Supporting Right-to-Left Layout)

3. <activity> – The activity tag is a subpart of the <application> and allows you to declare the various activities present in your application.

4. <intent-filter> – The <intent-filter> is a subelement of an activity. It’s used to specify the type of intent you need to perform for the root activity.

5. <action> – The <action> tag is used to specify the action which your intent filter should perform. Every intent filter should have an <action> tag along with it.

6. <category> – The <category> tag is used to provide category name to the intent-filter.

7. <service> – The <service> tag is used to access several APIs and register user-defined services.

Android Manifest File Application Property Elements

1. <uses-permission>: The <uses-permission> tag is used to declare the permissions that your app needs to function properly. By requesting these permissions, you let the Android system know what access your app requires, such as access to the internet or user contacts. Note that some permissions may require explicit user approval at runtime, especially those deemed sensitive.

2. <permission>: The <permission> tag defines custom permissions that your app or other apps can request. These permissions control access to specific components of your app, such as activities or services, and help manage security by restricting who can interact with these components.

3. <permission-groups>:The <permission-groups> tag allows you to organize multiple permissions into a cohesive group. This grouping helps in managing and displaying permissions in a more structured way, making it easier for users to understand and grant related permissions together.

4. <permission-tree>: The <permission-tree> tag specifies a hierarchical structure of permissions, where a particular component is designated as the owner of a set of permissions. This helps in defining a clear permission hierarchy, which can be useful for managing complex permission requirements.

5. <instrumentation>: The <instrumentation> tag is used to define the type and extent of interaction between your application and the Android system. This includes setting up tests or profiling tools that monitor the app’s performance, providing insights into its behavior and helping ensure it meets quality standards.

6. <uses-sdk>: The <uses-sdk> tag specifies the minimum and target SDK versions required for your app. This ensures that your app is compatible with the Android versions it supports and helps the system determine if the app can run on a particular device.

7. <uses-configuration>:The <uses-configuration> tag specifies additional configuration requirements, such as screen size or hardware capabilities, necessary to ensure your app runs smoothly. It helps in optimizing the app’s performance by declaring its dependencies on specific device configurations.

8. <uses-feature>: The <uses-feature> tag declares specific hardware or software features that your app requires to function. This can include camera functionality or Bluetooth support, allowing the Play Store to filter your app’s availability based on device features.

9. <supports-screen, compatible-screen>: These tags specify the screen sizes and densities that your application supports. By defining supported screen configurations, you ensure that your app provides an optimal user experience across various devices with different screen characteristics.

Intent-Filters

Intent-Filters are used to trigger the app components like Activity, Service, Receiver etc. When the app issues an intent towards an app component, the system locates the app component and performs the desired action provided by the intent filter. The action to be performed, data, or the intended message is carried through an object known as an intent object.
In the manifest file, you use the <intent-filter> tag to make intent to app components.

For example, you can see below the intent filter for activities.

Code:

<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>

Icons and Labels

Icons and Labels are an essential part of the Manifest File. The icon describes the app icon displayed on the user device when they install the app on their device. The label defines the name of your application that appears on the action bar and below the app icon.
Usually, the icon and label are defined inside the <application> tag.

Code:

 <application

        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"

……
……
</application>

However, you can have the icon and label for <intent-filter> also. These will be shown to the user when the intent is triggered. By default the <intent-filter> takes the icon and label from the <application> element.

Device Compatibility

The manifest file allows you to select the hardware and software requirements that your app would require. It also consists of the information about the SDK version over which the app is supportive. On the other hand, Google Play Store also enters your Manifest file and locates the hardware and software requirements. Only if the device satisfies those requirements, then the app is installed.

Permissions in Manifest File

Permissions are quite an essential aspect of the manifest file. Suppose you are developing a picture capturing and editing application. Now your application needs access to your camera. Now, if you need camera access, you need to seek permission from the user. After the user grants then only your application can access the camera to capture pictures.

Initially, the app has some permissions set to true, while most are set to false to avoid security issues.

Some of the permissions which are by default true are as follows:

  • INTERNET
  • ACCESS_NETWORK_STATE
  • READ_PHONE_STATE

Now, let’s see how you can specify the permissions for your application. You need to use the <uses-permission> to specify the permission you wish to have in your application.

Code:

<manifest >
<uses-permission .../>
...
<manifest >

Now let’s see the list of permissions that are by default false and require you to make them true if we need them explicitly.

ACCESS_WIFI_STATE
AUTHENTICATE_ACCOUNT
BLUETOOTH
BATTERY_STATS
BIND_APPWIDGET
BROADCAST_WAP_PUSH
BROADCAST_STICKY
BIND_INPUT_METHOD
CALL_PHONE
CHANGE_CONFIGURATION
CAMERA
CLEAR_APP_DATA
CHANGE_WIFI_STATE
CLEAR_APP_USER_DATA
DEVICE_POWER
DELETE_CACHE_FILES
DISABLE_KEYGUARD
DELETE_PACKAGES
EXPAND_STATUS_BAR
EXPAND_STATUS_BAR
FACTORY_TEST
GET_PACKAGE_SIZE
FLASHLIGHT
GLOBAL_SEARCH
HARDWARE_TEST
INTERNAL_SYSTEM_PROCESSES
USE_CREDENTIALS
MANAGE_ACCOUNTS
MANAGE_APP_TOKENS
MODIFY_AUDIO_SETTINGS
MODIFY_PHONE_STATE
NFC
SEND_SMS
PROCESS_OUTGOING_CALLS
SET_ALARM
SET_ALWAYS_FINISH
READ_CALENDAR
KILL_BACKGROUND_PROCESSES
SET_WALLPAPER
VIBRATE
WAKE_LOCK
WRITE_APN_SETTINGS
WRITE_CALENDAR
WARITE_SETTINGS

Summary

From this article, you learned what the Android Manifest file is and why it is used. You saw the structure and the information a Manifest file carries. Later on, you came across the several tags present in the Manifest file and understood what each of them does. Then you saw in detail the procedure to provide permission in your app using the Manifest file.

TechVidvan Team

The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today’s tech industry.