I'm writing an android application, which user can download some image files from server. There image files will be stored in android mobile.
Now I want to put some of image files inside the apk file, that user can start the application quickly after installing. I found I can put them into assets directory, but the directory is read only. When user download other image files, I need to store them into another directory.
So there will be two directories to store the image files, but they are the same type.
Is there any good solution for this case?
Check out http://developer.android.com/guide/topics/data/data-storage.html#filesInternal for a listing of different places you can put data on Android.
You should put downloaded image files into one of three places, depending on your needs.
If the images are meant to be viewable by the user (e.g. downloaded photos), put them on the external storage. If they are meant to be user-interface elements or other crucial (but not user-facing) images, put them on internal storage. If they are meant to be cached for quick access but downloaded if necessary (e.g. temporary images like those found on a website), put them in the internal cache directory (Context.getCacheDir()).
If you don't have a lot of assets, you can copy them to the target location when your program first runs (e.g. check for the existence of a certain file, and create that file when you are done setting up). Then you only have to check one place (unless it's the cache dir, in which case you can't guarantee that the files will stick around forever).
If you have a lot of asset files, I would use a two-stage lookup: consult your downloaded image directory first (so you can override builtin assets, for example), then consult your assets directory. This is also flexible enough to allow you to make use of multiple storage locations should you find the need.
Related
Using PhoneGap 3.2 and the File API, I'm downloading a set of images to display in the app. I create a folder named "Appname" and put all the files there. On Android this folder is accessible through the file manager, and on some models the images show up in the users image gallery.
Is it possible to save files locally, but prevent them from showing up to the user outside of the app?
Technically, no. Especially if the client has root access.
You may try the followings to mitigate the problem:
a) Name your files to start with a DOT (.) so that it is recognized as hidden file. (Still, a file manager configured to show hidden files can show it).
b) Store the file instead on some databases in the /data/data/your.app.packages path, which is by default only accessible to your app. (Still a root user can see it).
c) A linux trick. Create a file, open it, hold the file descriptor but remove the file. In this way the file is removed from the directory structure so that it doesn't show up in the FS layer (and thus inaccessible). To make it permanent, use the file descriptor you hold to create a link (or dig into the /proc directory tree to make links with files under fd.
Since this trick works on linux, I guess it should work on Android. But it's probably overkill.
d) Other stopgaps include encryption, obfuscation, etc. But they don't exactly fall into the kind you are looking for.
I'm developing an ebook reader app for Android. The special books for this app are zipped files of some html/css/js/image/... files which are in a server and will be downloaded by the app. Each zipped file may have 1-5 MB and if extracted, a lot more than that.
I was wondering, regarding to android guidelines, where is suitable to
Put the zipped book files?
Put the extracted files when they are being used?
Well, if you actually need to save that data when app finishes, you should use sd-card, since it has more space, but if you only download image one time, just to show it on screen than use internal storage. Also consider your lowest API since that will be phone with least storage, and your app needs to work there as well as on new devices. Either way if you have to make several files while extracting data, use internal storage because it will be faster, and move it later to sd card if you actually need to save it.
I making an application with phonegap/cordova where I need to keep a lot of files up to date. Some files (mainly images) will need to be erased in time, and some new ones will get downloaded. The thing is, in Android, to manipulate those files, it seems I need to have them on the sdcard; so I copy the files the app starts with from my assets folder to the sdcard. It just seems like a waste of memory space.
Do you know if is there anyway I can start with the app having those files the app starts with already inside the sdcard? or at least somewhere I can delete them later?
Thank you.
Files that are delivered to the device as part of your APK will be stored in a form that cannot be modified by your application (other than by updating to a new version of the apk).
If you copy the files out of the APK into the private internal storage area or the external storage area, those copies can be modified, but the originals inside the apk will remain.
The most efficient solution may be to not put these files in your apk, but have your app instead download them separately on the first run, using whatever mechanism you wanted to use to change them in the future.
(Some people object to this feeling that such files are less secure against unauthorized use, but as the contents of an .apk are trivial to extract this is not a strong argument. Needing to maintain a server to download from is a slightly more substantial objection.)
You do not need to store the files on the SD Card. Each app has its own internal storage that is not accessible by any other apps. For more information see the official docs: http://developer.android.com/guide/topics/data/data-storage.html
I'm creating a simple Android App, it will be a map with a number of points marked on it. These points will sometimes change, based on an XML file hosted on the internet.
To reduce the initial load time my intention is to distribute a serialized List of these points with the application that can be updated in the future.
At first my intention was to distribute this serialized file as an 'asset'. This way I could just generate the file and drop it in to 'assets'. However, this does not work because (from what I can see) it is not possible for me to overwrite these assets.
The second option was to use the internal storage, however (from what I can see) I can't distribute this file as 'internal storage'.
Is my only option to distribute my serialized List as an asset and then on the initial load copy it to the internal storage? The files only going to be around 50kb but it seems unnecessary to have 2 copies of the same file (1 of which will eventually become outdated) as part of the same application.
How about always first checking the internal storage and if your data does not exist there read the 'asset' version.
Then you will have a syncronization job that will download the updated file (when available/updated) and put it in internal storage. But yes I guess you will be stuck with always having the original file there.
I have the following situation:
I have files under raw directory. I use them to load them to textview.
I want user to load files from web to be used the same way.
Is it possible? Or do I need to load them to SD?
If so - on the SD - how do I prevent reading\copy of these files (in raw directory it is not reachable).
You can load files to the SD card, to internal storage, an SQLite data base, or as a Preferences object. This is discussed here, including security aspects.
What you cannot do is dynamically add to the resources or assets folder that ships with your app.