图片preVIEW电子邮件意图没有显示时,从资产文件夹中加载意图、加载、电子邮件、资产

2023-09-04 23:08:29 作者:呆萌小鸭子

我有类似如下的code:

public void shareImageInEmail(String imageUri){
   Intent emailIntent = new Intent(Intent.ACTION_SEND);
   emailIntent.setType("message/rfc822");
   emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   emailIntent.putExtra(Intent.EXTRA_TEXT, "Some text");
   emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imageUri));
   mActivity.startActivity(emailIntent);
}

乌里从媒体文件夹抢下(相机相册等),一切工作正常。 问题是,当我把一个乌里从资产文件夹是这样的:

When the Uri is grabbed from the media folders (camera albums, etc) everything works fine. The problem is when I take a Uri from the assets folder like this:

share("content://com.ex.myapp/logo.png");

在这种情况下,分享作品,但电子邮件客户端打开时,图片preVIEW是,而不是实际的图像一个灰色的框。当我发的图片是正确发送,它只是不显示preVIEW。

In that case, the sharing works but when the e-mail client is opened, the image preview is a grey box, instead of the actual image. When I send the picture is sent correctly, it's just not showing the preview.

任何人有一个解决方案?

Anyone have a solution for this?

推荐答案

一个简单的解决方法是将资产的全部内容复制到SD卡,并通过SD卡路径URI为EXTRA_STREAM到电子邮件。

A simple solution will be to copy all contents in Assets to Sdcard and pass 'Sdcard path Uri' as EXTRA_STREAM to Email.

样品code:

public void shareImageInEmail(String imageUri){
       Intent emailIntent = new Intent(Intent.ACTION_SEND);        
       emailIntent.setType("message/rfc822");

       emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       emailIntent.putExtra(Intent.EXTRA_TEXT, "Some text");

       Log.v(TAG, "imageUri, file://" + imageUri);
       emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + imageUri));
       startActivity(emailIntent);
}

复制所有资产,以SD卡(参见:Android:如何在复制文件'资产'到SD卡?)

Copy all assets to SDCard (Refer: Android: How to copy files in 'assets' to sdcard?)

new File(Environment.getExternalStorageDirectory(), filename); //Store in Sdcard

和最后调用shareImageInEmail如下,

And finally call shareImageInEmail as follows,

shareImageInEmail(Environment.getExternalStorageDirectory() + "/Image.png");//assets[0]);
 
精彩推荐
图片推荐