How to send email with link to open Android application(如何发送带有链接的电子邮件以打开 Android 应用程序)
问题描述
我创建了一些代码,可以通过电子邮件将 html 电子邮件发送到给定地址.该电子邮件包含如下链接:
I have created some code that emails an html email to a given address. The email contains a link like the following:
<a href="crystalcloud://android?4567">Click to validate account</a>
我通过将它发送到我的 gmail 帐户来测试它.出于某种原因,当我收到电子邮件时,它不会让我点击链接.如果我将此链接放在网页中,我的应用程序可以正常启动.
I was testing this by sending it to my gmail account. For some reason, when I receive the email, it will not let me click on the link. If I put this link in a web page, my application starts up fine.
我是否需要做一些特别的事情才能让这个链接出现在电子邮件中,或者去 gmail 只是阻止这些链接?有没有办法在 gmail 中解决这个问题?
Is there something special I have to do to get this link to show up in an email, or goes gmail just block these kind of links? Is there anyway to get around this issue in gmail?
添加了我的代码片段
发送链接的代码:
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailAddress));
message.setSubject("New Crystal Cloud User");
message.setContent("Thank you for creating a new Crystal Cloud account!<br><a href="crystalcloud://android?4567">Click to validate account</a>", "text/html; charset=utf-8");
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
响应意图的 Android 代码:
Android code to respond to intent:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="crystalcloud" />
</intent-filter>
推荐答案
这是 android 电子邮件客户端的问题,除非它们是 http 或 https,否则它们不会将链接显示为可点击.
This is a problem with the android email clients that they don't show links as clickable unless they are http or https.
我的解决方案是使用 http 方案来打开我的应用:
My solution was to use a http scheme to open my app:
<data android:scheme="http" android:host="com.company.app" android:port="3513" />
这很有效,但很烦人,因为它会提示用户在浏览器或您的应用程序中打开应用程序.另一种解决方案是有一个网站链接,然后将 javascript 重定向到您的应用程序,尽管这可能会导致更多问题.
This works but in annoying because it prompts the user to open the app in either the browser or your application. Another solution is to have a link to a website that then does a javascript redirect to your app though this can cause more problems.
这篇关于如何发送带有链接的电子邮件以打开 Android 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何发送带有链接的电子邮件以打开 Android 应用程序
基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
