图片preVIEW电子邮件意图没有显示时,从资产文件夹中加载 [英] Image preview in email Intent not showing when loaded from Assets Folder
问题描述
我有类似如下的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卡(参见:<一href="http://stackoverflow.com/questions/4447477/android-how-to-copy-files-in-assets-to-sdcard">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]);
这篇关于图片preVIEW电子邮件意图没有显示时,从资产文件夹中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!