Introduction
In this blog, we will look into the Android Manifest file of Android. The manifest file describes the structure and metadata of an application, which makes it a vital aspect of any project. It also defines the components and requirements of a project.
In this article, we will be using the Android Studio application, so in case you haven't yet set up the application on your system, you can check out this article.
Android Manifest
This file contains nodes for each of the Activities, Services, Content Providers, and Broadcast Receiver that make up the application, and it governs how they interact with each other and other applications using Intent Filters and Permissions. For example:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gridview_test">
<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.GridViewTest">
<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 simple example AndroidManifest.xml is shown above, which declares one activity for the program.
Version Information
The manifest includes a root manifest tag with the project's package as the package attribute. It should also have an xmls:android attribute, which will provide numerous system attributes that will be used throughout the file. The android:versionCode is used to specify the current application version as a number that increases with each repetition of the version that has to be updated. The versionName parameter can also be used to provide a public version that will be shown to users. For example,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gridview_test"
android:versionCode = "1"
android:versionName "1 Beta">
</manifest>
Some of the most commonly used manifest sub-node tags are:
Application
Only one application node can be found in a manifest. It specifies metadata for your application using attributes such as its title, icon, and theme. It serves as a container for the application's Activity, Service, Content Provider, and Broadcast Receiver nodes. To specify the name of our custom application class, we can use the android:name parameter. For example,
<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.GridViewTest">
<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>
Permission
Declares security permission for restricting access to this or other applications' specified components or functionalities. For this purpose, we can leverage the existing platform permissions or define our own permissions in the manifest.
Syntax:
<permission android:name="string"
android:protectionLevel=["normal" | "dangerous" | ...]
android:description="string resource"
android:label="string resource"
android:icon="drawable resource"
android:permissionGroup="string" />
Uses Configuration
It specifies which hardware and software features are required by the program. An application can specify information such as it requires a physical keyboard or a certain navigation device in uses-configuration. For example,
<uses-configuration
android:reqFiveWayNav="true"
android:reqHardKeyboard= "true"
android:reqKeyboardType= "qwerty"
android:reqNavigation= "wheel"
android:reqTouchScreen= "finger" />
Uses library
This property specifies a shared library against which the program must be connected and instructs the system to include the library's code in the package's class loader.
Syntax:
<uses-library android:name="string"
android:required=["true" | "false"]
/>
Action
An Action is an interaction contained inside an intent filter that supports a certain purpose and contains a fulfillment that processes the intent. An intent-filter element must contain at least one action element. An intent-filter with no action elements will not accept any Intent objects. For example,
<action android:name="android.intent.action.MAIN" />