简体   繁体   中英

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. What am I doing wrong here?

EDIT: Changed to text/html, like this:

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. any ideeas?

Try changing your type from plain/text to text/html

Edit: also don't use Html.fromHtml as that will strip out your HTML tags!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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