1

I'm using UrlImageViewHelper library and it works fine. It caches the images on internal storage and it's bad for me because I've about lots of images and if I want to cache them it's horrible. How can I save these downloaded files and store them in SD card instead of internal storage?

JorgeAmVF
  • 1,660
  • 3
  • 21
  • 32

2 Answers2

1

Please check your whether your URL is valid or not by putting into browser. If image size is large then please use placeholder image which still displays your URL, not load image available, like this:

UrlImageViewHelper.setUrlDrawable(imageView, "http://example.com/image.png", R.drawable.placeholder);
JorgeAmVF
  • 1,660
  • 3
  • 21
  • 32
chet's
  • 193
  • 2
  • 8
0

Use this class

public class DemoHelper {

    private static final String TAG = DemoMainActivity.TAG;

    public static class RemoteImageTask extends AsyncTask<Void, Void, Bitmap> {
        ImageView _image;
        String _imageSource;
        TaskCallback _callback;

        public RemoteImageTask(ImageView image, String imageSource) {
            this(image, imageSource, null);
        }

        public RemoteImageTask(ImageView image, String imageSource, TaskCallback callback) {
            _image = image;
            _imageSource = imageSource;
            _callback = callback;
        }

        protected Bitmap doInBackground(Void... params) {
            URL url;
            Bitmap bmp = null;
            try {
                url = new URL(_imageSource);
                bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
            } catch (Exception ignored) {
                Log.e(TAG, "Exception", ignored);
            }

            return bmp;
        }

        protected void onPostExecute(Bitmap bmp) {
            _image.setImageBitmap(bmp);
            if (_callback != null)
                _callback.onTaskFinished(bmp);
        }
    }

    public interface TaskCallback {
        public void onTaskFinished(final Bitmap bmp);
    }
   }
Lavekush Agrawal
  • 6,040
  • 7
  • 52
  • 85
Pawan asati
  • 292
  • 2
  • 13