I'm using Universal Image loader to retrieve a lot of images from a server and showing it inside a listview.
Now when cache is full, library remove automatically some "old" images for free space to keep new on, so when i scroll "back" for see previous images (that was deleted from cache), library download it again.
This is a very big problem if library recover picture using a 3g connection.
What i want to do is:
-recover picture from link
-save pic in cache (library already do this)
-save pic into a folder on storage too
so when library need to show again an old picutre that is not still into chache, it could recover it from storage, and not from web.
It's possible to do it?
I think the batter way is you use UrlImageViewHelper you can download from https://github.com/koush/UrlImageViewHelper
it will handle automatically store the image in cash memory it's a better way to use this lib to load image.
Yes you Can First you have to store images in specific folder while doing activity for first time later you can put small piece of code to check that requested file is present on local storage folder ..... thats will solve your Problem
Related
Scenario
I have made an application that displays a list of predefined products to the user. Each product has an image associated with it.
Initially to display the Image on the app, I had used ImageLoader which utilities the Image URL. But it takes up a lot of the users mobile-data.
To minimize the users mobile-data usages, I was planning to save the images on the users device when the app is installed and occasionally(once a month) when new items are added to the list.
Question
When the app is installed or if their are updates to certain image items is it better to download & save the images directly in the cache or as a hidden folder in the device storage ?
In my research I realized that
In the cache : Lesser Viewed Images/Objects are evicted from the cache.
(I have a check in my code to see if the image to displayed is still in the storage, if not it will intern lead to downloading the image again.which i don't want)
In the device storage: It may not be ethical to hide Folder and Images on the device.
(the reason why the Images and Folder is hidden is because i don't want the user to view the images in their Galley or delete the folder by mistake)
My Goal
To ask your opinion for the best solution to the above scenario.
Weather to save the images in the cache, device storage or some other method.
My Aim
How to minimize the users mobile-data usages.
If the images of products are not updated frequently than you can save the images in the memory.
You can use the private folder of your application which is not shared by other application and the images which you saved is not displayed in the gallery.
The folder is inside the data/data/yourPackageName
You can get the path of the folder by below line:-
getApplicationInfo().dataDir
ImageLoader is using the cache memory to temparary save the images into your device so if the image is present in the cache it will not download again instead of that it will take from cache.
It totally depend upon you, if you save the images on the phisical storage and if their are too much images and you are not managing well than it might be possible that your application take to much memory of the device.
Hope it will help you.
You can use Glide or Picasso 3rd party libraries available which will reduce load time and once it is load it will cache image and display cache for next time.
Below is code to use
Add below in your app.gradle
compile 'com.squareup.picasso:picasso:2.5.2'
Source to load an image from URL into Imageview
Picasso.get()
.load("your image url")
.placeholder(R.drawable.placeholder)
.error(R.drawable.error)
.fit()
.into(imageView)
I have a scenario which I am not sure which type of storage to use. I have a viewpager where each pages required to save a bitmap in local device which user have drawn on the page. If I used application cache, the file in the cache will get deleted if low. If that happened, the user swiped to previous screen will be gone at some point.
If I used application directory itself, I have to manually remove all the files in that directory.
Is the second option a way to go?
You can use the application directory and on your activity/fragment destruction event where you have your ViewPager, , you can write the code to delete those files.
Use Picasso library which will manage images caching automatically,
It will restore the deleted image from the disk into the memory again when you slide back to the previous page , so you don't have to save the images on the application directory.
http://square.github.io/picasso/
I need to make an application, which will be a gallery of several pictures, supplied with the application when downloading app from Play store.
Could you suggest how this is best done in the future to facilitate the addition of new images?
I know how to do to gallery took the images from a folder on your device, but how to put these images together with the application from Play Store? We need them as a resource to unpack?
Thank you!
You have 2 basic options.
Download images from internet on runtime - supplied by your server which you can control and therefore add new images without the need of updating the application.
Or you can just put images into your /drawable folder within app and every time you add new image there you update your app on play store.
if you put all the image in the drawable folder then the application is going to be very big. I would suggest putting the images on a image hosting cdn like cloudinary then use an image downloader to pick the images from the url and cache them on the device like Picasso or Universal Image Loader. Also you dont want to be shipping updates just because you want to add a few images.
I think there are 2 ways to do it:
(1) Put the pictures to web server. The apps can download the new picture from web server and store to device's local memory.
(2) Put the images to /Asset folder and submit app update to Google Play when you want to add more pictures to the Apps.
I'm not sure what you mean as a resource to unpack, but the simplest option is to include them as drawables.
If you do not want to do that, you can include them in the assets or raw resources directories. Assets is often used for some images raw might be used if you were for instance including some other format to unpack as you said, bit that comes with its own issues.
Lets say, i am creating a news app and also fetching the images from server.
Which is best place to save those images? in Cache Directory or external directory? since those images might be 500kb or sometimes even 1 MB or less.. How to manage those images since those files are app specific and user can read news containing images in offline too..
Currently i am saving in internal cache directory by creating another folder inside cache directory. If i save it in SD Card then wont it create problem for the phone or tablet which don't have Memory Card?
Any Alternative best way?
Use this https://github.com/nostra13/Android-Universal-Image-Loader lib to loading images , it do a lot of work for you. To cache images you on sdcard just needed to properly set up ImageLoaderConfiguration and DisplayImageOptions fields.
I have to do some stuff. I'm downloading images using web-service, after successful download of each image, I'm using "AES" encryption algorithm to encrypt that images. I'have done encryption successfully. But whenever I'm going to open Gallery of device, I am able to seen that downloaded images encrypted by me. I don't want that. I wanna secure that images that can prevent access from Gallery.
I understood the whole process here.When I am storing each image after download Gallery capture that image and store into its cache so before my encryption process may be Gallery populate that images.
-> My Encryption process : Download Image - > Store into SDCARD - > Encrypting Image - > Delete the real Image
But this is not deleting from Gallery also.
So in short I wanna secure that images that can prevent access from Gallery. Let me know your best suggestion about my process is right or wrong? May I have to do a few changes on it? or have you nice idea instead of my process ?
Thanks for your best suggestions.
You must add an empty file to your images folder called .nomedia. This will prevent the MediaScanner from indexes images in that folder.
However, there is a bug on ICS that makes this slightly harder. On ICS, your folder must have the .nomedia present before you add images to it, or else the images will be indexed.
Another, slightly less compliant option is to begin your folder name with a dot (something like .foldername). As Android is UNIX based, this will make it a hidden folder, and hence not have the MediaScanner scan it.
I have got a proper solution. That will also work with higher versions.
You can keep it private with your application's private folder using following directory :
String mDirectory = getPackageManager().getPackageInfo("com.example.myapp", 0).applicationInfo.dataDir;
You can store your private data into this package. It will prevent access as well as prevent indexing from Gallery. So you don't need to worry about it's encryption process also :) . May be this folder will not provide much space. But atleast it will be help us.
Sounds like below solution might work for all versions -
(Storing videos, images and audio files that can not be accesses by others)
For this you have to store your data in External Storage with creating a folder name starting with the .(dot) then this folder is hidden from the FileExplorer.In this folder you need to create a .nomedia file and place your Images and video then images and videos are can not be visible to User in the Gallery.nomedia folder files can not be read by the gallery.