Using Fresco + S3 in Android - android

I need a way to show several ( maybe 20-30 ) images on screen on an Android application i'm working on.
Considerations:
My images are stored in AWS S3.
The list that displays these images is implemented using RecyclerView.
After some research, i've decided to use Fresco to show and cache these images, but now i realize that i need a Uri from said S3 images.
How can i accomplish this?
Maybe using the newer TransferObserver.download(); and just display the images is better? But again, caching and recycling gets in the way.
Is there something super obvious im missing?
I've tried to use the link given at the S3 GUI but i get access denied, of course. I haven't made these images public because of security reasons.

Fresco does support content provider URIs. So you could write your own content provider that in turn wraps an Amazon TransferObserver.

Related

Using Amazon S3 TransferUtility files as image source for Fresco

I have a set of images that are being periodically uploaded to an Amazon S3 bucket. I need to display these images in my app. As opposed to manually writing code to handle aspects like multi-threaded downloads and caching I wanted to use Fresco to do this as I'm already using it for other tasks within my app. This answer mentions that it's possible to do this by writing a custom content provider which wraps a transfer observer. However, the specifics of doing this don't seem to be clear.
A bunch of tutorials about writing a custom content provider available. For instance: https://developer.android.com/guide/topics/providers/content-provider-creating.
Another option might be to implement a custom network fetcher which handles special URIs and queries S3 underneath: https://frescolib.org/docs/using-other-network-layers.html

Persistent/Offline Image cache in Android

I am trying to figure out the best and the most efficient way of caching images to the disk, such that they would persist even after app is killed and re-launched in airplane mode. Consider the following use case:
Open the app and get all images and display them in their respective ImageView's
Kill the app
Put device in air plane mode
Open the app again.
I am trying to get the images to persist in an offline cache so that they can be displayed in the scenario mentioned above.
I went through documentation for picasso and glide and it wasn't exactly clear if their disk caching would work in this case.
Is there a way to do this using picasso or glide? I am trying to avoid having to write a custom implementation for storing this in SQLite etc.
Glide will do this for you by default without any extra work on your side. You can also customize what versions of the requested image to store in the cache.
One important thing you need to consider is if the URLs that you use Glide to fetch images from are available offline otherwise you will need to have some way to cache those as well so that you can initiate the Glide calls when you are offline.
You can see how I did it in this project: https://github.com/KhalafMH/popular-movies-android.git
To read about how to configure Glide caching see:
http://bumptech.github.io/glide/doc/caching.html

Load multiple images with Glide on Android

I want to make a simple gallery app on Android (like Google Photo or any standard gallery app). I've read that the best way to load images is use Glide library (Google recommends to use it). But how can I load multiple images (from sdcard) using Glide? I can use Glide.with(ctx).load(File file)... for loading single image, but I dont know how to load multiple. And what library does Google Photo uses (it works really great both with local and with cloud images)?
So, the only one way to load images with Glide is to load them one by one using Glide.with(ctx).load(File file)...
But it's not a problem to use it even if we have a lot of images - it works perfectly. And it seems that Google Photo app for Android uses Glide, that's why Google recommend using it.

Android best way of caching images

I am making an attempt to build the most efficient way of caching images downloaded from the web for my app, a few years ago I tried to do this and could not find an efficient method of making this work until I stumbled upon the lazylist adapter found here:
Lazy load of images in ListView
this worked well until android 4.0 was introduced, at this point the app would crash after loading 10 to 20 images, as opposed to before where I could simply load up as many as I wanted without any issues, this I later found out was a result of the Ice cream sandwich having a set limit on memory usage per app, which didnt exist in Gingerbread 2.3 and below, I eventually decided to just clear the cache every 10 or so images to avoid crashing, however the user experience wasn't very good as a result of doing this and the app used tons of data as it was constantly redownloading images over and over again that were already viewed, I have since attempted to use an lru cache but this does not seem to work at all, especially when I leave the app and relaunch it the images are all released it seems, I need a better way of doing this and I have noticed that other apps such as instagram seem to have found a way to cache hundreds of megabytes of images, Im consistently having to manually clear the instagram cache in my settings because it seems that they are to able to store an infinite sized cache that seeming never ejects its contents, does anyone know how to build this kind of cache?
You can try using https://github.com/nostra13/Android-Universal-Image-Loader
library. This does most of the hardwork for you.
the way I wold suggest would be to store the images from the web to the sdcard or something then store the URI where the mage is located. The in your list just load the image from the uri.
If your images are big in size you should probably rezise the image before you save it so that you use less memory and it will load faster since the processing has already been done
BTW the memory limit always existed in android

Idea to download images in android

I'm making an android app, here the images are getting from Cloud, is it good idea to download images and save it & use it further. Or download images every-time user uses the app, what idea you prefer is the best?
Because downloading images always is slow & its bad i know but at some point if the images are updated then how to get to know about it?
You should definitely cache your downloaded files!
Do it in your internal app directory where only you do have access to (or otherwise external storage, thats still ok).
Bandwidth and connections are always expensive and should kept low as much as possible.
So your user can see images fast even on a bad connection and your app doesn't waste his valuable bandwidth of a users data plan.
Maybe this could also help you:
https://github.com/novoda/ImageLoader
http://www.androidhive.info/2012/07/android-loading-image-from-url-http/
Make it easy on yourself and use something like Android Smart Image View. It takes care of loading and caching, and it's just about a drop-in replacement for Android's ImageView. Universal Image Loader is another alternative, more configurable, but not as quick to implement.
I used https://github.com/nostra13/Android-Universal-Image-Loader
but I think you not want only download and cache.
these no trick ,if you want check weather the image update or not, you can add metadata for image, just like md5 .
in html and browser, you can set expires header for a image:
enter link description here
but in android app, you control all yourself.
Downloading images and saving them is probably the best way to do it because you don't want to download the same images over and over. If the images are updated you can delete the older one and download the new ones. Just make sure you don't download/save a million images. Take a look at this library. It has a built-in cache on sdcard/external sd.
Downloading images from the net for display, with possible requirement of caching is a very common problem that many people have solved, you can try these solutions to see which fits you:
Ion (https://github.com/koush/ion) - very flexible and feature complete, plus it can download more than images but JSON, Strings, Files, and Java types as well. The part that I really like about this is that it can automatically cancel operations when the calling Activity finishes, so users don't waste time & bandwidth downloading images that will no longer be displayed
Universal Image Loader (https://github.com/nostra13/Android-Universal-Image-Loader) - equally capable for most use cases but for downloading/caching images only

Categories

Resources