本文介绍了如何安装图像中的电子邮件中的Andr​​oid绘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我附上绘制文件夹中的图像和电子邮件发送。
当我从默认的电子邮件client.Image扩展(png格式)发送中缺少附件
并且,也文件名本身改变。
我想吨,默认名称发送图像(如绘制)和png格式的扩展名。

I am attaching an image from drawable folder and sending it in a email.when I send it from default email client.Image extension(.png) is missing in attachmentand and also the file name is changed itself.I want t send image with default name(as in drawable) and with .png extension.

这是我的code。

    Intent email = new Intent(Intent.ACTION_SEND);
            email.setType("image/png");

            email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });

            email.putExtra(Intent.EXTRA_SUBJECT, "Hey! ");


            email.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+ getPackageName() + "/" + R.drawable.ic_launcher));
startActivity(Intent.createChooser(email, "Sending........"));

请建议我什么是这个code拨错
谢谢。

Please suggest me what is worng in this code thanks.

推荐答案

您只能附加一个图像到邮件如果图像位于SD卡。
所以,你需要将图像复制到SD,然后安装它。

You can only attach an image to mail if the image is located in the SDCARD.So, you'll need to copy the image to SD and then attach it.

InputStream in = null;
OutputStream out = null;
try
{
in = getResources().openRawResource(R.raw.ic_launcher);
out = new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "image.png"));
copyFile(in, out);
 in.close();
 in = null;
 out.flush();
out.close();
out = null;
}
catch (Exception e)
                {
                    Log.e("tag", e.getMessage());
                    e.printStackTrace();
                }

private void copyFile(InputStream in, OutputStream out) throws IOException
    {
        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1)
        {
            out.write(buffer, 0, read);
        }
    }


Intent emailIntent = new Intent(Intent.ACTION_SEND);
                emailIntent.setType("text/html");
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "File attached");
                Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "image.png"));
                emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
                startActivity(Intent.createChooser(emailIntent, "Send mail..."));

这篇关于如何安装图像中的电子邮件中的Andr​​oid绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 09:38