I need to store and read objects in Android, these Object must be available until they are manually deleted through the app.
Since I cannot use the assets folder for this,
How could I store objects in an hide folder to access them in future?
Well, you can keep them in your app specific directory in SD card. If you want the content inside your directory should not be scanned by mediascanner (so that they will not appear in Gallery etc), you need to keep a ".nomedia" file in that directory.
for example, create a directory called "mytestapp" in sdcard, and keep a ".nomedia" file there, along with the files you want to store
Related
I have a question, I want to ask about reading data from files to construct setting for application.I want to download new files from the server to replace the files in the asset folder, but the files in asset folder doesnt allowed me to replace them, So I want to know is there any other way to do this ?
The assets folder in Android, are readonly, you can't add or edit files. So, if you want to use internal data files and replace them with a download, you have to set another directory, such as Internal Storage or External Storage.
I'm working on an Android application that needs to store media (document files like pdf or so for later reading) but the main requirement is that all media files have to be accesible through an absolute path (a physical path on filesystem).
I'd like to avoid copying files to external storage (like sdcard or phone internal memory) so to prevent that if application is uninstalled those files remain in phone (and of course to avoid duplicating the size in kb for each file) and instead to keep files in iny App internal resources folder, but tried "file:///asset_folder" whith no success. As far as I know "file:///asset_folder" only Works for a webview to Access www folder but not for regular files.
I'm not sure if there is any app internal data folder which I can access through an absolute path or if not which is the best way to store App resource files.
Thanks in advance!!
Edit: To make it more clear, the resource files are already bundled with the App, and not written during runtime, and what I'd like to know is where to put them so I can later Access them via absolute path for Reading.
To retrive your app specific data
openFileInput(file_name)
To save your app specific data
openFileOutput(file_name, Activity.MODE_PRIVATE)
Update : Read from asset folder. (InputStream)
getAssets().open(fileName);
getAssets().open(fileName, accessMode);
check the image to where to put asset files
now to make other app readable your files from private data/data directory use content providers.
You can not write data inside asset_folder because it is packed on apk file. You can use sd card or location where your app is installed inside internal memory.
In my application, I have created a bitmap and save it as a JPG image in the SD card. I don't want any other apps to use this image. Is this possible in android ? Any help will be greatly appreciated .
Unless you encrypt the file, there is nothing you can do to prevent access to files on the SD card.
(See the section on external storage here)
Files saved to the external storage are world-readable and can be
modified by the user when they enable USB mass storage to transfer
files on a computer.
Instead consider putting it in internal storage, then your application will be the only one that can access it.
Another option, if you only need to hide it from media scanners is to either give it a name that starts with a dot (.myfile.jpg) this will make it a hidden file. (if you have multiple files you want to hide this way, include an empty file with the name .nomedia (see Saving files that should be shared) so you don't have to rename them all)
When storing the image, change the extension of the file to something else, so other apps would not recognize it. But when you want to use it in your app, change the extension back to .bmp or .jpg!
Use an application specific database and save your images there instead saving it on the SD-Card. Then only your application has access. I'm doing this to encrypt the images in my application, just saving a BASE64 encoded image string doing crypto stuf on it and vice versa. This would also work if you save a Byte Array of the image file.
Method 1 – Creating A .nomedia File .
Using any file explorer/manager application (such as Astro File Manager or File Expert), navigate to the directory that you want hidden and create an empty file titled “.nomedia”.One way to do so is to:
Copy an existing text (.txt) or even an image (.jpg/.jpg) file to said directory,
Open it in a text editor (hold down on the file and select the appropriate option from the context menu that appears),
Delete its contents (hold down on the text, Select all and Delete), save changes and exit,
Rename it to “.nomedia” (hold down on the file again and select Rename from its context menu).
This method disables media scanning on the chosen directory, causing the Gallery to skip the directory altogether at launch.
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.
I am creating an app that could potentially be used in multiple educational establishments across a variety of courses with tutors who will want to be able to update some of the information within the app themselves on an ad hoc basis. I originally thought that the best way to do this would be to have the application download a new strings.xml file to the res/values folder, though I have read that you cannot update this folder/file whilst the app is packaged and running. I think a good work around for this would be to be able to save another strings.xml file elsewhere
My questions are:
Is this at all possible?
Where would I go about saving the strings.xml so that it is not
packaged when I export the app?
note: The file will not be called string.xml so there will be no confusion etc. with the actual strings.xml.
There is no "rule" of where you should put the file (minus, of couse system and other private folders you can't access). However, the logical and most common place to put a non-packaged resource that your app downloads would either be in your own applications data folder (located on the internal storage of the device) or on the external storage of the device (SD card).
To write your file to the internal storage you will need to use the context's openFileOutput(..) method. This stores the file within your apps private data directory. Use openFileInput(..) to read your stored file
To write to external storage you will need to add the WRITE_EXTERNAL_STORAGE permission to your manifest. After doing that, you can use FileOutputStream to write your files data when downloading. InputStream for reading (look up which input stream type would be most suitable)
Obviously, the examples I'm giving aren't fully detailed or have code but they will guide you in the right direction for storing files on your device.
Files under the res folder are used by the compiler to autogenerate the R class that contains the ids of the strings,layouts,drawables etc...
Of course you can download a custom resource from your server and stored it in the SD as #dymmeh points. And is the most reasonable way of to achieve modification of literals but be aware, you will not be able to use the #string/string_id in your layout's xml and you will have to parse the downloaded file yourself.