Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Essential Elements of the Android Manifest File: grant-uri-permission, instrumentation, intent-filter, manifest, and meta-data

Tech 1

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.
    • Because \ serves as an escape character in XML, you must double-escape: a literal * is writtten as \\*, and a literal \ is written as \\\\.

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".
  • android:handleProfiling
    • Indicates if the instrumentation object controls profiling start/stop ("true"), or if profiling runs continuously ("false"). Default is "false".
  • 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 Instrumentation subclass (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.
  • 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).

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.
  • 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 <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".
  • package
    • The app's fully-qualified Java-style package name. This serves as the namespace for the generated R class and is used to resolve relative class names in the manifest. It also represents the default process name and task affinity.
  • 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).
  • 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 to 2 enables a stricter SELinux sandbox with limitations like default cleartext traffic blocking. Required to be 2 for Android Instant Apps targeting API 26+.

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").
  • 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()).
  • 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 using Bundle.getInt().

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.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.