使用gmail应用程序共享图像不起作用

时间:2011-10-19 13:19:33

标签: android image gmail share

我与Gmail应用程序共享图像问题。 这是我的代码。

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);     
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,  getString(R.string.mail_subject)); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,  getString(R.string.mail_body)); 
    emailIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.facebook_share_text));


    //Download the image first
    String location=downloadImage(true);
    File root=android.os.Environment.getExternalStorageDirectory();
    Log.e("send from where:","file:///"+root.getAbsolutePath()+"/"+location);

    //Add attachment
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///"+root.getAbsolutePath()+"/"+location));

    emailIntent.setType("image/jpeg");
    startActivity(Intent.createChooser(emailIntent, getString(R.string.share_by)));

默认电子邮件应用程序运行良好,Facebook共享工作正常,Gmail应用程序接缝工作但附件未发送,但显示为附件。

以下是截屏。 All share options Email is send but without attachment, although the attachment is displayed here Facebook share is perfect

所以请帮忙。

2 个答案:

答案 0 :(得分:3)

String location=downloadImage(true);
File root=android.os.Environment.getExternalStorageDirectory();
Log.e("send from where:","file:///"+root.getAbsolutePath()+"/"+location);

//Add attachment
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///"+
root.getAbsolutePath()+"/"+location));
 // replace "Uri.parse" with Uri.fromFile(new File("file:///"+
root.getAbsolutePath()+"/"+location))
emailIntent.setType("image/jpeg");
startActivity(Intent.createChooser(emailIntent, getString(R.string.share_by)));

这件事实际上对我有用。当我发送Uri.parse时,同样的事情发生在我身上。您可以看到附件的大小将显示0 kb。但是当我改变它时,它运作得很好。

答案 1 :(得分:0)

分享在facebook,whatsapp,gmail,蓝牙和消息上运行的图片

            Uri imageUri = Uri.fromFile(file);
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM,imageUri);
            shareIntent.setType("image/*");
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(Intent.createChooser(shareIntent,"Share with.."));