I am planning on implementing, Picasso with OKHTTP for Disk caching of images. But I also plan on having encryption on images caches on disk. What should I do? I couldn't find a single helpful link, that can guide me in the right direction. Any kind of help would be greatly appreciated.
If somebody is looking for an answer, here is how I achieved it.
Firstly I switched to UIL since it provides more customization than Picasso.
Then I customized the built in diskCache mechanism.
ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(getApplicationContext());
builder.threadPriority(Thread.NORM_PRIORITY - 2);
builder.threadPoolSize(5);
builder.imageDownloader(new CustomImageDownaloder(this, new OkHttpClient()));
builder.diskCache(new CustomDiskCache(cacheDir));
Now in CustomDiskCache just override the methods where it read bytes from network and save them to disk, read bytes encrypt them and save them. Similarly, when you are about to read from cache file, decrypt bytes and convert them to bitmap.
Hope it helps.
Related
How to encrypt and decrypt disk cache images in android using Glide ?
Hi one idea would be create a cache decoder / encoder and use a library such https://github.com/facebook/conceal to do the hard encrypt / decrypt lift.
This image might help you navigate through the life cycle of glide:
I got a question about android fresco library. Do you guys know how to get callback when file is saved in cache? Generally, we could get file from cache:
ImageRequest imageRequest= ImageRequest.fromUri(url);
CacheKey cacheKey= DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest);
BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
File file=((FileBinaryResource)resource).getFile();
However, if I put this in onCreate() function, it will crash since the file was not in the cache yet. Do you guys know how I got get a callback when the fresco finish saving it? Is it DataSubscriber? Could you guys provide an example? I read the documentation but I couldn't figure out.
Thanks.
I am part of the Fresco team and may be able to help. Please see our documentation on how to properly get the encoded image bytes. There is a code example of how to get an InputStream of the encoded image (which is what is being stored in cache). You can then use those bytes directly, or if you need a File in order to pass it somewhere else, you should create your own file and store the returned bytes in it. There is no other safe way to deal with cached images because you have no guarantees that Fresco will not evict (delete) the cached file at any time.
I am working with #Xamarin.Android# Application. I don't know how to cache Bitmap images. In Xamarin.Android Application how to cache data?
I'm going to recommend you look at this library
https://github.com/LukeForder/Xamarin-Bindings-Android-Universal-Image-Loader
It is a Xamarin Binding for this Android Library
https://github.com/nostra13/Android-Universal-Image-Loader
And it does everything you want in regards to caching images.
As for caching a byte[] in memory you can create PCL and use this code
http://ranahossain.blogspot.co.uk/2014/01/cache-provider-for-portable-class.html
I recently had to write something to do this, and wasn't able to use the libraries mentioned by Adam because we needed to do some custom post processing of the images before they were cached etc.
I can't share the code I wrote, but I referred to this article heavily. In my case, we also had to load the images remotely before processing, so the prior article on that same site here was a lot a lot of help.
So what I to achieve is to apply encryption while caching images on disk.
I have decided to go with Universal Image Loader, I understand I will have to add an custom
disk caching implementation of my own but I don't know where to start with.
How can I achieve this, encryption while writing byte stream in file and decryption while getting the stream only from file.
Any kind of help would be deeply appreciated :)
Thanks for not replying :P
But I did eventually end up solving it. And here is what I did, maybe It will help anyone else.
All I had to was to create a custom disk cache and custom downloader.
In custom disk caching class, in the method where UIL write byte stream to file, I encrypted the byte stream.
and In custom downloader, I override the method where it take byte stream from file and decrypted it.
I'm developing a "Contacts" application, and I'm not sure what is the best type(Database or File System) to save the contact image. Can you guys please guide in the right way.
Thanks.
As an L1 cache I'd use a Bitmap memory cache for image caching during the application's upkeep. Read the Android guidelines regarding bitmap caching.
For persistence (L2 cache), I'd save the images as byte arrays of the encoded data, since bitmaps are super huge. Check out this question.
depends but for you, the best type will be database.
You can see,
http://developer.android.com/guide/topics/data/data-storage.html