0

我的应用程序成功发送电子邮件,但是当我尝试附加图像时,代码崩溃是代码片段

        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("message/rfc822");
        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"email address"});
        i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
        i.putExtra(Intent.EXTRA_TEXT   , "body of email");
    //  i.putExtra(Intent.EXTRA_STREAM, R.drawable.pic4);



        try {
            startActivity(Intent.createChooser(i, "Send mail..."));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(EidCards.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }

被注释的行使代码崩溃,请提出出路!

4

2 回答 2

1

这对您不起作用:

i.putExtra(Intent.EXTRA_STREAM, R.drawable.pic4);

R.drawable.pic4 的类型是什么?那不是用于解析可绘制对象的整数吗?

查看其他人如何附加图片: 使用 Intent.ACTION_SEND 和 Intent.EXTRA_STREAM 与 Google+ 应用共享图片

于 2012-08-10T10:30:02.400 回答
1

好吧,这很简单:P

Intent i = new Intent(Intent.ACTION_SEND);

        int imageURI=R.drawable.pic4;

        i.setType("message/rfc822");
        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"email address"});
        i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
        i.putExtra(Intent.EXTRA_TEXT   , "body of email");
        i.putExtra(Intent.EXTRA_STREAM, R.drawable.pic4);

            i.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+getPackageName()+"/"+imageURI));


        try {
            startActivity(Intent.createChooser(i, "Send mail..."));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(EidCards.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }
于 2012-08-10T10:31:47.020 回答