Loading files from web - android

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.

Related

Bundle app with files located in internal storage directory instead of assets directory?

I am building an app which will contain media files that are bundled with the application.
Users will also be able to download additional media files at runtime.
I want to store the downloaded files in the application's internal storage directory.
Is it possible to "bundle" the initial files in such a way that it is also stored in the internal storage directory, or will I need to place them in assets, and thus have two different ways of accessing my media files?
Is it possible to "bundle" the initial files in such a way that it is also stored in the internal storage directory
If you are looking to have them be placed there automatically, then no, there is no option for this.
will I need to place them in assets, and thus have two different ways of accessing my media files?
You are welcome to copy the assets to the filesystem yourself (see AssetManager). You would treat the filesystem as the "system of record" and only copy things there if needed (e.g., first run of the app, after user does "Clear Data").

About reading data from files to construct setting for application

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.

Android folder to store media files and access them via an absolute path

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.

How to provide some resource files for an android application?

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.

Best storage file for existing images which is writeable in Android

I have a database which contains Image paths. I have access to the existing Images by these database paths.
I also need a folder containing Images which are writeable to modify the images.
Besides "assets" files are only readable, so I can't change them. Therefore the "assets" folder doesn't work for me.
What is the best file storage in this case?
My solution was to save images in assets and then copy the folder in an internal storage, but it takes a large amount of memory.
The best way is to save the files in internal or external android device.

Categories

Resources