Search code examples
androidflutterdeep-linking

In my Flutter project, adding a Browsable category in AndroidManifest.xml makes my app unusable


Recently, I've added the stripe_sdk package to my flutter project. The 3DS system requires to add a deep link mechanism to come back to the app when the 3D is OK or KO.

On iOS, I modified my Info.plist to declare the scheme, it works well when I debug and when I deploy the released version via diawi.

On Android, I modified my android/app/src/main/AndroidManifest.xml to add in intent-filters :

<intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:scheme="myapp"
                    android:host="3ds.myapp.fr" />
                

            </intent-filter>

No compilation issue, when I debug on simulator or device, no problem. The issue appears when I build a release package using flutter build apk, and distribute it via diawi. the apk is well download, installation works also, but at the end of the installation, The "Open" button is not active. The app is not present with others apps. If I go to parameters -> Applications, I can find my app, but the "open" button is also inactive. I can only uninstall my app. PS : The issue is exactly the same if I upload directly my apk without using diawi.

I tried to modify the scheme and host, and the result is always the same : unable to open my app.

If I modify my AndroidManifest.xml to remove the BROWSABLE category and rebuild the package, all becomes OK again. The app can be launched.

What can be the issue ?

Thanks, Luc

My full AndroidManifest.xml :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="fr.myapp">
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="myapp"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />

                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:scheme="myapp"
                    android:host="3ds.myapp.fr" />


            </intent-filter>

        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.INTERNET" />


</manifest>

Solution

  • The standard launcher intent in Android does not include a URI, so it will not match the combined filter.

    An intent that contains neither a URI nor a MIME type passes the test only if the filter does not specify any URIs or MIME types.

    In order to accept both the launcher intent and an ACTION_VIEW intent for your URI scheme, MainActivity will need two intent filters:

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    
    <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="myapp"
            android:host="3ds.myapp.fr" />
                    
    </intent-filter>