I have an application which downloads the image and saves in the sdcard of the device and meanwhile it saves the name of downloaded image in the database along with their path (this path is a physical path on device)
Why I am doing this? It has only one reason and that is not to download images again and again from the server. But as I am saving them in the sdcard then they are showing in the Gallery. So there is chance that user can delete some of the images or may be all of them. (Due to some reasons I am not saving them in app folder)
So what I want
I want couple of things that can be simplify as following
I want to see that if any of the image has been removed/deleted by the user, if so then I may download that also and then I will update my Grid view accordingly. If there is no deleted image then it should show normally.
I searched on internet and I found one method to check if the file is still there "myFile.exists()" but do not know how to use it in my case.
This is the worse point and could be hard of my logic, what Is going on now is I open my activity and it takes the image path from the database and fetch the image into the imageview. but what If there is sime 1 present , image 2 present but not image 3 , image 3 is deleted by user , then Now How to adjust this thing , as we are in the adapter of the gridview, how we would wait and download this image and would fit it at that place ?
Please tell me How to do this and How to check if any of the file has been deleted. ?
Related
Lets say I have an App that allows me to rate mugs. Therefore, I enter some rating criterias, take a Picture of the mug and then save it to a DataBase, to look at it later.
At the moment, I save the picture on a path obtained by
getExternalFilesDir(Environment.DIRECTORY_PICTURES)
and save the path to my SQLite database to look at it later.
This works fine, however, as I rate a hole bunch of mugs all day and change my phone quiet often, I want to be able to backup my App and its data by common Android backup solutions. This works fine with the SQLite Database that holds the data and is stored in App-Context.
But since the database just holds a path to the taken picture (as returned by getExternalFilesDir), the picture is not backed-up. Where do I have to save the picure, to ensure that any common Android backup software will also grap the pictures?
Is it possible to ensure that the path stored in the database is the same, after I put the backup on a new phone? Since it may be possible that the App is located somewhere else on the new phone, absolute paths are not a good idea here... Is it possible to save the picture relative to the App and just save the relative path?
As suggested by greenapps, a possible solution is to save just the relative path of the image in the database. Instead of using
getExternalFilesDir(Environment.DIRECTORY_PICTURES)
I now use
getFilesDir()
to get the app intern folder and save images there. When I want to load the picture I build the path with the same method to get the app dir and the relative path saved in the database.
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
I'm working on a feature that lets users select their own background image in an app.
Should that image be copied into an app associated folder after they selected it or what's convention for this?
In this case the user has freedom to select a picture from the other folder hierarchies and that picture can be deleted by the user. So you should save a copy of that image in your application folder and decode that picture to use as the background.
But the user can repeat this operation several times and saving a copy of each picture will consume a lot of space so, you should just create a single file that will be overwritten each time the user selects a picture to change the background.
And you need not to have a very high resolution image. You should down sample the image and then save it.
Follow this link for effective bitmap decoding.
I want to do this. my app has many screens and in each of them, on the top, I display an imageView as a logo. So I have 20 screens and that means (20*3) images in my drawable which makes my app be many Mb's. Because this image is static and never changes I want to do this: Getting it from the web (I know how to do it, I am not asking this) only for the first time this screen is ever launched, then this image be stored somewhere in user's device and then use that path as a source. (I mean not download it again, because it will be annoying for the user waiting every time). So is it possible? Will it make my app go slower (not the first time, but the rest) because I am retrieving data from SD?
Yes, you can do this fairly easily. You also do not have to store the data on the SD card necessarily. You can store the image in the internal storage.
Basically, set up a cache directory. When you need the image, check the cache directory, and if the file is not there, download it over http and store the file in the cache directory.
It will change how you get the resource (e.g., you won't be able to use R.drawable.imagename), but you can just load the drawable programmatically.
So, the thing is that i've downloaded a couple of photos and stored them in the data/data/project/username directory on the phone and I want to display them (without having to download them again first) every time the user with username is using my application.
So've created a linkedlist with the paths on the phone where these photos are stored and every time a new photo is downloaded I add it to this linked list. Every time the activity is created/stopped i deserialize/serilize the list containning these links.
The serilialization part seems to be working ok, since I checked and the deserialized list seems to contain proper links to the the photos on the phone, but nonetheless when I start this activity nothing appears on the screen (before that I was downloading the photos every time the user logs in and they were displayed properly and everything was fine) and there's no error bumping in logcat or whatsoever. I first thought I had some typo when adding the photo urls to the list, but i checked and everything seems fine. Any ideas? (think)
Flickr photos have unique IDs. When you save the photos on the internal storage of the device, use their ID's for names (for example 123456111.jpg). When the user reconnects to Flicker, just check each image in his gallery if it is already downloaded.
It is good to use getCacheDir() for your cache directory, because it is automatically managed by Android.