Check if Image is in Cache - Universal Image Loader

前端 未结 5 1911
醉梦人生
醉梦人生 2021-02-07 18:29

I guess the title says it all. I tried:

imageLoader.getMemoryCache().get(key); 

with the image uri as key, but it always return null

5条回答
  •  隐瞒了意图╮
    2021-02-07 19:02

    Sometimes, when using the Universal Image Loader library, there comes a time where the loader takes a while to verify whether the remote image has been already loaded in your cache. To load the cache file directly, you can use the following method to check whether a local copy of the remote file has already been made:

        File file = imageLoader.getDiscCache().get(url);  
     if (!file.exists()) {  
          DisplayImageOptions options = new DisplayImageOptions.Builder()  
          .cacheOnDisc()  
          .build();  
          imageLoader.displayImage(url, imageView, options);  
     }  
     else {  
          imageView.setImageURI(Uri.parse(file.getAbsolutePath()));  
     }  
    

    check it hereenter link description here

提交回复
热议问题