【问题标题】:How can I link to an Android app from an email without the need of gmail?如何在不需要 gmail 的情况下从电子邮件链接到 Android 应用程序?
【发布时间】:2015-09-12 18:12:42
【问题描述】:

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

这是我的 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”链接直接链接到我的应用。 “http”链接询问是否需要打开我的浏览器或我的应用程序。 “doe”链接不起作用(没问题)。

这是我的带有意图过滤器的 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

如何从电子邮件链接到我的应用并使其在 Gmail 以外的其他电子邮件应用中运行?

【问题讨论】:

    标签: android html email xamarin xamarin.android


    【解决方案1】:

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

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

    包括 BROWSABLE 类别。 BROWSABLE 类别是必需的 为了使意图过滤器可以从网络浏览器访问。 没有它,单击浏览器中的链接将无法解析您的应用程序。 DEFAULT 类别是可选的,但建议使用。没有这个 类别,活动只能以明确的意图启动, 使用您的应用组件名称。

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

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

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

    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

    【讨论】:

    • 确实需要可浏览的类别并解决了问题。 chrome Android Intents 没有用。这些链接在 Android 电子邮件应用程序和 Outlook 应用程序中有效,但在 Gmail 应用程序中无效。 FTP 链接更有效。如果应用程序可用,则打开应用程序而不要求用户打开浏览器。如果应该问这个,http链接是好的。
    猜你喜欢
    • 2014-10-10
    • 2021-05-19
    • 2021-06-24
    • 2011-09-10
    • 2016-11-05
    • 2019-02-10
    • 1970-01-01
    • 2012-02-04
    • 1970-01-01
    相关资源
    最近更新 更多