AndroidManifest
One of the most important components of your project. Stays in the root directory of the project source. This is used to describe essential information about the app to Android Build Tools, Android OS and Google Play.
Defined using <user-permission> tag and using android:name attribute which can be uniquely identified.
Note if user’s device does not have satisfy these conditions system will not allow it.

Most important things for which AndroidManifest is used:
- To declare app’s package name: Used by Android build tools to map code entities and to map it with applicationId defined in build.gradle
- To declare different app components: Include all activities, services, broadcast receivers, and content providers
- To declare app permissions: Helps in accessing specific restricted by System or other apps.
- To declare hardware and software features: Used to decide which device can app be installed into
- Package name and application ID
Example
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication"
android:versionCode="1"
android:versionName="1.0">
...
</manifest>
How is package attribute used by Android build tools?
- Used as a namespace for the generated R class of the project. E.g com.example.myapplication.R
- Resolve relative names of components declared in the file. E.g <activity android:name=“.FirstActivity"> is resolved as com.example.myapplication.FirstActivity
- When building the final APK, the build tool replaces packageName with applicationId declared build.gradle file. This is then used to uniquely identify the app at system and google play level.
- Avoid changing the package attribute once the project is packaged
App components
Tags to declare different app comments:
- <activity> for each subclass of Activity
- <service> for each subclass of Service
- <receiver> for each subclass of BroadcastReceiver
- <provider> for each subclass of ContentProvider
Things to note:
- Declaring an app component is a must unless it cannot be started by the system (i.e your app will crash while trying to open the non declared component.
- android: name is a must. The value should be a full package destination.
- If the component is part of same package full package name can skipped ie. <activity android:name=“.FirstActivity”> format can be followed
- If the component is part of sub-package (com.example.myapplication.training) then the name attribute must add missing path i.e <activity android:name=“training.TrainingActivity”>
Intent filters
Read https://www.linkedin.com/pulse/android-intent-filters-tech-shift for detailsIcons and Labels
Displays a small icon and the text for the corresponding app component. Set using android:icon and android:label attributes.Things to note:
- The value set for icon and label in parent tag becomes default for child tag. For e.g these attributes set in <application> tag are default values for <activity> tag.
- The icon and label set in <intent-filter> is displayed in the chooser dialog shown to the user. This help in providing better visual display of functionality of that choose option.
Permissions
A way to let application access user sensitive data (contacts, SMS) and some restricted features of Android System (Camera, Bluetooth).Defined using <user-permission> tag and using android:name attribute which can be uniquely identified.
<manifest ... >
<uses-permission android:name="android.permission.SEND_SMS"/>
...
</manifest>
<user-feature> - Specifies the hardware and software feature required by the application.
Things to note:
- Starting Android 6.0 (API level 23) permissions will have be requested at runtime. This means user can accept or cancel as per their wish. So app should be able to handle both these scenarios.
- Apps can use the permissions defined in Android framework or permissions from another app or can defines its own permissions.
- A new permission is declared using <permission> tag.
Device compatibility
With a lot of Android devices in market with different hardware and software support this feature of Android Framework plays a very important role allowing developers to select only those devices which have those features which very much required for the application.<user-feature> - Specifies the hardware and software feature required by the application.
<manifest ... >
<uses-feature android:name="android.hardware.sensor.compass"
android:required="true" />
...
</manifest>
<user-sdk> - Specifies the minimum sdk version with which app is compatible. Those this is not the ideal place to add this info as these information should be mentioned in build.gradle file.
<user-sdk> - Specifies the minimum sdk version with which app is compatible. Those this is not the ideal place to add this info as these information should be mentioned in build.gradle file.
<manifest ... >
<uses-sdk
android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
...
</manifest>
Note if user’s device does not have satisfy these conditions system will not allow it.
Example of AndroidManifest file
Comments
Post a Comment