如何在不需要 gmail 的情况下从电子邮件 link 到 Android 应用程序?

How can I link to an Android app from an email without the need of gmail?

我想从电子邮件 link 我的应用程序(使用 Xamarin Android 制作)。这行得通。当我在 gmail 中打开 link 时,应用程序确实打开了。然而,当使用另一个众所周知的邮件客户端(例如 Outlook 或 Android Email)时,情况就不同了。它尝试浏览到 link 而不是打开我的应用程序。

这是我的html(邮件):

    <a href="http://testje1.mywebdomain.net" style="text-decoration:none;color:#fff;background-color:#5bc0de;border-color:#46b8da;display:inline-block;padding:6px 12px;margin-bottom:0;font-size:14px;font-weight:400;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid transparent;border-radius:4px"

  role="button">HTTP</a>
<a href="ftp://testje2.mywebdomain.net" style="text-decoration:none;color:#fff;background-color:#5bc0de;border-color:#46b8da;display:inline-block;padding:6px 12px;margin-bottom:0;font-size:14px;font-weight:400;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid transparent;border-radius:4px"

  role="button">FTP</a>
<a href="doe://testje3.mywebdomain.net" style="text-decoration:none;color:#fff;background-color:#5bc0de;border-color:#46b8da;display:inline-block;padding:6px 12px;margin-bottom:0;font-size:14px;font-weight:400;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid transparent;border-radius:4px"

  role="button">doe</a>

在 gmail 中,"ftp" link 直接 link 发送到我的应用程序。 "http" link 询问是否需要打开我的浏览器或我的应用程序。 "doe" link 不起作用(没问题)。

这是我的带有意图过滤器的 C# 代码:

[Activity(Label = "MultiLinks", MainLauncher = true, Icon = "@drawable/icon")]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
DataScheme = "http",
DataHost = "testje1.mywebdomain.net",
Categories = new[] { Android.Content.Intent.CategoryDefault })]
public class MainActivity : Activity

[Activity(Label = "SecondActivity")]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
DataScheme = "ftp",
DataHost = "testje2.mywebdomain.net",
Categories = new[] { Android.Content.Intent.CategoryDefault })]
public class SecondActivity : Activity

[Activity(Label = "ThirdActivity")]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
DataScheme = "doe",
DataHost = "testje3.mywebdomain.net",
Categories = new[] { Android.Content.Intent.CategoryDefault })]
public class ThirdActivity : Activity

如何从电子邮件 link 我的应用程序并使其在 Gmail 以外的其他电子邮件应用程序中运行?

根据文档,如果您希望网络浏览器能够启动您的应用程序,您需要将 Browsable Category 添加到 IntentFilter

https://developer.android.com/training/app-indexing/deep-linking.html#adding-filters

Include the BROWSABLE category. The BROWSABLE category is required in order for the intent filter to be accessible from a web browser. Without it, clicking a link in a browser cannot resolve to your app. The DEFAULT category is optional, but recommended. Without this category, the activity can be started only with an explicit intent, using your app component name.

因此您的类别应该如下所示:

Categories = new[] { Android.Content.Intent.CategoryDefault,
     Android.Content.Intent.CategoryBrowsable }

所以当另一个客户端启动网络浏览器时,网络浏览器应该能够发现 link 实际上属于已安装的应用程序。

Chrome 浏览器还支持特殊的 url 可以直接启动 Intent 或者如果 Intent 不存在则显示 Play 商店页面设备。

它可能看起来像:

intent://myApp/#Intent;scheme=myScheme;package=my.awesome.package.name;S.browser_fallback_url=http%3A%2F%2Fmyapp.com;end

更多相关信息:https://developer.chrome.com/multidevice/android/intents