AndroidManifest.xml Key Functions
Permission Management
Example: Requesting internet access in an Android app.
Code:
<uses-permission android:name="android.permission.INTERNET" />
Explanation: This line in the AndroidManifest.xml
file grants the app permission to access the internet. It ensures that the app can make network requests, which is critical for features like fetching data from web APIs. Users are informed of this permission when they install the app, promoting transparency and security.
Component Configuration
Example: Declaring an activity in the manifest.
Code:
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Explanation: This snippet defines the MainActivity
of the app, marking it as the entry point (launcher activity) when the app starts. The android:exported
attribute specifies whether the activity can be launched by components of other apps, impacting how the app interacts with external systems.
Advanced Application Settings
Example: Managing memory usage with a large heap.
Code:
<application
android:largeHeap="true">
</application>
Explanation: Setting android:largeHeap="true"
in the application tag allows the app to request a larger heap size from the Android system. This can be necessary for apps that handle large amounts of data or perform memory-intensive operations, ensuring better performance and stability.
Intent Handling and Queries
Example: Specifying which intents the app can handle.
Code:
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>
Explanation: This section of the manifest declares that the app can handle intents for viewing URLs (android.intent.action.VIEW
) with the https
scheme. It allows the app to be recognized by the system as capable of opening web links, integrating it with the broader Android ecosystem.
Tooling and Compatibility
Example: Targeting a specific API level and handling back navigation.
Code:
<application
tools:targetApi="tiramisu"
android:enableOnBackInvokedCallback="true">
</application>
Explanation: The tools:targetApi="tiramisu"
attribute ensures the app is optimized for Android 13 (Tiramisu), while android:enableOnBackInvokedCallback="true"
enables advanced back navigation behavior introduced in Android 13. These settings help maintain compatibility and ensure the app takes full advantage of the latest Android features.
Complete Example Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>
<application
android:name=".ReaderApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Twine.App"
android:allowBackup="false"
android:fullBackupContent="false"
android:dataExtractionRules="@xml/data_extraction_rules"
android:enableOnBackInvokedCallback="true"
tools:targetApi="tiramisu"
android:largeHeap="true">
<meta-data android:name="com.bugsnag.android.API_KEY"
android:value="${BUGSNAG_API_KEY}"/>
<activity
android:name="dev.sasikanth.rss.reader.MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<!-- If you are using androidx.startup to initialize other components -->
<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />
</provider>
</application>
</manifest>