我所做的是另一個獲取圖像的請求,並添加了一個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();
}
}
});
由於圖像已經下載並緩存(使用BitmapLRU緩存和ImageLoader的),這個新的請求給我從緩存中所以沒有新的網絡數據由位圖。