Essential Elements of the Android Manifest File: grant-uri-permission, instrumentation, intent-filter, manifest, and meta-data
The <grant-uri-permission> Element
Syntax
<grant-uri-permission android:path="string"
android:pathPattern="string"
android:pathPrefix="string" />
Contained Within
<provider>
Description
Defines a subset of application data within the parent content provider that can be accessed by clients. The data subset is identified by the path portion of a content: URI (the authority portion identifies the provider). This allows temporary access for clients that normally lack permissions.
When the provider's grantUriPermissions attribute is "true", permissions can be granted for any of its data. If set to "false", permissions can only be granted for the specific data subsets declared by this element. A provider may contain multiple <grant-uri-permission> elements. Each element specifies a single path using only one of its three attributes.
Key Attributes
android:path- Specifies a complete path. Permission is granted only for the exact data subset identified by this path.
android:pathPrefix- Specifies the initial segment of a path. Permission is granted for all data subsets sharing this prefix.
android:pathPattern- Specifies a full path but allows wildcards:
- An asterisk (
*) matches zero or more occurrences of the preceding character. - A period followed by an asterisk (
.*) matches any sequence of zero or more characters.
- An asterisk (
- Because
\serves as an escape character in XML, you must double-escape: a literal*is writtten as\\*, and a literal\is written as\\\\.
- Specifies a full path but allows wildcards:
The <instrumentation> Element
Syntax
<instrumentation android:functionalTest=["true" | "false"]
android:handleProfiling=["true" | "false"]
android:icon="drawable_resource"
android:label="string_resource"
android:name="string"
android:targetPackage="string"
android:targetProcesses="string" />
Contained Within
<manifest>
Description
Declares an Instrumentation class for monitoring an application's interaction with the system. This object is instantiated before any of the app's components.
Key Attributes
android:functionalTest- Indicates if the instrumentation class should run as a functional test. Default is
"false".
- Indicates if the instrumentation class should run as a functional test. Default is
android:handleProfiling- Indicates if the instrumentation object controls profiling start/stop (
"true"), or if profiling runs continuously ("false"). Default is"false".
- Indicates if the instrumentation object controls profiling start/stop (
android:icon- An icon representing the instrumentation class. Must reference a drawable resource.
android:label- A user-readable label for the class. Can be a raw string or a string resource reference.
android:name- The fully-qualified class name of the
Instrumentationsubclass (e.g.,com.example.app.TestRunner). If the first character is a dot, it is appended to the package name from the<manifest>element. Required.
- The fully-qualified class name of the
android:targetPackage- The package name of the application the instrumentation will run against.
android:targetProcesses- A comma-separated list of process names, or
"*"for all processes of the target application. If omitted, instrumentation runs only against the main process. (Introduced in API level 26).
- A comma-separated list of process names, or
The <intent-filter> Element
Syntax
<intent-filter android:icon="drawable_resource"
android:label="string_resource"
android:priority="integer"
android:order="integer" >
...
</intent-filter>
Contained Within
<activity>,<activity-alias>,<service>,<receiver>
Must Contain
<action>
May Contain
<category><data>
Description
Specifies the types of intents an Activity, Service, or Broadcast Receiver can respond to. It declares the component's capabilities, allowing it to receive meaningful intents while filtering others. The filter's behavior is primarily defined by its <action>, <category>, and <data> sub-elements.
Key Attributes
android:icon- An icon representing the component when presented with the filter's capabilities. References a drawable resource. Defaults to the parent component's icon, or the application's icon.
android:label- A user-readable label for the component when presented with the filter's capabilities. Should be a string resource reference. Defaults to the parent component's label, or the application's label.
android:priority- The priority for handling intents matching this filter. Affects Activity selection and broadcast receiver execution order. Higher values indicate higher priority. Default is
0. System restrictions may apply for non-privileged apps.
- The priority for handling intents matching this filter. Affects Activity selection and broadcast receiver execution order. Higher values indicate higher priority. Default is
android:order- The order for processing multiple matching filters within the same application. Higher values are processed first. Default is
0. (Introduced in API level 28).
- The order for processing multiple matching filters within the same application. Higher values are processed first. Default is
The <manifest> Element
Syntax
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="string"
android:sharedUserId="string"
android:sharedUserLabel="string_resource"
android:versionCode="integer"
android:versionName="string"
android:installLocation=["auto" | "internalOnly" | "preferExternal"]
android:targetSandboxVersion="integer">
...
</manifest>
Contains
<application>(required)- May also contain elements like
<uses-permission>,<uses-sdk>,<instrumentation>, etc.
Description
The root element of the AndroidManifest.xml file. It must include the <application> element and define the xmlns:android and package attributes.
Key Attributes
xmlns:android- Defines the Android namespace. Must be
"http://schemas.android.com/apk/res/android".
- Defines the Android namespace. Must be
package- The app's fully-qualified Java-style package name. This serves as the namespace for the generated
Rclass and is used to resolve relative class names in the manifest. It also represents the default process name and task affinity.
- The app's fully-qualified Java-style package name. This serves as the namespace for the generated
android:versionCode- An internal integer version number used for version comparison (higher numbers are newer). Not displayed to users.
android:versionName- The version string displayed to users (e.g., "1.2.3"). Can be a raw string or a string resource.
android:installLocation- The app's default installation location. Values:
"internalOnly": Install only on internal storage (default)."auto": Prefer internal storage, but use external if internal is full."preferExternal": Prefer external storage (SD card).
- The app's default installation location. Values:
android:sharedUserId/android:sharedUserLabel- (Deprecated) Allows apps with identical certificates to share a Linux user ID and access each other's data.
android:targetSandboxVersion- The security sandbox level. Default is
1. Setting to2enables a stricter SELinux sandbox with limitations like default cleartext traffic blocking. Required to be2for Android Instant Apps targeting API 26+.
- The security sandbox level. Default is
The <meta-data> Element
Syntax
<meta-data android:name="string"
android:resource="resource_specification"
android:value="string" />
Contained Within
<activity>,<activity-alias>,<application>,<provider>,<receiver>,<service>
Description
Provides a name-value pair of arbitrary supplemental data to its parent component. Multiple <meta-data> elements can be added. Their values are collected into a Bundle accessible via PackageItemInfo.metaData.
Key Attributes
android:name- A unique name for the item (e.g., using Java-style naming like
"com.example.app.config").
- A unique name for the item (e.g., using Java-style naming like
android:value- The value assigned to the item. The data type is inferred, and corresponding
Bundle.get*()methods are used for retrieval (e.g.,getString(),getInt(),getBoolean(),getFloat()).
- The value assigned to the item. The data type is inferred, and corresponding
android:resource- A reference to a resource (e.g.,
@string/app_name). The assigned value is the resource's numeric ID, not the content of the resource, and is retrieved usingBundle.getInt().
- A reference to a resource (e.g.,
For complex data, it is recommended to store it as a resource and reference it via resource, rather than using multiple separate <meta-data> entries.