android - 在我的 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>
解决方案
Android 中的标准启动器 Intent 不包含 URI,因此它不会匹配组合的 filter。
仅当过滤器未指定任何 URI 或 MIME 类型时,既不包含 URI 也不包含 MIME 类型的意图通过测试。
为了同时接受启动器意图和ACTION_VIEW
URI 方案的意图,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>
推荐阅读
- r - 修复了通过 ip 检查器网站 (html+table) 从 ip 列表获取城市信息到数据框的错误
- javascript - 响应式表单中具有动态表单数组的动态表单字段
- c# - 可以启动进程,最小化窗口,点击打开相同的窗口进程?
- javascript - 可以使用 JavaScript 检测浏览器内容解密模块 (CDM) 版本吗?
- python - JupyterHub - xdg-open:没有可用于打开的方法
- c++ - MatrixBase和SparseMatrixBase的隐式模板推导(Eigen C++)
- excel - 具有多个条件的 vlookup
- bash - Heroku CLI 显示 - bash: shell: command not found
- java - 更新 AEM 6.4 到 6.5 之间的依赖关系后,单元测试日志级别更改为 DEBUG
- python - 使用自动检测将动态架构 JSON 文件加载到 BigQuery 表中