[英]I need to add a href inside a body for a gmail intent. Works on Android 4.3 but not on 6/7
我有以下代碼:
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..."));
這就是正文字符串的樣子:
<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>
在 Gmail 中,href 不起作用,因此我無法按任何內容。 我在這里做錯了什么?
編輯:更改為 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..."));
現在我得到了這個回應,但仍然無法正常工作:
PS:我在 android 4.3 上試過它可以工作,但從 Android 5 開始它不再工作了。 任何想法?
嘗試將類型從plain/text
更改為text/html
編輯:也不要使用Html.fromHtml
因為這會Html.fromHtml
你的HTML
標簽!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.