With felipecsl Android-ImageManager library how can I replace a cached image - android

I am using felipecsl Android-ImageManager library to download some images from one of our servers and load it in a list view. In my Android application I have a feature to change that downloaded image from app side and upload it to server.
I do know how to load the image from URL because it is well documented with the above mentioned link. What I need is to change/delete a particular cached item and replace it with my new image from Android application side.
Let me explain it further. Normally what happens is, it loads an image from the provided URL and caches it in the manager's LRU and Disk cache. Then the second time call to that same URL, if the image is already cached, fetches it from the cache even I have set a different image from my application side.
Therefore how can I either delete that URL from cache OR set the new image for the cache of that same URL.
I have tried something like below, but seems it is not working.
imageManager.getCacheManager().getMemoryCache().put(ImageManager.getCacheKeyForJob(myUrl, jobOptions), bitmap);

That is not really supported by the library. If you need to do this kind of more advanced cache management, you can use Picasso (https://github.com/square/picasso), where you can set your own cache manager and have more control over your cached images.

Related

Caching with Glide

I'm using Glide and want to cache loaded images to local memory.
I searched for the same, and found out that images are cached automatically. You just need to provide the same loadURL , and Glide will search for image (along with other provided attrs : Resolution, Key, etc). The problem that I'm facing is that, I know what the loadURL will be at the time of initial resource load. But when the app wants to load the cached copy of, it doesn't have any loadURL info. How can I load cached images without providing loadURL (which was same at the time of initial load). Can I use any key (say StringKey), which can be associated with the image at initial load, and use the same key (without loadURL) at the time of loading cached copy? Thank you.
Glide doesn't support directly accessing the cache.
So, just persist the url the first time and use it later to load the cached image.
First time:
Glide.with(this).load(url).into(image);
save(url);
Later:
String url = getUrl();
Glide.with(this).load(url).into(image);

Fetch Image from server by using url with Universal Image Loader

I am successfully fetching and caching image from server url by using Universal Image Loader. My DisplayImageOptions are given below.
new DisplayImageOptions.Builder().cacheInMemory(true)
.showImageOnLoading(R.drawable.home_back_img)
.showImageOnFail(R.drawable.home_back_img)
.bitmapConfig(Bitmap.Config.ALPHA_8)
.showImageForEmptyUri(R.drawable.home_back_img)
.build();
My problem is, when I updates image in server(with same file name), the image is not updated in application, its just using the cached file itself. Is there is any solution for this? Yes we can avoid caching, but then it might take some time to load the image every time, rather than avoid caching it would be nice if any solution exists. Help will be appreciated!
You must use different name to get the updated photo. Because , the image already stored in your local cache by the same name. So, It will never call to network to download the image .
Or , Clear your application cache , then you will get the updated image.

Using Glide for Android, what's a good way to use (local) alternative sources for urls?

I'm using Glide to load images in my Android app:
Glide.with(context)
.load("http://www.example.com/whatever/icon.png")
.into(imageView);
I would like to bundle some images in my app APK file to make sure that they are always available even if the device is offline. I would still like to use Glide to benefit from features such as memory caching of resized images, loading and scaling in a background thread and also to keep the interface for displaying images consistent.
Each image that I need to load like this is specified by a URL.
If there's a local version ( the local file name is generated by using a part of the URL [ e.g. replacing "http://www.example.com/" with "file:///android_asset/bundled_images/whatever/" ] in the URL string ), I would like to use that one. If not, the image needs to be downloaded from the actual URL.
Here's an example:
I have an image at http://www.example.com/whatever/icon.png
I will bundle this image in the apk under:
/assets/bundled_images/whatever/icon.png
The rule would be as follows:
If the image file exists under local assets, use that file. If the image does not exist under local assets, use the remote file.
Whenever I request an image to be loaded into an imageview, I would like to be able to use just the full URL (http://www.example.com/whatever/icon.png), and my image loader should automatically be able to check for a local copy first.
Can I do something like this with any of Glide's functionality? Yes, I could of course to the file exists check before calling glide, but it seems like a common enough use case that Glide could/should have a feature for this. Would also be nice to do the file-exists check in the background.
You can achieve required flexibility by adding custom GlideModule in the way described here: Glide Configuration. Also you need to implement appropriate Glide's Loader which would encapsulate the logic for downloading. In your case it can be something similar to UriLoader.
Glide provides an option to load a local image if the device is offline.
This can be done using the error() method.
Glide.with(this).load(imageUrl)
.error(localImageResId)
.into(mIconView);
The code above downloads an image from imageUrl and loads it into the imageView.
In case of an error (ex device offline) it loads the local image resourse.

Android + Picasso: How to show images from URL properly form cache

I am developing Android app now where I need to store image Url in DB for each object and then load this image from the web (if connection is on) OR get it form cache (if not).
Picasso seems to be best lib for handling images in Android, so I starter using it. But I can not get how do I use it properly for my case. Even more - Images strangely are loaded into views right after they are first time get from API but if user starts app again, we can see placeholder only (even with internet connection on). Can someone suggest a solution or at least any kind of idea of best way to do this?
My code in Adapter (is is also same in ShowActivity):
String img_url = item.getImage(); // img_url is valid image url
Picasso.with(mContext).load(img_url).placeholder(R.drawable.plchldr).fit().centerCrop().into(holder.image);
I tried to use Picasso at the start as well, and found out that their caching system is horrible.
It would cache some images i downloaded, but not others, and would therefore leave alot of images with placeholders.
I suggest you try Universal-Image-Loader (https://github.com/nostra13/Android-Universal-Image-Loader). I'm currently using this to cache all images in my app, and it works flawlessly (Around 200 images atm).
Finally got the problem - API is returning valid image url BUT actually it (image) is hosted on S3 cloud and it is expiring till the user loads application again. So, actually saving expiring image URL is useless in this situation. I am not sure what will I do here (it seems that the only way here is hard one - storing images on SD as Bitmap). But I just wanted to tell this for those who will get similar issue.

Android Image fetching library

Hi i wanted to know is their any library in which we pass the URL and the image-view and it checks whether the images is present on device if not, then fetch image from URL and store to device and bind with the view passed. I tried writing the code but once the view is loaded and image is not fetched the images is never fetched in future unless i uninstall the app , i also tried universal image loader library and asynchronous image loader
Picasso is doing all things what you want.
It loads from internet and cache
It loads from cache
It loads from Local File
Read More Here And Here
Try volley library. you have a NetworkImageView I guess. Which fits your need.

Categories

Resources