Dim*_*imZ 6 android applinks flutter
我试图使用uni_links包让应用程序链接在 Android 上工作一整天,但没有成功。
当我打开链接时,浏览器会打开它而不是启动应用程序。
你可以看我完整的AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<!-- Permissions options for the `storage` group -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- Permissions options for the `camera` group -->
<uses-permission android:name="android.permission.CAMERA"/>
<!-- Permissions options for the `access notification policy` group -->
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY"/>
<application
android:label="example"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
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"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Deep 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="https" android:host="example.com" />
</intent-filter>
</activity>
<!-- Apple Sign In: Set up the Sign in with Apple activity, such that it's callable from the browser-redirect -->
<activity
android:name="com.aboutyou.dart_packages.sign_in_with_apple.SignInWithAppleCallback"
android:exported="true"
>
<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="signinwithapple" />
<data android:path="callback" />
</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>
Run Code Online (Sandbox Code Playgroud)
我替换com.example.app为我的 appID 和example.com我的主机名。我还添加到了我的后端,并且https://developers.google.com/digital-asset-links/tools/generatorassetlinks.json上的测试通过了。
我创建了一个简单的函数来签入main.dart:
Future<void> initUniLinks() async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
final initialLink = await getInitialLink();
print('initialLink');
print(initialLink);
// Parse the link and warn the user, if it is not correct,
// but keep in mind it could be `null`.
// Attach a listener to the stream
_sub = linkStream.listen((String? link) {
// Parse the link and warn the user, if it is not correct
print(link);
}, onError: (err) {
// Handle exception by warning the user their action did not succeed
print('error');
print(err);
});
} on PlatformException catch (err) {
// return?
// Handle exception by warning the user their action did not succeed
print('error');
print(err);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我运行模拟器,从 VSCode 启动应用程序。在这里我可以看到应用程序调用/.well-known/assetlinks.json并成功返回文件内容。
最后我用 CLI 进行测试:
adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://example.com/ping"
Run Code Online (Sandbox Code Playgroud)
该链接是直接使用浏览器而不是应用程序打开的。
我错过了什么或做错了什么?
感谢您的帮助!
我终于让它发挥作用了。我必须在assetlinks.json文件中添加未签名应用程序的指纹(我认为)。部署后必须记住更改/删除它。就我而言,我在 2 个不同的主机名上使用 2 个不同的资产链接,因此这不会成为问题。
我在使用以下命令检查应用程序链接时获得了指纹:
adb shell pm get-app-links com.example.app
Run Code Online (Sandbox Code Playgroud)
如果我犯了错误或者是否有其他方法可以做到这一点,请告诉我!
| 归档时间: |
|
| 查看次数: |
5474 次 |
| 最近记录: |