Monday, 8 June 2015

AndroidManifest.xml file in android

Every application must have an AndroidManifest.xml file. The manifest file presents essential information about your app to the Android system. It contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc.

 A simple AndroidManifest.xml file looks like.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

   package="your.java.package.name"

   android:versionCode="1"

   android:versionName="1.0" >
<!-- min and max api level here  -->

    <uses-sdk

      android:minSdkVersion="8"

      android:targetSdkVersion="22" />

<!-- permisions here -->

          <uses-permission android:name="android.permission.INTERNET" />

<!-- app comonents inside application tags -->
      <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>

       <service android:name="your.java.package.name.SecretService" >
        </service>

   </application>

</manifest>

Elements of the AndroidManifest.xml file

 The elements used in the above Manifest file are described below.

i. <manifest>

manifest is the root element of the AndroidManifest.xml file. It has package attribute that describes the package name of the activity class.

ii.<uses-sdk> this element describes the minimum and Target api level of android.


iii. <uses-permission> This element describes the permissions for the application. A permission is a restriction limiting access to a part of the code or to data on the device.  

iv. <application>

application is the subelement of the manifest. It includes the namespace declaration. This element contains several subelements that declares the application component such as activity etc.
The commonly used attributes are of this element are icon, label, theme etc.
android:icon represents the icon for all the android application components.
android:label works as the default label for all the application components.
android:theme represents a common theme for all the android activities.

v. <activity>

The activity represents an activity (Single Screen) that must be defined in the AndroidManifest.xml file. It has attributes like label, name, theme, launchMode etc.
android:label represents a Title of Activity (Label) i.e. displayed on the screen.
android:name This attribute must be present in activity. which represents a name for the activity class. name must be same as java activity class.

vi. <intent-filter>

intent-filter describes the type of intent to which activity, service or broadcast receiver can respond to.  it is the sub-element of activity that

vii. <action>

It adds an action for the intent-filter. The intent-filter must have at least one action element.

viii. <category>

It adds a category name to an intent-filter.





No comments:

Post a Comment