繁体   English   中英

如何在不需要gmail的情况下通过电子邮件链接到Android应用?

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

我想通过电子邮件链接到我的应用程序(由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中,“ 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以外的其他电子邮件应用程序中运行?

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

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

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

因此,您的类别应类似于:

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

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

Chrome浏览器还支持特殊的url,这些URL可以直接启动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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM