In Flutter, the AndroidManifest.xml file is crucial for configuring various aspects of your Android application, including permissions, activities, services, receivers, and intent filters. Here’s a list of common uses for AndroidManifest.xml in Flutter applications, along with examples:
- Declaring Activities Activities represent screens in your Android application. You declare activities in AndroidManifest.xml to define their behavior, properties, and how they interact with the system.
Example:
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Explanation:
android:name: Specifies the activity class name.
android:launchMode: Specifies how the activity should be launched.
android:theme: Specifies the theme for the activity.
android:configChanges: Specifies configuration changes the activity can handle without being restarted.
android:hardwareAccelerated: Specifies whether hardware acceleration is enabled for the activity.
android:windowSoftInputMode: Specifies how the window containing the activity responds to input methods.
- Adding Permissions Permissions control access to sensitive device features or data. You declare permissions in AndroidManifest.xml to request access to specific resources or functionalities.
Example:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Explanation:
INTERNET: Allows applications to open network sockets.
ACCESS_NETWORK_STATE: Allows applications to access information about networks.
- Registering Broadcast Receivers Broadcast receivers respond to broadcast announcements from other applications or from the system itself. You declare broadcast receivers in AndroidManifest.xml to define which broadcasts your app listens for and how it responds.
Example:
<receiver
android:name=".MyBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Explanation:
android:name: Specifies the receiver class name.
android:enabled: Specifies whether the receiver is enabled.
android:exported: Specifies whether the receiver is accessible to other apps.
- Defining Services Services are components that run in the background to perform long-running operations or to perform work for remote processes. You declare services in AndroidManifest.xml to define their properties and how they interact with the system.
Example:
<service
android:name=".MyBackgroundService"
android:exported="false">
</service>
Explanation:
android:name: Specifies the service class name.
android:exported: Specifies whether the service is accessible to other apps.
- Configuring Intent Filters Intent filters specify the types of intents that an activity, service, or broadcast receiver can respond to. You declare intent filters in AndroidManifest.xml to define how your app handles incoming intents.
Example (Activity with Intent Filter):
<activity
android:name=".DeepLinkActivity"
android:label="@string/deep_link_activity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="example.com"
android:pathPrefix="/deep-link" />
</intent-filter>
</activity>
Top comments (0)