Understanding The Android Application Manifest File

Today, I would like to help you understand the Android Application Manifest File as an android developer. Each android application you build will include a file called AndroidManifest.xml which is placed in the root of the project hierarchy. So why is it important? Because it lets you define the structure and metadata of your android application and its components.

The Android Application Manifest file includes nodes for each of the following components:

Activities

Services

Content providers

Broadcast Receivers

that make up your application and uses Intent Filters and Permissions to determine how they interact with each other and other applications. It also offers you attributes that you can use to specify application metadata like icon and theme among other things.

The Android Application Manifest file is made up of a root manifest tag with a package attribute set to the project’s package. It normally includes an xmlns:android attribute that supplies several system attributes used within the android application manifest file.

Example of Android Application Manifest File

[java];
[ …manifest nodes… ]

[/java]

As stated earlier, the manifest tag includes nodes that define the application components, security settings and even test classes that make up your cool app. Let us now get personal with these manifest node tags with xml examples.

Android Application Manifest Node Tags

1)application – A manifest can contain only one application node. This uses attributes to specify the metadata for your android application(title, icon and theme). Besides that, it acts as a container that includes the Activity, Service, Content Provider and Broadcast Receiver tags for specifying the application components:

[java];
[… application nodes … ]

[/java]

activity – For every activity displayed by your android application, an activity tag is required. You set it using android:name attribute to specify the class name. It must include the main launch Activity and any other screen or dialog that can be displayed. If you try to start an Activity that is not defined, you will get a runtime exception. Each Activity node supports intent-filter child tags which specify which Intents launch the activity.

[java]

[/java]

service – Just like the activity tag, you must create a new service for each Service class used inside your application. Service tags also support intent-filter child tags to allow late runtime binding.

[java]
[/java]

provider – provider tags are used for each of your application’s Content Providers. Content Providers are used to manage database access and sharing within and between applications.

[java]
[/java]

receiver – You can register a Broadcast Receiver by adding a receiver tag without having to launch your application first. Broadcast Receivers are more like global event listeners – once registered, they will execute whenever a matching Intent is broadcast by an application.

[java]
[/java]

2)uses-permission – this is part of the security model. It declares permissions you have determined that your application needs to operate properly. The permissions you include will always be presented to the user to either grant or deny during installation. Many native android services require permissions for example those that have cost or security implications. Examples : location services, SMS etc.

[java]

[/java]

3)permission – You need to define a permission in the android application manifest file before restricting access to any application component. Use the permission tag to create the permission definitions. The application components can then require them by adding the android:permission attribute. Other apps will then need to include a uses-permission tag in their manifest file and have it granted before they can use these protected components.

Within the permission tag you can specify the level of access the permission will permit( normal, dangerous, signature, signatureOrSystem), a label, and an external resource containing the description that explains the risks of granting this permission.

[java]
[/java]

4)instrumentation – Instrumentation classes provide a framework for running tests on your Activities and Services at run time. They simply provide hooks to monitor your application and its interaction with the system resources. You must create a new node for each of the test classes you have created in your application.

[java]

[/java]

Summary

That is basically what you need to know about android application manifest file as a beginner. I hope you enjoyed reading through this and if you have any questions, please ask them away.

Thank you for reading through this post. Please consider sharing it using the buttons below. To read more about the Android Application Manifest File, please click here. See you soon and let me know if you have any comments. Subscribe for more cool posts.

Written By Elisha Chirchir

Elisha Chirchir is a software developer. He is also the founder of Simple Developer and co-founder of Instinctive Software Solutions. On any given day, he works on both Android and Web Development. During his 'free time', he offers training to those interested in learning how to code in php, java, python, javaScript etc. You can easily find him on StackOverflow Android chatroom or on Twitter @Eenvincible

7 Comments on “Understanding The Android Application Manifest File”

I am now not certain where you’re getting your information, however good topic. I must spend a while studying more or understanding more. Thank you for magnificent info I was on the lookout for this information for my mission.

I don’t understand your first line there “I am now not certain where you’re getting your information”. Normally, after you learn how to program or build android apps, you will eventually know what lives in the androidmanifest xml file. That is how I learned it then shared with others here.

Thank you for stopping by and I hope you enjoy your learning process. Good luck!

Please give more details so I can help you with this problem. Remember to add all newly created activities, services, broadcast receivers and other main components to the android manifest file or nothing will work for your app. Again, please give more details and I can gladly help you!

I have never seen that done before but there is no need to do that. The best way to get permissions in android is to ask for them all at once. If I learn of how to do that, I will let you know or you can update me if you do as well. Good luck.