AndroidManifest.xml:
AndroidManifest.xml is a powerful
file in the Android platform that allows you to describe the functionality and
requirements of your application to Android. However, working with it is not
easy.Android helps to minimize this difficulty by allowing you to add
custom attributes to your classes, which will then be used to automatically
generate the manifest for you. Our goal is that 99% of our users should never
need to manually modify AndroidManifest.xml.
AndroidManifest.xml is generated as
part of the build process, and the XML found within Properties/AndroidManifest.xml is merged with xml that is generated from custom attributes. Thes resulting merged Manifest file resides in the Obj Sub directory.
For Example: It resides at obj/Debug/android/AndroidManifest.xml for debug builds.
Manifest file for an android application is
a resource file which contains all the details needed by the android system
about the application. It is a key file that works as a bridge between the
android developer and the android platform. It helps the developer to pass on
functionality and requirements of our application to Android. This is an xml
file which must be named as AndroidManifest.xml and placed at application root.
Every Android app must have AndroidManifest.xml file. AndroidManifest.xml
allows us to define.
Below is the only skeleton of the manifest file:
<?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>
We can use all the properties according to our project requirement.
In Details the structure of the manifest:
<manifest>:
manifest is the root element of the AndroidManifest.xml file. It has package attribute
that describes the package name of the activity class.
<manifest xmlns:android=http:
//schemas.android.com/apk/res/android
package
=
"com.simpledeveloper.blog_app"
>;
[ ...manifest nodes... ]
<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.
<application android:icon=
"@drawable/icon"
<android:theme=
"@style/my_theme"
>;
[... application nodes ... ]
</application>
<activity>:
activity is the subelement of application and represents an activity
that must be defined in the AndroidManifest.xml file. It has many attributes
such as label, name, theme, launchMode etc.
android:label represents a label i.e. displayed on the screen.
android:name represents a name for the activity class. It is required
attribute.
<activity android:name=
".MyActivity"
android:label=
"@string/app_name"
>
<intent -filter>
<action android:name=
"android.intent.action.MAIN"
></action>
<category android:name=
"android.intent.category.LAUNCHER"
></category>
</intent>
</activity>
<intent-filter>
intent-filter is the sub-element of activity that describes the type of
intent to which activity, service or broadcast receiver can respond to.
<action>:
It adds an action for the intent-filter. The intent-filter must
have at least one action element.
<category>:
It adds a category name to an intent-filter.
Defining Following Properties in manifest file:
Provider:
provider – provider tags are used
for each of your application’s Content Providers. Content Providers
are used to manage database access and sharing within and between applications.
<provider android:permission=
"com.simpledeveloper.MY_PERMISSION"
android:name=
".MyContentProvider"
android:enabled=
"true"
android:authorities=
"com.simpledeveloper.blog_app.MyContentProvider"
>
</provider>
Service:
service – Just like the
activity tag, you must create a new service for each Service class
used inside your application. Service tags also
support intent-filter child tags to allow late runtime binding.
<service android:enabled=
"true"
android:name=
"MyServices"></service
Receivers:
receiver – You can register
a Broadcast Receiver by adding a receiver tag without having to
launch your application first. Broadcast Receivers are more like global event
listeners – once registered, they will execute whenever a matching Intent is
broadcast by an application.
<receiver android:enabled=
"true"
android:label=
"My Broadcast Receiver"
android:name=
".MyBroadcastReceiver"
</receiver>
use permissions:
uses-permission – this is part of the
security model. It declares permissions you have determined that your
application needs to operate properly. The permissions you include will always
be presented to the user to either grant or deny during installation. Many
native android services require permissions for example those that have cost or
security implications.
<uses -permission android:name=
"android.permission.ACCESS_LOCATION"
>
</uses>
permissions:
permission – You need to define a permission in
the android application manifest file before restricting access to any
application component. Use the permission tag to create the
permission definitions. The application components can then require them by
adding the android:permission attribute. Other apps will then
need to include a uses-permission tag in their manifest file
and have it granted before they can use these protected components.
Within the permission tag you can specify
the level of access the permission will permit( normal, dangerous, signature,
signatureOrSystem), a label, and an external resource containing the
description that explains the risks of granting this permission.
<permission android:name=
"com.simpledeveloper.DETONATE_DEVICE"
android:protectionLevel=
"dangerous"
android:label=
"Self Destruct"
android:description=
"@string/detonate_description"
</permission>
NOTE: Very Rarely used this Property:
Instrumentation:
instrumentation – Instrumentation
classes provide a framework for running tests on your Activities and Services
at run time. They simply provide hooks to monitor your application and its
interaction with the system resources. You must create a new node for each of
the test classes you have created in your application.
<instrumentation android:label=
"My Test"
android:name=
".MyTestClass"
android:targetPackage=
"com.simpledeveloper.aPackage"
>
</instrumentation>
Final Code For Android Manifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.basiccontactables" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.READ_CONTACTS"/> <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <permission android:name="android"></permission> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/Theme.Sample" > <activity android:name="com.example.android.basiccontactables.MainActivity" android:label="@string/app_name" android:launchMode="singleTop"> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
No comments:
Post a Comment