简体   繁体   中英

Is there a way to know where an image was loaded from on UniversalLoader?

I'm using the Universal Image Loader on my project. I want to do a specific action if the image was loaded from server and nothing if loaded from memory or disk cache.

So far the only way I found to do this is to ping memory and disk cache in advance to see if they contain the image. This is not very nice since in case it's not there, the normal flow to display image will repeat this checks so I'm duplicating efforts.

Is there a better way to do this? I saw in the code a LoadedFrom variable that is passed across different internal methods, but is not returned on public API.

YOu can use this codes to check image cached or not:

public static boolean checkCacheImageUri(String uri) {
        List<String> findCacheKeysForImageUriThumbnail = MemoryCacheUtils.findCacheKeysForImageUri(
                uri, ImageLoader.getInstance().getMemoryCache());
        if (findCacheKeysForImageUriThumbnail != null
                && !findCacheKeysForImageUriThumbnail.isEmpty()) {
            return true;
        }
        return false;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM