Android Manifest
Definition
The Android Manifest File is an essential part of every Android application. It provides important information to the Android system about the app's structure, components, and permissions. The manifest file is an XML file that acts as a bridge between the Android operating system and the application, specifying crucial aspects of the app.
Purpose of the Android Manifest File
The main purpose of the Android Manifest file is to:
Define the application's components such as activities, services, content providers, and broadcast receivers.
Declare the permissions the app needs to access device resources (e.g., internet, camera, GPS).
Specify the minimum Android API level required to run the app.
Define the hardware and software features the app needs, such as a camera or GPS.
Establish the app's entry point by defining the main activity that launches first.
Handle various application settings such as themes, icon, and versioning.
Structure of the Android Manifest File
The Android Manifest file is located in the root directory of the project and is named AndroidManifest.xml. The structure typically looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<!-- App Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Minimum API level required -->
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="30"/>
<!-- App Components -->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<!-- Main Activity -->
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Key Components of the Android Manifest File
a. <manifest> Tag
The root element of the manifest file.
Contains the package name which uniquely identifies the app.
b. <uses-permission> Tag
Used to declare the permissions the app requires to function properly.
Example
If the app needs internet access, the following line is added:
<uses-permission android:name="android.permission.INTERNET" />
c. <application> Tag
Defines the global settings of the application.
It contains attributes like icon, label, allowBackup, theme, etc.
Example:
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
d.<activity> Tag
Declares an activity in the app. Activities represent a single screen with a user interface.
The main activity (the app’s entry point) is marked with an intent-filter.
Example:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
e. <service> Tag
Used to declare a service. A service performs background tasks without a user interface.
Example:
<service android:name=".MyService"/>
f. <receiver> Tag
Declares a broadcast receiver, which listens for and responds to system-wide broadcast messages.
Example:
<receiver android:name=".MyBroadcastReceiver"/>
g. <uses-sdk> Tag
Specifies the minimum SDK version and the target SDK version for the app.
Example:
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="30"/>
Role of the Manifest in Application Configuration
a. Permissions
Permissions control which device features or user data the app can access.
Common permissions include:
android.permission.INTERNET: To access the internet.
android.permission.CAMERA: To access the camera.
b. Declaring Activities and Entry Point
The manifest file is responsible for defining all the activities in the app.
The main activity (launch activity) is identified by the <intent-filter> tag containing the MAIN action and LAUNCHER category.
c. Versioning
The manifest file contains versioning information, including:
versionCode: An integer used for version control.
versionName: A string representing the app’s release version.
Future Enhancements and Features of Manifest Files
With every Android version, new features are added to the manifest file:
Dynamic Feature Modules: Starting from Android 10, developers can create modular apps where specific features can be downloaded on demand.
Background Execution Limitations: Android has increasingly restricted background processes, and these rules are defined through changes in manifest tags and permissions.