如何使用 Universal Image Loader 从缓存中下载的图像

How can I use Already downloaded images from cache with Universal Image Loader

我使用 Universal Image Loader 从 Activity A 中的 uri 中获取数据,但我没有使用 displayImage() 方法在 [=14] 中再次从 uri 中获取图像=].

相反,我想将已存储在缓存中的图像提取到另一个 Activity B

如何做到这一点?

我已经使用这些选项来初始化图像加载器

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                .cacheOnDisc(true).cacheInMemory(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .displayer(new FadeInBitmapDisplayer(300)).build();

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                getApplicationContext())
                .defaultDisplayImageOptions(defaultOptions)
                .memoryCache(new WeakMemoryCache())
                .discCacheSize(100 * 1024 * 1024).build();

ImageLoader.getInstance().init(config);

然后调用它来获取图像

ImageLoader imageLoader = ImageLoader.getInstance();

//download and display image from url
imageLoader.displayImage(url, myImageView);

解决方案:

Yes it's working in Activity B, but it is making unwanted connections to download the image when the internet is not connected, Every time the 'getView()' method is called in ListView when scrolling. 'failed to connect to /192.168.1.3 (port 80) after 5000ms: connect failed: ENETUNREACH (Network is unreachable) java.net.ConnectException: failed to connect to /192.168.1.3 (port 80) after 5000ms: connect failed: ENETUNREACH (Network is unreachable)`

  ImageLoader imageLoader = ImageLoader.getInstance();

        File file = imageLoader.getDiskCache().get(image_url);
        if (file==null) {

            //Load image from network
        }
        else {
           //Load image from cache
            mImageView.setImageURI(Uri.parse(file.getAbsolutePath()));
        }