AndroidManifest xml in Android

Each Android application contains a file named AndroidManifest.xml, are stored in the root directory (root) of the application. AndroidManifest xml in Android describes the necessary information of the application for the Android operating system, such information needs to know the operating system before it runs any program. The manifest file jobs that need to make is:

  • Declare the name of the application package. The name of the package is the unique identifier of the application.
  • Describe the components of the application: activity, services, broadcast receivers, and content providers. Declare the name of the class that install these components and the tasks that these components can handle (for example the message that an Intent can handle). The declaration allows the OS Android know these components may be performed what actions and conditions so that we can execute.
  • Define the process (process) will contain components (component) does.
  • Declaring the permissions that apps need to access elements of API and interface with other applications.
  • Declaring the rights that require different applications need to be able to communicate with the component of this application.
  • Description minimum API version that the application can run.
  • Lists the libraries that the application needs to connect.

1. Structure of file Manifest:

The following section describes the structure of the manifest file and the elements that it may contain:

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

<manifest>

    <uses-permission />
    <permission />
    <permission-tree />
    <permission-group />
    <instrumentation />
    <uses-sdk />
    <uses-configuration />  
    <uses-feature />  
    <supports-screens />  
    <compatible-screens />  
    <supports-gl-texture />  

    <application>

        <activity>
            <intent-filter>
                <action />
                <category />
                <data />
            </intent-filter>
            <meta-data />
        </activity>

        <activity-alias>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </activity-alias>

        <service>
            <intent-filter> . . . </intent-filter>
            <meta-data/>
        </service>

        <receiver>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </receiver>

        <provider>
            <grant-uri-permission />
            <meta-data />
            <path-permission />
        </provider>

        <uses-library />

    </application>

</manifest>

2. The convention for the manifest file:

Tag (element):

  • Only two of the tags <manifest> and <application> is mandatory and appears only once. The other tags may appear or not.
  • The tag contains sub tags but it does not contain content is a string. The value (information) is set through attributes.
  • The same tags does not need to arrange the order. For example: the <activity>, <provider> and <service> can be arranged in this order or the <provider>, <service> and <activity>.

Attribute:

  • Attributes do not have to exist, however, in some special tags, it must be to describe the function.
  • Except the attributes of the <manifest>, the name of all remaining properties must begin with the prefix (prefix) Andoid :, for example android: alwaysRetainTaskState.

Declaring class names:

  • Many tags needs to declared Java objects, including the main tags applications and other components: activity, services, broadcast receivers, and content providers.
  • If you install a class implements one of the basic tasks: Activity, Service, BroadcastRecevier, and ContentProvider, information of this class will be declared through the name attribute. Class name must accompany the name of the package. For example: Service class describes is declared as follows:

<manifest . . . >
                 <application . . . >
                       <service android:name=”com.designthing.netapplication” . . . >
                       </service>
                 </application>
</manifest>

However, if the class Service in package has been declared within the manifest tags, we can write brief as follows:

<manifest package=”com.designthing” . . . >
                        <application . . . >
                              <service android:name=”.netapplication” . . . >
                              </service>
                       </application>
</manifest>

When executable component netapplication, Android will create an instance of this class in memory. If Android can not be identified netapplication class, it will create an object of class father netapplication.

Attributes can contain multiple values:

If there is more value to be declared, tags will appear repeatedly. For example, an intent can filter multiple tasks (action):

<intent-filter . . . >
                <action android:name=”android.intent.action.EDIT” />
                <action android:name=”android.intent.action.INSERT” />
                <action android:name=”android.intent.action.DELETE” />
</intent-filter>

Reference to value in other resource files

  • Some attribute values can be displayed to the user, for example label and icon for an activity. The value of these attributes can be just as in the properties, but also can be described in a file resource or theme.
  • Resource Values declaration syntax: @ [package:] type: name.
  • In case resource package names similar to the name of the application package, it could be removed package.
  • Type is the type of resource, for example string or drawable.
  • Name is the name of the resource.
  • For example:  <activity android:icon=”@drawable/smallPic” . . . >
  • Reference to the value of the theme is similar, only instead of ‘@’ sign with a ‘?’:
  • Theme Syntax Values declared:? [Package:] type: name.

String Values: When the attribute value is a string, can be used (‘\\’) for special characters. For example: ‘\\ n’ characters for line breaks.

3. Other features:

The following section describes other features of the manifest file

Intent Filters:

  • The main components of the application (Activities, services, and broadcast receivers) are activated by intents. One intent includes set of information (object Intent) describing corresponding tasks, including data required, type component will perform tasks, and other relevant directives. Android will determine the appropriate component for intent, creating an entity (instance) of the component if necessary, and pass it to the intent.
  • Component have to describe the possibility that it could handle – kind intent that it can meet – through intent filters. So Android operating system have to anticipate the intent of a component before it executable component, intent filters described in the manifest file using the <intent-filter>. A component can have multiple filters, describing various tasks.
  • An intent have to know the name of the component will be enabled through intent.

Icon và Label:

  • Some tags have attributes icon and label to display 1 symbol (icon) small and a text label for the user. Some cards also have the attribute description text string is longer than can be displayed on the screen. For example, the <permission> it has 3 attributes that users must provide information to the application can be accessed, icon: symbols of authority, name: the name of rights, description: describes the authority may inheritance applied to the user.
  • In most cases, the properties icon and label are set in the parent tag becomes the default value for the card.

Permissions:

  • Permission is used to restrict access to program data on the device. These limits are imposed to protect sensitive data and programs can cause errors or deliberate misuse of the user experience.
  • Each right is determined by one single chain. Often string that uniquely identifies each one right. Here are some of the rights conveyed by Android Available
    • android.permission.CALL_EMERGENCY_NUMBERS
    • android.permission.READ_OWNER_DATA
    • android.permission.SET_WALLPAPER
    • android.permission.DEVICE_POWER
  • Every feature of the application can be protected by a right
  • If the application needs access to a feature-protected access rights, it have to describe the rights needed to access the manifest file in the <uses-permission>. When the application is installed on the device, the installer will check can grant requested by checking the authentication certificate of application, if no grant is, the installation may require identification receipt by the user. If authorized, the application can gain access to the protected features, if not authorized, the application will not have access to the protected features without any notice to the user.

<manifest . . . >
                       <permission android:name=”com.example.project.DEBIT_ACCT” . . . />
                       <uses-permission android:name=”com.example.project.DEBIT_ACCT” />
                          <application . . .>
                         <activity android:name=”com.example.project.FreneticActivity”
                         android:permission=”com.example.project.DEBIT_ACCT”
                         . . . >
                        </activity>
             </application>
</manifest>

  • Note that in the example above, the right DEBIT_ACCT not only declared by the <permission>, it can also be used to request permission to the <users-permission>.
  • In the above example, if the attribute permission to use other rights, such as android.permission.CALL_EMERGENCY_NUMBERS, is not no need to declare this right with the <permission>. Just declare the rights declared in the <dùng-permission>.

Library:

  • Each application will need to be linked with the availability of Android library, containing the basic package for compiling the application.
  • However, if the application uses the library package available outside of Android, you need to associate with them. The <uses-library> in the manifest file will perform this task.

4. Some example about AndroidManifest.xml:

Applications send / receive SMS

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.javapapers.androidreceivesms" >
    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".SmsActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <receiver android:name=".SmsBroadcastReceiver" android:exported="true" >
            <intent-filter android:priority="999" >
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

    </application>

</manifest>

 

Add Comment