首页 > 解决方案 > 在我的 Flutter 项目中,在 AndroidManifest.xml 中添加 Browsable 类别会使我的应用无法使用

问题描述

最近,我在我的 Flutter 项目中添加了 stripe_sdk 包。3DS 系统需要添加深度链接机制,以便在 3D OK 或 KO 时返回 App。

在 iOS 上,我修改了我的 Info.plist 以声明该方案,它在我调试和通过 diawi 部署发布版本时运行良好。

在 Android 上,我修改了我的 android/app/src/main/AndroidManifest.xml 以添加 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>

没有编译问题,当我在模拟器或设备上调试时,没问题。当我使用颤振构建 apk 构建发布包并通过 diawi 分发它时,会出现此问题。该apk很好下载,安装也可以,但是在安装结束时,“打开”按钮未激活。该应用程序不存在于其他应用程序中。如果我转到参数 -> 应用程序,我可以找到我的应用程序,但“打开”按钮也处于非活动状态。我只能卸载我的应用程序。PS:如果我直接上传我的apk而不使用diawi,问题是完全一样的。

我尝试修改方案和主机,结果总是一样:无法打开我的应用程序。

如果我修改我的 AndroidManifest.xml 以删除 BROWSABLE 类别并重建包,一切都会再次正常。该应用程序可以启动。

可能是什么问题?

谢谢, 卢克

我的完整 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>

标签: androidflutterdeep-linking

解决方案


Android 中的标准启动器 Intent 不包含 URI,因此它不会匹配组合的 filter

仅当过滤器未指定任何 URI 或 MIME 类型时,既不包含 URI 也不包含 MIME 类型的意图通过测试。

为了同时接受启动器意图和ACTION_VIEWURI 方案的意图,MainActivity 将需要两个意图过滤器:

<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>

推荐阅读