[英]Is there a way to know in code from where the application downloaded on Android
[英]Is there a way to know where an image was loaded from on UniversalLoader?
我在我的項目中使用 Universal Image Loader。 如果圖像是從服務器加載的,我想做一個特定的操作,如果從內存或磁盤緩存加載什么都不做。
到目前為止,我發現這樣做的唯一方法是提前 ping 內存和磁盤緩存,看看它們是否包含圖像。 這不是很好,因為如果它不存在,顯示圖像的正常流程將重復此檢查,因此我正在重復工作。
有一個更好的方法嗎? 我在代碼中看到一個LoadedFrom
變量,它在不同的內部方法之間傳遞,但沒有在公共 API 上返回。
您可以使用此代碼來檢查圖像是否已緩存:
public static boolean checkCacheImageUri(String uri) {
List<String> findCacheKeysForImageUriThumbnail = MemoryCacheUtils.findCacheKeysForImageUri(
uri, ImageLoader.getInstance().getMemoryCache());
if (findCacheKeysForImageUriThumbnail != null
&& !findCacheKeysForImageUriThumbnail.isEmpty()) {
return true;
}
return false;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.