How to share an image using Android-Universal-Image-Loader I have an imageview which is loaded through imageloader but providing a URL to the image loader, I think the image loader already done writing the image from URL to disk and then displayed it
how can I share it without re-writing it to disk?
item_zoom_image_view is ImageView selectedItemImage is a class that has a property that contains the URL ( http://... .)
here is my image loader config:
public void initImageLoader(Context context) {
DisplayImageOptions options = new DisplayImageOptions.Builder()
.cacheOnDisc().imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
context).threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.defaultDisplayImageOptions(options)
.memoryCache(new WeakMemoryCache())
.denyCacheImageMultipleSizesInMemory()
.tasksProcessingOrder(QueueProcessingType.LIFO).build();
imgLoader = ImageLoader.getInstance();
imgLoader.init(config);
}
and here is how I display the image
ImageLoader imgLoader = AppData.imgLoader;
if (!selectedItemImage.getImageURL().trim().equals("")) {
imgLoader.displayImage(selectedItemImage.getImageURL(), item_zoom_image_view, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
Progress.ShowProgressDialog(true);
currentImageURI = "";
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
item_zoom_image_view.setImageResource(R.drawable.ic_artificial_flowers);
Progress.HideProgressDialog();;
currentImageURI = "";
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
Progress.HideProgressDialog();;
currentImageURI = imageUri;
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
item_zoom_image_view.setImageResource(R.drawable.ic_artificial_flowers);
Progress.HideProgressDialog();;
currentImageURI = "";
}
});
}
else
{
item_zoom_image_view.setImageResource(R.drawable.ic_artificial_flowers);
Progress.HideProgressDialog();;
currentImageURI = "";
}
Here is how I share the image:
void ShareImg() {
try {
Uri bmpUri = Uri.parse(currentImageURI);
if (bmpUri != null) {
// Construct a ShareIntent with link to image
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/*");
// Launch sharing dialog for image
startActivity(Intent.createChooser(shareIntent, "Share Image"));
} else {
// ...sharing failed, handle error
}
} catch (Exception e) {
}
}
the problem is that the URI which I took while displaying the image (currentImageURI) is not correct or i don't know but it shows a black image
you need to save bitmap in storage to share it. you cannot share cache image which image loader download from url
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap
loadedImage) {
Progress.HideProgressDialog();;
currentImageURI = imageUri;
loadedImage
//save it in storage then share
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.