简体   繁体   English

我需要在正文中为 gmail 意图添加一个 href。 适用于 Android 4.3 但不适用于 6/7

[英]I need to add a href inside a body for a gmail intent. Works on Android 4.3 but not on 6/7

I have the following code:我有以下代码:

Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{user.getEmail()});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Passenger Excel/CSV");
String body = " <html> <body> <p>" + getString(R.string.reports_send_email_body) + "</p><a href=\"" + key + "\">XLS</a>" + "\n <p>or</p> \n" + "<a href=\"" + key2 + "\">CSV</a></body></html>");
Log.i("","body is: " + Html.fromHtml(body));
Log.i("","body is: " + body);
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
getActivity().startActivity(Intent.createChooser(emailIntent, "Reports link..."));

And This is what the body string looks like:这就是正文字符串的样子:

 <html> <body> <p>Download your Passenger report here:
 <a href="https://staging.api.psngr.co/api/v2/users/110/trips?start_date=1483228800&end_date=1485907199&format=csv&hmac=1.KqXdqdatvtwLlgXYfDX3fF2vB-k=">CSV</a>
 </body></html>

And in Gmail the href do not work, so I cannot press on anything.在 Gmail 中,href 不起作用,因此我无法按任何内容。 What am I doing wrong here?我在这里做错了什么?

EDIT: Changed to text/html, like this:编辑:更改为 text/html,如下所示:

Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{user.getEmail()});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Passenger Excel/CSV");
String body = " <html> <body> <p>" + getString(R.string.reports_send_email_body) + "</p><a href=\"" + key + "\">XLS</a>" + "\n <p>or</p> \n" + "<a href=\"" + key2 + "\">CSV</a></body></html>";
Log.i("","body is: " + body);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
getActivity().startActivity(Intent.createChooser(emailIntent, "Reports link..."));

And now I get this response, still not working:现在我得到了这个回应,但仍然无法正常工作:

在此处输入图片说明

PS: I tried on android 4.3 and it works, but starting with Android 5 it doesn't work anymore. PS:我在 android 4.3 上试过它可以工作,但从 Android 5 开始它不再工作了。 any ideeas?任何想法?

Try changing your type from plain/text to text/html尝试将类型从plain/text更改为text/html

Edit: also don't use Html.fromHtml as that will strip out your HTML tags!编辑:也不要使用Html.fromHtml因为这会Html.fromHtml你的HTML标签!

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

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