0% found this document useful (0 votes)
15 views9 pages

Understanding Android Manifest File

The Android Manifest (AndroidManifest.xml) is a crucial file for every Android application, serving as an ID card and blueprint that declares app components, requests permissions, and defines hardware and software requirements. It includes declarations for activities, services, broadcast receivers, and content providers, along with permissions for accessing sensitive data and system features. The Manifest also specifies app metadata, such as the app's name, icon, and unique package name, and outlines advanced features like hardware requirements and deep linking.

Uploaded by

Ann Wangari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views9 pages

Understanding Android Manifest File

The Android Manifest (AndroidManifest.xml) is a crucial file for every Android application, serving as an ID card and blueprint that declares app components, requests permissions, and defines hardware and software requirements. It includes declarations for activities, services, broadcast receivers, and content providers, along with permissions for accessing sensitive data and system features. The Manifest also specifies app metadata, such as the app's name, icon, and unique package name, and outlines advanced features like hardware requirements and deep linking.

Uploaded by

Ann Wangari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

The Android Manifest (officially named AndroidManifest.

xml) is a required file in every Android


application. It's located in the root directory of your app's source code.

Think of it as:

 An ID Card: It presents essential information about your app to the Android operating
system.

 A Blueprint: It declares the app's core components and requirements to the system.

The system must see this file before it can run any of your app's code.

Key Information Stored in the Android Manifest

Here are the most important things the Manifest file does:

1. Declares App Components

This is its primary job. You must declare every component of your app using specific XML elements:

 Activities (<activity>): Your app's screens (e.g., the main screen, a settings screen).

 Services (<service>): Background operations that run without a user interface.

 Broadcast Receivers (<receiver>): Components that respond to system-wide announcements


(e.g., low battery, boot completed).

 Content Providers (<provider>): Manage a shared set of app data that other apps can query.

2. Requests Permissions

If your app needs to access sensitive user data (like contacts or location) or system features (like the
internet or camera), you must declare those permissions here.

 Normal Permissions: Automatically granted at install time (e.g., INTERNET).

 Dangerous Permissions: Must be explicitly granted by the user at runtime (Android 6.0+).

3. Defines Hardware and Software Requirements

The Manifest tells Google Play Store which devices your app can run on.

 Minimum API Level: The oldest version of Android your app supports (minSdkVersion).

 Target API Level: The version of Android your app is optimized for (targetSdkVersion).

 Required Features: Declares if your app requires specific hardware, like a camera (<uses-
feature>).

4. Declares App Metadata

Basic information about the application itself.

 App Name (android:label)

 App Icon (android:icon)


 App's Unique Package Name (package): This is your app's unique identifier on the device
and on the Play Store (e.g., [Link]).

Android Manifest Basic Structure

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="[Link]

package="[Link]">

<!-- Application-level components and properties -->

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme">

<!-- Activities -->

<activity android:name=".MainActivity">

<intent-filter>

<action android:name="[Link]" />

<category android:name="[Link]" />

</intent-filter>

</activity>

<!-- Services -->

<service android:name=".MyService" />


<!-- Broadcast Receivers -->

<receiver android:name=".MyReceiver">

<intent-filter>

<action android:name="[Link].BOOT_COMPLETED" />

</intent-filter>

</receiver>

<!-- Content Providers -->

<provider android:name=".MyContentProvider"

android:authorities="[Link]" />

</application>

<!-- Permissions -->

<uses-permission android:name="[Link]" />

<uses-permission android:name="[Link].ACCESS_FINE_LOCATION" />

</manifest>
Manifest Components Explained
1. Manifest Element

xml

<manifest xmlns:android="[Link]

package="[Link]"

android:versionCode="1"

android:versionName="1.0">

 package: Your app's unique identifier

 versionCode: Integer for version comparison (incremented with each release)

 versionName: User-visible version string

2. Application Element

xml

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme"

android:usesCleartextTraffic="false">

 icon: App icon displayed to users

 label: App name displayed to users

 theme: Default theme for activities

 allowBackup: Whether to include in auto-backup

 usesCleartextTraffic: Whether to allow HTTP traffic

3. Activity Declaration

xml

<activity

android:name=".MainActivity"

android:label="@string/main_activity_title"

android:screenOrientation="portrait"

android:configChanges="keyboardHidden|orientation|screenSize">

<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]" />

</intent-filter>

</activity>

 name: The activity class name (. means relative to package)

 intent-filter: Defines how the activity can be launched

4. Common Intent Filter Actions

xml

<!-- Main launcher activity -->

<intent-filter>

<action android:name="[Link]" />

<category android:name="[Link]" />

</intent-filter>

<!-- Handle specific data types -->

<intent-filter>

<action android:name="[Link]" />

<category android:name="[Link]" />

<category android:name="[Link]" />

<data android:scheme="http" />

<data android:scheme="https" />

<data android:host="[Link]" />

</intent-filter>

<!-- Share intent -->

<intent-filter>

<action android:name="[Link]" />

<category android:name="[Link]" />

<data android:mimeType="text/plain" />

</intent-filter>

5. Permissions
xml

<!-- Request permissions your app needs -->

<uses-permission android:name="[Link]" />

<uses-permission android:name="[Link]" />

<uses-permission android:name="[Link].ACCESS_FINE_LOCATION" />

<!-- Declare permissions your app provides to others -->

<permission

android:name="[Link].SPECIAL_PERMISSION"

android:protectionLevel="normal" />

6. Service Declaration

xml

<service

android:name=".MyService"

android:enabled="true"

android:exported="false">

<intent-filter>

<action android:name="[Link].MY_ACTION" />

</intent-filter>

</service>

 enabled: Whether the service can be instantiated

 exported: Whether other apps can access this service

7. Broadcast Receiver

xml

<receiver

android:name=".MyReceiver"

android:enabled="true"

android:exported="false">

<intent-filter>

<action android:name="[Link].BOOT_COMPLETED" />

<action android:name="[Link].ACTION_POWER_CONNECTED" />


</intent-filter>

</receiver>

8. Content Provider

xml

<provider

android:name=".MyContentProvider"

android:authorities="[Link]"

android:exported="true"

android:readPermission="[Link].READ_EXTERNAL_STORAGE"

android:writePermission="[Link].WRITE_EXTERNAL_STORAGE">

</provider>

Advanced Manifest Features

9. Hardware and Software Features

xml

<!-- Specify required device features -->

<uses-feature

android:name="[Link]"

android:required="false" />

<uses-feature

android:name="[Link]"

android:required="true" />

<!-- Screen compatibility -->

<supports-screens

android:smallScreens="true"

android:normalScreens="true"

android:largeScreens="true"

android:xlargeScreens="true" />

<!-- API level requirements -->


<uses-sdk

android:minSdkVersion="21"

android:targetSdkVersion="33"

android:maxSdkVersion="33" />

10. App Links and Deep Linking

xml

<!-- App Links for HTTP deep linking -->

<intent-filter android:autoVerify="true">

<action android:name="[Link]" />

<category android:name="[Link]" />

<category android:name="[Link]" />

<data android:scheme="https" />

<data android:host="[Link]" />

<data android:pathPrefix="/products" />

</intent-filter>

11. Metadata for Components

xml

<activity android:name=".MainActivity">

<meta-data

android:name="[Link].APPLICATION_ID"

android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" />

</activity>

<application>

<meta-data

android:name="[Link].API_KEY"

android:value="YOUR_GOOGLE_MAPS_API_KEY" />

</application>

12. Backup Rules

xml

<application
android:allowBackup="true"

android:fullBackupContent="@xml/backup_rules">

<!-- Alternatively, specify backup rules directly -->

<full-backup-content>

<include domain="sharedpref" path="."/>

<exclude domain="database" path="sensitive_data.db"/>

</full-backup-content>

</application>

You might also like