1、问题
这段时间我遇到了一个比较奇怪的问题,记录一下。
大家应该都知道在微信浏览器里面是无法直接拉起 APP 的,需要对接微信的开放标签 (wx-open-launch-app) 拉起 APP 。
但是在 Flutter 项目中使用微信开放标签拉起 APP 会跳转进一个 native 白屏界面,只有你返回的时候才会返回到 flutter 的 页面,这就非常的奇奇怪怪。
去各种搜索问啊,发现好像都没有什么解决办法。
一开始怀疑是项目代码有问题,但是我新建一个空白的项目去拉起还是白屏,这就比较难搞了。
2、解决它
但是,功夫只负有心人,还是让我找到解决办法了。
监听 APP 在浏览器中拉起使用的是 uni_links。
就是这个 fluwx 让我找到了最终的答案。
在 fluwx 它的 GitHub 仓库里让我发现了这个 issues。
这个 issues 的下面有个大佬的回答解决了这个问题。他让我们去参考一下 example 配置一下 meta-data 和 intent-filter。
我把这个example 的配置全部拿到新建的空白项目中后,就不会在跳到 native 的白屏界面。
后面就可以继续使用 浏览器拉起的逻辑了。
🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉
附录
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jarvan.fluwx_example">
<!-- 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. -->
<queries>
<intent>
<action android:name="${applicationId}.FlutterActivity" />
</intent>
</queries>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:label="fluwx_example">
<meta-data
android:name="weChatAppId"
android:value="12345678" />
<meta-data
android:name="handleWeChatRequestByFluwx"
android:value="true" />
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:exported="true"
android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="${applicationId}.FlutterActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="${applicationId}"
android:path="/"
android:scheme="wechatextmsg" />
</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>
</manifest>