Android Manifest file

  • In android, manifest file is most important file for any android application or project.
  • Each android project has one android manifest file.
  • Android manifest file is stored on the root of the package explorer hierarchy.
  • The android manifest file defines the structure and metadata of the android application, its components and its requirements.
  • Android manifest file includes the node for each component such as activities, services, content providers, broadcast receiver which are used to make the android application.
  • In android manifest file, by using the intent-filters and permissions, we can determine how they interact with each other and can also with other applications.
  • The android manifest file provides the attributes to specify the application metadata such as icons and themes and it also offers the top level nodes which are used for security settings, unit tests, defining hardware platform support requirements.
  • The android manifest file is uses the <manifest> tag .
  • The manifest file includes the xmlns:android attribute that is used to supply the several system attributes in the file.
  • In android manifest file, the versionCode is used to define the version of the current application. It uses the integer value to define the versionCode.
  • In android manifest file, the versionName is used to define the name of the version of the current application that is shown to the users.
  • The manifest file uses the xml, and demo manifest file can look as follows:
  • <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.helloandroid"     android:versionCode="1"     android:versionName="1.0" >  </manifest>
  • In this demo structure of the manifest file, tag is used to start the creation of the manifest file.
  • Inside this tag, package is used to define the package name of the current application.
  • android:versionCode defines the version of the current application.
  • android:versionName define the name of the version of the current application.
  • tag defines the end of the manifest file.
  • Android manifest file also tells about the target and sdk version as follows:
  • <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
  • node is used to define the minimum, maximum and the target SDK version which must available on a device.
  • If we don’t define these things in the application then our application will not work properly.
  • We can use the combination of the android:minSdkVersion, android:maxSdkVersion and android:targetSdkVersion is used to define that on which device our application can run means using this combination we can restrict which device can run our application that is totally based on the SDK version supported by the platform installed by us.
  • The minimum SDK is used to define the lowest version of the SDK which includes the APIs that we are using in our application.
  • If we are not defining any minimum SDK version for the application then by default version 1 is assumed. In this case, our application can be crash; if it attempts to access APIs which are not available on the host device.
  • The maxSdkVersion is used to define the maximum version of the SDK which we want to use in order to support.
  • Once we defined the maxSdkVersion, then our application will not show on the market for that device which are using the higher version.
  • The targetSdkVersion is used to define the platform on which we did the application development and the testing.
  • The target SDK version tells the android system that there is no need to apply the compatibility to support the particular version.
  • Uses-feature is the important advantage of the android that is used to support the hardware.
  • We can use multiple uses-feature nodes to specify the hardware features which our application requires.
  • This is beneficial because it will prevent our application when we install the application on the device that does not required hardware features.
  • We can use the camera in our application using the android.hardware.camera.
  • If we want autofocus camera then we have to use this attributes android.hardware.camera.autofocus.
  • In manifest file, the activity is defined as follows:
  • <activity
    android:name="com.example.helloandroid.MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
  • <activity> tag is used to define the activity for the application. Every activity of the application uses one tag to define the activity in the android manifest file.
  • By using the android:name attribute; is used to specify the Activity class name.
  • We must include the main launch activity or any other screen or dialog which can be displayed.
  • When our application launch then the first displayed activity is the main activity in the entire application.
  • If we don’t set this, then we get runtime exception.
  • Inside <intent-filter> tag, the main activity is defined or we can make one activity as a main activity for the application.