[英]Unable to get Android App Link to work in an Android app written in Flutter
I am trying to implement Moneris hosted pay page from a flutter mobile app but this question is relevant to any app that wants to implement Android App Links .我正在尝试从 flutter 移动应用程序实现 Moneris 托管的支付页面,但这个问题与任何想要实现 Android App Links 的应用程序有关。 In order to redirect back from the hosted pay page, I need to implement Android App Link (haven't gotten to do iOS version yet).为了从托管支付页面重定向回来,我需要实现 Android 应用链接(还没有做 iOS 版本)。 Based on this article, in order for App Links to work, one needs:根据 这篇文章,为了使 App Links 工作,需要:
For #1, I have identified 2 URLs, one for approved payments ( https://example.com/moneris_approved ) and one for declined payments ( https://example.com/moneris_declined ).对于 #1,我确定了 2 个 URL,一个用于已批准的付款( https://example.com/moneris_approved ),一个用于拒绝付款( https://example.com/moneris_declined )。 URLs have to be in https for the whole thing to work. URL 必须在 https 中才能使整个工作正常进行。 Moneris can reply with a POST with XML, POST with parms or GET with parms. Moneris 可以使用带有 XML 的 POST、带有 parms 的 POST 或带有 parms 的 GET 回复。 Tried all three.三个都试过了。
For #2, I have modified AndroidManifest.xml both by hand and with help of Android Studio.对于 #2,我手动修改了 AndroidManifest.xml,并在 Android Studio 的帮助下进行了修改。 Relevant pieces look like this:相关部分如下所示:
<application
android:name="io.flutter.app.FlutterApplication"
android:label="<label>"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
...
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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"
android:pathPattern="/moneris_approved" />
</intent-filter>
<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"
android:pathPattern="/moneris_declined" />
</intent-filter>
</activity>
</application>
For #3, I am using uni_links package which takes care of channeling incoming App Links to my app.对于#3,我使用 uni_links package 负责将传入的应用链接引导到我的应用。
For #4, I have created and uploaded the assetlinks.json file and placed in the right folder.对于#4,我创建并上传了assetlinks.json 文件并放置在正确的文件夹中。 Included both debug and release SHA256 fingerprints.包括调试和发布 SHA256 指纹。 The file looks like this:该文件如下所示:
[
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.example.<name>",
"sha256_cert_fingerprints":
["........"]
}
}
]
Now, after doing all that, when Moneris redirects to provided URLs, I am seeing a 404 page coming from my hosting site.现在,在完成所有这些之后,当 Moneris 重定向到提供的 URL 时,我看到来自我的托管站点的 404 页面。
To verify the setup, I have:为了验证设置,我有:
At this point, I don't know how else to test it or what the problem is.在这一点上,我不知道如何测试它或问题是什么。 I don't think the problem is with my app but rather soemthing is not closing the loop between Moneris redirect and it coming back to my app.我不认为问题出在我的应用程序上,而是某些东西没有关闭 Moneris 重定向和它返回到我的应用程序之间的循环。
I devised a testing approach like this:我设计了一个这样的测试方法:
So now my question is: what is the difference between me clicking on a link on my page (HTTP GET) vs. Moneris redirecting to the same link using HTTP GET?所以现在我的问题是:我点击页面上的链接(HTTP GET)与 Moneris 使用 HTTP GET 重定向到同一链接有什么区别? Me clicking on the link works.我点击链接有效。 Moneris redirect does not. Moneris 重定向没有。
thanks for clarification.感谢您的澄清。 Unfortunately, Moneris only supports http and https schemas so using com.googleusercontent.apps as schema will not work for me.不幸的是,Moneris 仅支持 http 和 https 架构,因此使用 com.googleusercontent.apps 作为架构对我不起作用。 And while I get that it works for you, your implementation contradicts my understanding of how Android App Links should work虽然我知道它对你有用,但你的实现与我对 Android App Links 应该如何工作的理解相矛盾
Failed to lanch the app after Redirect重定向后无法启动应用
=> (1) App (lanch browser) => (1) 应用程序(浏览器)
==> (2) browser ( Moneris.com) ==> (2) 浏览器 (Moneris.com)
===> (3) browser (redirct to example.com) ===> (3) 浏览器(重定向到 example.com)
=====> (4) browser (404 page)❌ =====>(4)浏览器(404页面)❌
======> (5) failed because the app is not launched❌ ======> (5) 应用未启动失败❌
because you used a real domain schema因为您使用了真实的域模式
the browser used the DNS not ask the OS to lanch the app浏览器使用 DNS 不要求操作系统启动应用程序
String returnUrl =
"com.googleusercontent.apps.932931520452-buv2dnhgo7jjjjv5fckqltn367psbrlb:/approved)";
String cancelUrl =
"com.googleusercontent.apps.932931520452-buv2dnhgo7jjjjv5fckqltn367psbrlb:/declined)";
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.e042_flutter_paypal_f">
<application android:name="io.flutter.app.FlutterApplication" android:label="e042_flutter_paypal_f" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
<meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:value="true" />
<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" />
<!-- Custom Path data -->
<data android:path="/auth" android:scheme="com.googleusercontent.apps.932931520452-buv2dnhgo7jjjjv5fckqltn367psbrlb"/>
</intent-filter>
</activity>
</application>
</manifest>
Create Deep Links to App Content | 创建指向应用内容的深层链接 | Android Developers Android 开发人员
android - Intent filter using path,pathPrefix, or pathPattern - Stack Overflow android - 使用路径、pathPrefix 或 pathPattern 的意图过滤器 - Thinbug
manifest data-element Android Developers 清单数据元素 Android 开发人员
Android deep links not following path prefix - Stack Overflow Android 深层链接不遵循路径前缀 - Thinbug
I can see that you want to handle deep link right in the flutter code.我可以看到您想在 flutter 代码中处理深层链接。 That is possible but you have to use one of the libraries for that - for example this .这是可能的,但您必须为此使用其中一个库 - 例如this 。
If you want to do it by yourself you have to create a platform specific Method Channels for that.如果你想自己做,你必须为此创建一个特定于平台的方法通道。 This answer shows how to do it.这个答案显示了如何做到这一点。
Also you can find a more detailed explanation here你也可以在这里找到更详细的解释
Hope it helps.希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.