2011-10-19 58 views
2

我与Gmail应用程序共享图像问题。 这是我的代码。与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

所以,请帮助。

回答

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。但是当我改变它时,它工作得很好。

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..")); 
相关问题