【问题标题】:Share image with gmail application doesn't work与 gmail 应用程序共享图像不起作用
【发布时间】:2011-10-19 13:19:32
【问题描述】:

我在与 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 Share 运行良好,Gmail 应用程序正常运行,但附件未发送,尽管显示为附件。

这里是屏幕截图。

所以请帮忙。

【问题讨论】:

    标签: android image gmail share


    【解决方案1】:
    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。但是当我改变它时,它工作得很好。

    【讨论】:

      【解决方案2】:

      在 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.."));
      

      【讨论】:

        猜你喜欢
        • 2012-06-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-26
        • 1970-01-01
        • 2016-02-08
        • 2020-02-14
        相关资源
        最近更新 更多