androidManifestIntentFilterSample function

String androidManifestIntentFilterSample({
  1. required String domain,
  2. String? scheme,
})

Sample for AndroidManifest.xml intent-filter

Implementation

String androidManifestIntentFilterSample({
  required String domain,
  String? scheme,
}) {
  final List<String> intentFilters = [];

  // Add App Links intent filter if domain is provided
  if (domain.isNotEmpty) {
    intentFilters.add('''
            <!-- App Links -->
            <intent-filter android:autoVerify="true">
                <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="$domain" />
                <data android:scheme="https" android:host="$domain" />
            </intent-filter>''');
  }

  // Add Custom Scheme intent filter if scheme is provided
  if (scheme != null && scheme.isNotEmpty) {
    intentFilters.add('''
            <!-- Custom URL Scheme -->
            <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="$scheme" />
            </intent-filter>''');
  }

  return intentFilters.join('\n');
}