I'm trying to get fresco cached image from a fragment after a button click event to share the image bitmap in whatsapp!! Unfortunately it's very slow, after click the share button 2, 3 times code works!! I'm looking for better solution !!
ImageRequest imageRequest = ImageRequestBuilder
.newBuilderWithSource(Uri.parse("http://example.com/test,jpg"))// disck cached
.setRequestPriority(com.facebook.imagepipeline.common.Priority.HIGH)
.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.DISK_CACHE)
.build();
// .setRequestPriority(Priority.HIGH)
DataSource<CloseableReference<CloseableImage>> dataSource =
imagePipeline.fetchDecodedImage(imageRequest, this);
try {
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
if (bitmap == null) {
Log.d(TAG, "Bitmap data source returned success, but bitmap null.");
return;
}
sharewithwhatsappBitmap(bitmap);
// The bitmap provided to this method is only guaranteed to be around
// for the lifespan of this method. The image pipeline frees the
// bitmap's memory after this method has completed.
//
// This is fine when passing the bitmap to a system process as
// Android automatically creates a copy.
//
// If you need to keep the bitmap around, look into using a
// BaseDataSubscriber instead of a BaseBitmapDataSubscriber.
}
@Override
public void onFailureImpl(DataSource dataSource) {
// No cleanup required here
Log.d(TAG, "Bitmap data source onFailureImpl");
}
}, CallerThreadExecutor.getInstance());
} finally {
if (dataSource != null) {
dataSource.close();
}
}
I'm using DraweeController in recyclerview, DraweeController is more optimized I guess !! but don't how to use it for getting one image with bitmap !!
public void sharewithwhatsappBitmap(Bitmap bitmap) {
String path = MediaStore.Images.Media.insertImage(getApplicationContext().getContentResolver(),
bitmap, "Image Description", null);
Uri bmpUri = Uri.parse(path);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
//shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Title Of The Post");
shareIntent.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=garbagebin.com.garbagebin");
shareIntent.setType("image/*");
//startActivity(Intent.createChooser(shareIntent, "Share Image"));
shareIntent.setPackage("com.whatsapp");
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.whatsapp")));
}
}
Log when first time it calls for bitmap:
v/unknown:AbstractDraweeController: controller 2a7f5b0e null -> 15: initialize
V/unknown:AbstractDraweeController: controller 2a7f5b0e 15: setHierarchy: com.facebook.drawee.generic.GenericDraweeHierarchy@20cc392f