什么是可能的办法,通过电子邮件在发送机器人形象?(what are the possible way

2019-10-23 04:27发布

我使用下面的代码来发送HTML格式Android中发送电子邮件; 现在我想用它发送图片。

   private void friends_email_share() {

    Log.i("Send email", "");
    String mail_body = "<!DOCTYPE html><html><body>\n" +
            "    <p>Hi,</p>\n" +
            "    <p>Lorem Ipsum <b>Lorem Ipsum Lorem Ipsum Lorem IpsumLorem </b> Lorem IpsumLorem  Ipsum</p>\n" +
            "    <p>Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum.</p>\n" +
            "    <p>Lorem IpsumLorem  IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum.</p>\n" +
            "    <p>Lorem IpsumLorem  IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum.</p>\n" +
            "    <p>Lorem IpsumLorem IpsumLorem IpsumLorem  IpsumLorem IpsumLorem Ipsum.</p>\n" +
            "</body></html>";
    String[] TO = {};
    String[] CC = {};
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.setType("text/html");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
    emailIntent.putExtra(Intent.EXTRA_CC, CC);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Extra Subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "" + "\n" + Html.fromHtml(mail_body));
    try {
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
        //getActivity().finish();
        Log.i("-->", "Finished sending email...");
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(getApplicationContext(), "There is no email client installed.", Toast.LENGTH_SHORT).show();
    }

什么是可能的办法,通过电子邮件在android系统发送图片?

我需要一个严重的帮助这里,谢谢....

Answer 1:

这可以帮助你..

尝试{

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);  
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "android@abcxyz.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Emergency");         
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://"+ path + "/" + image_name));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Please Find Attachments");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
} catch (Throwable t) {
    Toast.makeText(MainActivity.this, "Request failed: " + t.toString(),Toast.LENGTH_LONG).show();
}

}



Answer 2:

你可以找到答案在这里 。

关于你的问题,你可以在资产文件夹这样的附件添加的图像:

 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("application/image");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "Text text");
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"This is email subject");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is extra text");
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///android_asset/allimages/demoImage.jpg"));
    startActivity(Intent.createChooser(emailIntent, "Send mail..."));

希望这可以帮助。



文章来源: what are the possible ways to send image via email in android?