Android manifest file and its Elements with example

In this tutorial, we will find what is an android manifest file. We also talk about the different elements. If you are new here and don’t know how to create a new project in android studio. Create a new project in android.

What is an Android manifest file?

The Manifest file provides information about your app and is in XML format. The manifest file contains the name of your Java package and lists components like Activities, services, content providers, and lots more. If your app needs certain permissions, then they’ll be listed here. In short, Manifest.xml is very crucial for your Android app.

Where we can find the manifest file?

The Android_Manifest file is present inside the root directory. 

Goto Project >> Select Android from drop-down menu >> app >> manifest >> AndroidManifest.xml

android manifest file location

After clicking on the manifest.xml. The file will open and it looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.codingquery.myapplication">

    <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/AppTheme">
        <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>

Elements of manifest.xml file are:

<manifest> This is a root element of the manifest file. It defines the package name of the application. It also tells about versionCode, versionName, etc.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.codingquery.myapplication"
    android:versionCode="1"
    android:versionName="1.0">

</manifest>

We can also specify whether our app should install on an SD card of the internal memory using the installLocation attribute.

<use-sdk> This tag is used for defining the minimum and maximum SDK version that must be available on a device so that our application working properly. targetSdkVersion is used for which it has been designed.

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

<application> A manifest file contains only one application node. It is a subelement of the manifest. It defines the metadata of your android App(icon, name, roundIcon, theme, label ).  The application node also acts as a container for the Activity, Service, Content Provider, and Broadcast Receiver nodes.

<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/AppTheme">
    </application>

<supports-screens> This tag is used to defines the different screens supported by our application.

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:xlargeScreens="true"/>

<activity> It is a subelement of the application element. It represents an activity that must be defined in the AndroidManifest.xml file. Any that are not declared there will not be seen by the system and will never be run. It has many attributes. Some of them are screenOrientation, theme, name, label, and so on.

<activity android:name=".MainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:icon="@drawable/ic_launcher_background">
        </activity>

<intent-filter> Specifies the types of intents that an activity, service, or broadcast receiver can respond to. It’s a sub-element of activity elements. An intent filter must contain an action.

<action>  Adds an action to an intent filter. If there is no action in the intent filter then, the filter doesn’t accept any Intent objects.

<category> It adds a category name to an intent filter.

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

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

If you like this tutorial, Android manifest file and its Elements with example. Follow us on Facebook and Telegram. For more information comment below.

Reference: https://developer.android.com/guide/topics/manifest/manifest-element

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *