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

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

这是我的带有 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 以外的其他电子邮件应用程序中运行?

最佳答案

根据文档,您需要将 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 }

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

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

关于android - 如何在不需要 gmail 的情况下从电子邮件链接到 Android 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31062187/

相关文章:

android - 不同应用程序调用时 "Generating New Processes"出现问题?

javascript - 创建移动的文本装饰

javascript - 阻止聊天消息从 MySQL 服务器发送后在浏览器中执行脚本?

c# - Qt 4.7 QRegExp 电子邮件地址验证

php - 使用从数据库中选择的不同数据发送组邮件

javascript - 使用 linkedin API javascript SDK 获取电子邮件地址

java - 连接到服务器中的 ms sql 数据库

android - 使用 android opencv 和 javacv 制作全景图

jquery - 从链接弹出div

android - 将新字体粘贴到 Android Studio 中的 Assets 文件夹时,文件以错误的编码 'UTF-8' 加载