Where is the cache folder of the Universal ImageLoader? - android

The caching of my Universal ImageLoader seems not working. I'm wondering where the folder of the cache is. I found there is a folder in my sdcard:
data->data->id of my app->cache->uil-images
But it's empty. Here is my code:
DisplayImageOptions displayOptions = new DisplayImageOptions.Builder()
.cacheOnDisc(true)
.cacheInMemory(false)
.showStubImage(R.drawable.img_placeholder)
.showImageForEmptyUri(R.drawable.img_placeholder)
.showImageOnFail(R.drawable.img_placeholder)
.bitmapConfig(Bitmap.Config.RGB_565)
.displayer(new FadeInBitmapDisplayer(500))
.build();
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(this.context));
imageLoader.displayImage(imgUrl, imageView, displayOptions);
No matter I set the cacheInMemory to false or true, the result is the same. Can somebody explain what could be wrong with it? Thanks.
By the way, I'm using universal imageloader 1.8.6

According to the source code file library/src/main/java/com/nostra13/universalimageloader/utils/StorageUtils.java, cache directory will be created on :
SD card, in preference, if card is mounted and app has appropriate permission, at this location /Android/data/[app_package_name]/cache/
device's file system /data/data/[app_package_name]/cache/.
This response need to completed because incomplete.

Related

Image caching using Universal Image loader in android

I am working on a project in which I have to lazy load profile images of contacts into recyclerview, and I am loading cached images into recyclerview if the user is offline. I am using Universal Image loader to load images from server and cache it in device.Universal Image loader is caching Images in file path
[Android->data->packagename->cache]
here the problem is user able to see the cached images (thumbnails of images) by going to that path [Android->data->packagename->cache].
1) Is there any way that I can cache images with different extension so the user cannot able to see those cached images?
2) How to cache images other than this path [Android->data->packagename->cache] using UIL ?
Here is how I tried to cache image with different extension and in different location,It created folder "cool" but the image is getting cached in default location ([Android->data->packagename->cache])
I tried to cache image in [Android->data->packagename->files]
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.profileimage)
.cacheInMemory(true)
.cacheOnDisk(true)
.build();
File cacheDir = this.getExternalFilesDir("cool");
File cache = new File(cacheDir,"cool.m");
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
.defaultDisplayImageOptions(defaultOptions)
.diskCache(new UnlimitedDiskCache(cache))
.build();
ImageLoader.getInstance().init(config);

Different saving path for universal image loader

I am using 'universal image loader' library in my application to load images from internet. In some parts of my application I don't need to cache the images in memory for long time so I clear the cache every 24 hours. In other parts I need to cache images for long time and I don't want to clear them.
My question is, is it possible to config universal image loader some how to use different caching paths and the other question is how can I save the cached data in a custom folder ?
This is how I configure my uil :
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.image_loading)
.showImageForEmptyUri(R.drawable.strawberry)
.showImageOnFail(R.drawable.image_faild)
.cacheInMemory(false)
.cacheOnDisk(true)
.considerExifParams(true).build();
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));
You may use different instances DisplayImageOptions. Something like this
cachedOnDiskOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.image_loading)
.showImageForEmptyUri(R.drawable.strawberry)
.showImageOnFail(R.drawable.image_faild)
.cacheInMemory(false)
.cacheOnDisk(true)
.considerExifParams(true).build();
cachedInMemoryOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.image_loading)
.showImageForEmptyUri(R.drawable.strawberry)
.showImageOnFail(R.drawable.image_faild)
.cacheInMemory(true)
.cacheOnDisk(false)
.considerExifParams(true).build();
ImageLoader.getInstance().displayImage(url, imageView, cachedInMemoryOptions);
ImageLoader.getInstance().displayImage(anotherUrl, anotherImageView, cachedOnDiskOptions);

Universal Image Loader not loading image for specific link

I started to use Universal Image Loader instead of Picasso, to avoid the image-not-loading problem. Now it emerges in Universal Image Loader too. It is the same problem with the same unique image, but not other images.
The problematic Image:
http://luxproperty.kaytami.com/platform/media/image/jpeg/2015/01/4_4.jpg
Other properly-behaved images:
http://luxproperty.kaytami.com/platform/media/image/jpeg/2015/01/4.2_4.jpg
http://luxproperty.kaytami.com/platform/media/image/jpeg/2015/01/4.3_4.jpg
http://luxproperty.kaytami.com/platform/media/image/jpeg/2015/01/4.4_4.jpg
They are of similar sizes. And about my Universal Image Loader, the setting is as such:
In Application:
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.diskCacheFileNameGenerator(new Md5FileNameGenerator())
.diskCacheSize(50 * 1024 * 1024) // 50 Mb
.tasksProcessingOrder(QueueProcessingType.LIFO)
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
In activity:
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.image_placeholder)
.showImageForEmptyUri(R.drawable.image_error)
.showImageOnFail(R.drawable.image_error)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.build();
.......
ImageLoader.getInstance().displayImage(url), image, options);
Any hints would be much appreciated. I just cannot get rid of this problem anyhow, neither with Picasso nor Universal Image Loader.....
My previous StackOverFlow with Picasso:
Picasso cannot load images for some URL (no special characters)
It seems like the image is corrupted as downloading and opening it in photoshop also throws error. You can also see the bottom part of the image for blurry pixels.
Although there is one more case that I know of when image loading fails is when loading an image in CMYK color format. Android doesn't support CMYK, although there are some Third-party libraries for loading CMYK images but I don't think that it is the case for you. I strongly believe that the image is corrupted.
imageLoader = ImageLoader.getInstance();
prova = context;
options = new DisplayImageOptions.Builder()
//.displayer(new RoundedBitmapDisplayer(1000))
.showImageOnLoading(R.drawable.placeholder)
.showImageForEmptyUri(R.drawable.placeholder)
.showImageOnFail(R.drawable.placeholder)
.cacheInMemory(true)
.cacheOnDisc(true)
.considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565)
// .displayer(new RoundedBitmapDisplayer(70))//////
.build();
//note you use this in your adapter where your handling your image and make sure you inistalize that your UIL class in your manifest application
<application
android:name="com.example.UILApplication"

How to set universal image loader to download a picture once?

I'm using universal image loader.
I want to download a picture from url and show it in my application.
I'm sure that i'll never change the picture in my site.
So I need it to be downloaded once. and don't even check the date of modification to download it.
In fact I want the app to check if the image was downloaded the don't download it :)
How can I do this.
Thank you
instead of download image you should keep in drawable and use it
if you are download image via UID its save in catch memory and it is removable you can clear that catch once it is clear than you have to download again if you sure that you want download once only than i suggest go for drawable not for UID unless you have specific requirement
On universal loader if you are true cacheInMemory then it maintain cache and your image download once. By default it is false:-
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
...
.cacheInMemory(true)
.cacheOnDisk(true)
...
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
...
.defaultDisplayImageOptions(defaultOptions)
...
.build();
ImageLoader.getInstance().init(config);
for more info you have to read below link:-
https://github.com/nostra13/Android-Universal-Image-Loader

Display Image in list View with using ImageLoader once time

I've code to display image in list view using imageLoader library from com.nostra13.universalimageloader
this code like this
imageLoader.displayImage(link_url, imageView, options, animateFirstListener);
but this code make this app must download image from this url. I wanna ask , can I using this cache image to show image. So if not connect internet the image can be show because this image was save as cache before?? How to show image in imageview if this image is from cache?? thanks
Instead of downloading it again you should cache images in phone memory or sdcard.
It caches images in say sdcard (if you have configured properly) using url as the key. If present display from cache else download, cache and display images.
In your custom adapter constructor
File cacheDir = StorageUtils.getOwnCacheDirectory(activity context, "cache_folder")
imageLoader = ImageLoader.getInstance();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a)
.discCache(new UnlimitedDiscCache(cacheDir))
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.enableLogging()
.build();
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_id)//display stub image untik image is loaded
.cacheInMemory()
.cacheOnDisc()
.displayer(new RoundedBitmapDisplayer(20))
.build();
In your getView()
viewholder.image=(ImageView)vi.findViewById(R.id.imageview);
imageLoader.displayImage(imageurl, viewholder.image,options);
By deafult it stores cache i guess.
Check once Disconnecting internet.
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.deafaultimage).cacheInMemory()
.cacheOnDisc().bitmapConfig(Bitmap.Config.RGB_565).build();
HTTP caching depends on Cache-Control headers. If the server is sending the proper headers in the response then the library will automatically cache the resource automatically and access it even if there is no network. You don't have to do anything explicitly.
You can configure more options such as cache size etc if you want. See the docs.

Categories

Resources