Wednesday, April 24, 2019

Understanding Android Manifest File


                                           

                                               Android Manifest file



Every Android application must have a manifest file. Manifest file contains very essential information about the application. Having a proper understanding of manifest is necessary for Android application development.

A manifest file contains following information of Android application

  • Package name: The package name serves as a unique identifier for the application.
  • Activities : All activities are declared in manifest file.
  • Services : All the services used in you application must be declared in activities.
  • BroadcastReceivers : If your application has broadcast receiver, it must be declared in the manifest file.
  • Permissions : Lists the permissions required for your application.
  • API Level : It declares the minimum, maximum and target API level of the Android API that the application requires.
  • Application version : specifies the application version.
  • Features used in application : it specifies which android feature the application require to run properly.
  • Supported screen size : Android devices comes in many shapes and size. You need to specify which screen types your application supports.


Let us have a sample manifest file and discuss each element in detail.



<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.calculator"
    android:versionCode="1"
    android:versionName="1.1" >

    <uses-sdk
        android:minSdkVersion="8"
        android:maxSdkVersion="16"
        android:targetSdkVersion="15" />
   
    <!--  list of permissions  -->
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_MMS" />
   
    <!--  Screen types supported  -->
    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="false"/>
   
    <!--  Features needed -->
    <uses-feature android:name="android.hardware.bluetooth" />
    <uses-feature android:name="android.hardware.camera" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       
         <receiver android:name=".SmsReceiver">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>
        <service  android:name="VibrateService"/>
       
    </application>

</manifest>



Let us discuss each attribute
1:   package="com.android.calculator"
package name of the application is "com.android.calculator".
2: android:versionName="1.1"
version of application is 1.1
3: <uses-sdk
        android:minSdkVersion="8"
        android:maxSdkVersion="16"
        android:targetSdkVersion="15" />

minSdkVersion attribute: specifies the lowest API level that the application supports, here it is 8.
maxSdkVersion attribute: specifies the maximum/highst API level that the application supports, here it is 16.
targetSdkVersion attribute: specifies the optimun API level that the application supports, here it is 15.



4: <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_MMS" />

The application has requested four permissons
Permission to read contacts.
Permission to access internet.
Permission to vibrate the device.
Permission to receive the SMS.


Note: If you not declare the required permission in the manifest and use the feature in your application you will get “SecurityException”. List of all imporatnt permissions is given in the appendix.

5:    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="false"/>

application supports devices with small and normal screens but not support devices with large screens.

6: <uses-feature android:name="android.hardware.bluetooth" />
   <uses-feature android:name="android.hardware.camera" />

Application uses camera and Bluetooth hardware of the device.


7: the     <application> tag

In the application tag all activities, services and broadcast receivers are declared.

No comments:

Post a Comment