The Android Manifest file is necessary in every Android application and must be named AndroidManifest.xml exactly. The AndroidManifest uses XML to define everything that lives inside it, which makes it easy enough for us to take a closer look at what is inside it. Following code is generated by Android Studio for our empty activity App MyFirstApp
:
1. <?xml version="1.0" encoding="utf-8"?> 2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3. package="com.brainbell.myfirstapp"> 4. <application 5. android:allowBackup="true" 6. android:icon="@mipmap/ic_launcher" 7. android:label="@string/app_name" 8. android:roundIcon="@mipmap/ic_launcher_round" 9. android:supportsRtl="true" 10. android:theme="@style/AppTheme"> 11. <activity android:name=".MainActivity"> 12. <intent-filter> 13. <action android:name="android.intent.action.MAIN" /> 14. <category android:name="android.intent.category.LAUNCHER" /> 15. </intent-filter> 16. </activity> 17. </application> 18. </manifest>
Line 2 and 3 <manifest> tag:
A parent container tag containing the xmlns:android schema reference and application's package name.
Line 4 <application> tag:
Android manifest files generally include a single <manifest> tag with a single <application> tag. The <application> tag contain several parameters:
Line 5 android:allowBackup ="true":
The default value of this attribute is true. This attribute determines if an application's data can be backed up and restored by the users.
Line 6 android:icon="@mipmap/ic_launcher":
The default application icon stored within the /res/mipmap
directory (there are actually multiple versions for different pixel densities, such as, /res/mipmap-anydpi-v26, /res/mipmap-hdpi, /res/mipmap-mdpi, /res/mipmap-xhdpi, /res/mipmap-xxhdpi, /res/mipmap-xxxhdpi).
Line 7 android:label= "@string/app_name":
The user-friendly app name. Must be set as a reference to a string resource.
Line 8 android:roundIcon= "@mipmap/ic_launcher_round":
The default app icon in round shape. On some Android devices, the home screen launcher can show round icons.
Line 9 android:supportsRtl= "true":
The default value of this attribute is false. Set true if your app in Arabic, Hebrew, Urdu or any other language that is written from right to left.
Line 10 android:theme= "@style/AppTheme":
A reference to a style resource defining a default theme to use for the application.
Line 11 <activity> tag:
The <application> child tag has its own child tag called an <activity> tag that defines the name for MainActivity.java file as well as a label. This application has a single Activity MainActivity
.
Line 12 <intent-filter> tag:
The <activity> tag also has a child tag called an <intent-filter> tag, an intent filter declares the capabilities of the Activity i.e. what an activity can do.
Line 13 <action> tag:
The <intent-filter> tag has an <action> child tag, which references to Main Activity. An <intent-filter> tag must contain one or more <action> tags. android.intent.action.MAIN
defines the primary entry point for the application.
Line 14 <category>:
The <category> tag that references an intent action category constant of LAUNCHER
. This Intent serves to launch an Android application by launching the MainActivity top-level Activity subclass to the main display screen.
List of possible elements in AndroidManifest.xml
The code snippet below shows the general structure of the manifest file and every element that it can contain.
1. <?xml version="1.0" encoding="utf-8"?> 2. <manifest> 3. <uses-permission /> 4. <permission /> 5. <permission-tree /> 6. <permission-group /> 7. <instrumentation /> 8. <uses-sdk /> 9. <uses-configuration /> 10. <uses-feature /> 11. <supports-screens /> 12. <compatible-screens /> 13. <supports-gl-texture /> 14. <application> 15. <activity> 16. <intent-filter> 17. <action /> 18. <category /> 19. <data /> 20. </intent-filter> 21. <meta-data /> 22. </activity> 23. <activity-alias> 24. <intent-filter> . . . </intent-filter> 25. <meta-data /> 26. </activity-alias> 27. <service> 28. <intent-filter> . . . </intent-filter> 29. <meta-data/> 30. </service> 31. <receiver> 32. <intent-filter> . . . </intent-filter> 33. <meta-data /> 34. </receiver> 35. <provider> 36. <grant-uri-permission /> 37. <meta-data /> 38. <path-permission /> 39. </provider> 40. <uses-library /> 41. </application> 42. </manifest>
uses-permission
Line 3. A permission is a way for Android to require an app developer to notify the user about something that the app will do that might raise concerns with the user.
For more information visit:
https://developer.android.com/guide/topics/manifest/uses-permission-element.html.
permission
Line 4. It is signature-level permission for securing your own app, e.g. when making an app that other apps can access in to, limiting access is a must.
For more information visit:
https://developer.android.com/guide/topics/manifest/permission-element.html.
permission-tree
Line 5. Declares a base name of the tree of permissions that can be added programmatically using the method addPermission()
of the class android.content.pm.PackageManager
.
For more information visit:
https://developer.android.com/guide/topics/manifest/permission-tree-element.html.
permission-group
Line 6. Permissions (<permission>) are collected into permission groups.
For more information visit:
https://developer.android.com/guide/topics/manifest/permission-group-element.html.
instrumentation
Line 7. Allow to configure unit-testing feature for monitoring the application.
For more information visit:
https://developer.android.com/guide/topics/manifest/instrumentation-element.html.
uses-sdk
Line 8. Allow developers to specify which versions of the Android platform an app supports. This tag has three important attributes: minSdkVersion, targetSdkVersion and maxSdkVersion, which specify the lowest, optimum and highest API level, respectively.
For more information visit:
https://developer.android.com/guide/topics/manifest/uses-sdk-element.html.
uses-configuration
Line 9. Allow developers to specify which hardware and software input methods the application supports. Multiple use configuration tags can be used to list different combinations of system features that the application can support.
For more information visit:
https://developer.android.com/guide/topics/manifest/uses-configuration-element.html.
uses-feature
Line 10. Allow developers to restrict the app to devices that have certain hardware or software features.
For more information visit:
https://developer.android.com/guide/topics/manifest/uses-feature-element.html.
supports-screens
Line 11. Screen sizes and pixel densities vary tremendously across the wide range of Android devices. This tag allow developers to specify which "Android types" (small or large and HDPI or extra-high-HDPI ) of screens the app supports.
For more information visit:
https://developer.android.com/guide/topics/manifest/supports-screens-element.html.
compatible-screens
Line 12. The compatible-screens element is not used by Android or your app directly. It is used only by the Google Play Store to determine which devices this app is compatible with.
For more information visit:
https://developer.android.com/guide/topics/manifest/compatible-screens-element.html.
supports-gl-texture
Line 13. Specify if your app use the graphics libraries and you want to allow only devices that support a specific GL compression format.
For more information visit:
https://developer.android.com/guide/topics/manifest/supports-gl-texture-element.html.
application
Line 14. This tag contains application-wide settings, including the application label and icon, as well as information about the application components, such as activities, and other application components, including configuration for services, intent filters, and content providers.
For more information visit:
https://developer.android.com/guide/topics/manifest/application-element.html.
activity
Line 15. Declares an activity that implements part of the application's visual user interface.
For more information visit:
https://developer.android.com/guide/topics/manifest/activity-element.html.
intent-filter
Line 16. Intent filters are used to declare serviceable intents in Android. This information is then used by Android to search the right serving component for implicit intents.
For more information visit:
https://developer.android.com/guide/topics/manifest/intent-filter-element.html.
action
Line 17. An <intent-filter> tag must contain one or more <action> tags.
For more information visit:
https://developer.android.com/guide/topics/manifest/action-element.html.
category
Line 18. Allow developers to specify additional information describing the supported categories of the intent.
For more information visit:
https://developer.android.com/guide/topics/manifest/category-element.html.
data
Line 19. Allow developers to describe the URL and/or MIME type that they wish to respond to.
For more information visit:
https://developer.android.com/guide/topics/manifest/data-element.html.
meta-data
Line 21. This tag can be child of <activity>, <activity-alias>, <receiver>, or <service> tags. Put more data to use with libraries or plugin distribution models for sharing some configuration.
For more information visit:
https://developer.android.com/guide/topics/manifest/meta-data-element.html.
activity-alias
Line 23. Aliases provides an alternative set of Intent filters or other component settings for an already-defined activity.
For more information visit:
https://developer.android.com/guide/topics/manifest/activity-alias-element.html.
service
Line 27. A Service is an entity that runs without a user interface, it has life-cycle callback methods, similar to those of Activity.
For more information visit:
https://developer.android.com/guide/topics/manifest/service-element.html.
receiver
Line 31. A broadcast receiver listens for incoming intents.
For more information visit:
https://developer.android.com/guide/topics/manifest/receiver-element.html.
provider
Line 35. A content provider allows your app to share data (i.e. SQLite database) with other applications.
For more information visit:
https://developer.android.com/guide/topics/manifest/provider-element.html.
grant-uri-permission
Line 36. Specifies which data subsets of the parent content provider permission can be granted for. Defines a URI address of the ContentProvider component, to which a one-time access can be granted for third-party applications.
For more information visit:
https://developer.android.com/guide/topics/manifest/grant-uri-permission-element.html.
path-permission
Line 38. Path permissions allow a content provider to assign individual permissions for different paths in its URIs, enabling the content provider to allow access to different sections of the data it exposes.
For more information visit:
https://developer.android.com/guide/topics/manifest/path-permission-element.html.
uses-library
Line 40. Allow developers to link to additional external libraries.
For more information visit:
https://developer.android.com/guide/topics/manifest/uses-library-element.html.