[英]How to share image that is downloaded and cached with Volley?
In my app I download images from server using Volley and its ImageLoader (with BitmapLruCache). 在我的应用程序中,我使用Volley及其ImageLoader(带有BitmapLruCache)从服务器下载图像。 I want to create a share option, researched a little bit, and found that share intent can only share localy stored images.
我想创建一个共享选项,进行了一些研究,发现共享意图只能共享本地存储的图像。 First question, is this right?
第一个问题,对吗?
Second, if that is right, what should I do? 第二,如果那是正确的,那我该怎么办? Should I download image again and save it to local storage?
我应该再次下载图像并将其保存到本地存储吗? Or put it in MediaStore?
还是放在MediaStore中? Or I can pull image from cache and share cached version?
或者我可以从缓存中提取图像并共享缓存的版本? What are the best practices?
最佳做法是什么?
Any suggestion is welcome, or code snippet. 欢迎任何建议或代码段。
What I did is made another request for getting the image, and added an ImageListener which provides ImageContainer containing bitmap. 我所做的是再次请求获取图像,并添加了一个ImageListener,它提供了包含位图的ImageContainer。
MyApplication.getImageLoader(activity).get(imageURL, new ImageListener() {
@Override
public void onErrorResponse(VolleyError error) {}
@Override
public void onResponse(ImageContainer response, boolean isImmediate) {
Bitmap mBitmap = response.getBitmap();
ContentValues image = new ContentValues();
image.put(Media.MIME_TYPE, "image/jpg");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, image);
try {
OutputStream out = getContentResolver().openOutputStream(uri);
boolean success = mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.close();
if (!success) {
} else {
imageUri = uri;
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
// Create the share Intent
Intent shareIntent = ShareCompat.IntentBuilder.from(activity).setType("image/jpg").setText(shareText).getIntent();
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
mShareActionProvider.setShareIntent(shareIntent);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
As image is already downloaded and cached (using BitmapLRU cache and ImageLoader), this new request gives me bitmap from cache so no new network data is made. 由于已经下载并缓存了图像(使用BitmapLRU缓存和ImageLoader),因此此新请求为我提供了来自缓存的位图,因此不会产生新的网络数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.