Monday, October 22, 2012

Inside Android Manifest



The foundation for any Android application is the manifest file, AndroidManifest.xml in 
the root of your project. Here is where you declare what is inside your application—the activities, the services, and so on. You also indicate how these pieces attach themselves to the overall Android system; for example, you indicate which activity (or activities) should appear on the device’s main menu. 
When you create your application, a starter manifest will be generated for you
automatically. For a simple application, offering a single activity and nothing else, the autogenerated manifest will probably work out fine, or perhaps require a few minor modifications. On the other end of the spectrum, the manifest file for the Android API demo suite is more than 1,000 lines long. Your production  Android applications will probably fall somewhere in the middle.

Underneath the Manifest element


  • user permission elements: Indicate the permissions your application will need in order to function properly.
  • permission elements: Declare permissions that activities or services might require other applications to hold in order to use your application’s data or logic.
  • instrumentation elements: Indicate code that should be invoked on key system events, such as starting up activities, for the purposes of logging or monitoring.
  • uses-library elements: Hook in optional Android components, such as mapping services.
  • uses-sdk element: Indicates for which version of the Android SDK the application was built.
  • application element: Defines the guts of the application that the manifest describes.

Here’s an example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commonsware.android">
<uses-permission
android:name="android.permission.ACCESS_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_GPS" />
<uses-permission
android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission
android:name="android.permission.ACCESS_CELL_ID" />
<application>
...
</application>
</manifest>
In this example, the manifest has uses permission elements to indicate some device capabilities the application will need—in this case, permissions to allow the application to determine its current location. The contents of the application element will describe the activities, services, and whatnot that make up the bulk of the application itself.

No comments:

Post a Comment