如何在不破坏嵌入图像的情况下从Android发送带有HTML的电子邮件?

时间:2014-02-05 16:49:21

标签: android html android-intent

我试图用HTML格式发送包含一些格式化文本的电子邮件。 此文本有一个指向我的图像的链接,并且不会显示此图像,就像链接被展开一样。我测试了图像的链接,它工作正常。

这是代码:

textoEmail = Html.fromHtml("<img src='https:link to my image'></br></br>Text<br/>Download it: http://Link to my app");


    btEmail.setOnClickListener(new OnClickListener() {          
        @Override
        public void onClick(View v) {
            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            emailIntent.setType("vnd.android.cursor.item/email");               
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Carrorama - Recomendação de aplicativo");
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, textoEmail);                
            try {
                startActivity(emailIntent);
            } catch (ActivityNotFoundException e) {


            }               
        }
    });

1 个答案:

答案 0 :(得分:0)

试试此代码

String body="<!DOCTYPE html><html><body><a href=\"http://www.w3schools.com\" target=\"_blank\">Visit W3Schools.com!</a>" +
                  "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("text/html");           
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);    
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
        startActivity(Intent.createChooser(emailIntent, "Email:"));