0

I'm trying to save image from url to a new File with ion library. But nothing happens. Can anybody help me with it?

Ion.with(mContext)
                .load("someUrl")
                .write(new File(mContext.getCacheDir(), "123.jpg"));
Kara
  • 6,115
  • 16
  • 50
  • 57
d0pestar
  • 565
  • 1
  • 5
  • 10

2 Answers2

1

Use Universal Image Loader

You can do it by

ImageLoader imageLoader = ImageLoader.getInstance(); // Get singleton instance

// Load image, decode it to Bitmap and return Bitmap to callback
imageLoader.loadImage(imageUri, new SimpleImageLoadingListener() {
    @Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage){
    // Do whatever you want with Bitmap
}
});
Pravin Raj
  • 3,439
  • 1
  • 13
  • 13
0

Ion is asynchronous. Use .setCallback to get a callback when it completes.

Ion.with(mContext)
                .load("someUrl")
                .write(new File(mContext.getCacheDir(), "123.jpg"));
                .setCallback(....)
koush
  • 2,972
  • 28
  • 31
  • What is the best way to parse the result to another function? Right now, I'm using another callback as a parameter of my function and returning the `result` using that callback: `if (responseCallback != null) { responseCallback.onSuccess(result); }`. Is this a good practice/good way to do that? – Otacilio Oliveira Jul 20 '15 at 21:52