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

时间:2015-06-25 22:56:51

标签: android html email xamarin xamarin.android

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

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

以下是带有intent过滤器的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?

1 个答案:

答案 0 :(得分:1)

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

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

  

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

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

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

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

Chrome浏览器还支持特殊网址,如果设备上没有Intent,则可以直接启动Intent或显示播放商店页面。

它可能看起来像:

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