从资产的文件夹的android共享图像 [英] android share images from assets folder
本文介绍了从资产的文件夹的android共享图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的资产文件夹共享的图像。我的code是:
I'm trying to share an image from my assets folder. My code is:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpg");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///assets/myImage.jpg"));
startActivity(Intent.createChooser(share, "Share This Image"));
,但它不工作。你有什么想法?
but it doesn't work. Do you have any ideas?
推荐答案
这是可能的共享文件(影像含)的资产,通过自定义文件夹的ContentProvider
It is possible to share files (images including) from the assets folder through a custom ContentProvider
您需要延长的ContentProvider
,在你的清单中注册并执行 openAssetFile
方法。然后,您可以通过乌里
取值
You need to extend ContentProvider
, register it in your manifest and implement the openAssetFile
method. You can then assess the assets via Uri
s
@Override
public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
AssetManager am = getContext().getAssets();
String file_name = uri.getLastPathSegment();
if(file_name == null)
throw new FileNotFoundException();
AssetFileDescriptor afd = null;
try {
afd = am.openFd(file_name);
} catch (IOException e) {
e.printStackTrace();
}
return afd;
}
这篇关于从资产的文件夹的android共享图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文