Android SDK Save image to drawable - android

Is is it possible to save downloaded images from my site into the drawable folder? I've preloaded the images, but how can I save them for later use?
Thanks!

You can't save anything into the drawable folder. What is packaged at compile time is all it'll have.
Instead, you can save the images to the external storage, or into a database or into internal storage.

No, because there's no "drawable" folder at all. All your drawables remain in APK file after installation and your APK file is read only hence no modification of any sort is possible. Use SD card or application storage for storing files.

Related

How to set an image in assets folder from Url in android

I am planning to show some image in my app. Also, this images must be in assets folder. First I will upload images into assets folder from url, and when app runs, must show this images from assets folder. Is there any possible way to do this ?
The assets folder is read-only the images you get should be saved to a spot on the device then referenced by its path
there is a detailed explanation here for how to save image to internal directory and load them

Where do you put downloaded filed in android

My application downloads files from the server and save them somewhere. Where should I put the folder to save the files? Not in assets right? Should I create a folder somewhere parallel to "bin"/"libs"/"res" folder?
Another question: should I put the downloaded files in internal storage or external storage?
Actually you can not save the downloaded file in either of this folders because they are not allowed to make modification at run time.
Best option goes according to your requirement, as if you file is too large and you are not much worried about it's security then you can store them on SDCARD(External storage). and if your file is small enough and much secure then you should save them on internal storage.
Check most popular application store their files on SDCARD but encrypted way...
Hope this ans your question
Store your downloaded files in a folder on an external storage directory. like
String yourFolderPath = Environment.getExternalStorageDirectory() + /com.yourapp/;
Store files in that folder.
if its just few files, it would be safer and more convenient to use the context.getCacheDir(). with it, you can be sure that it will always be there unlike sdcard which can be locked when the phone is in storage mode. it doesnt require manifest permission. You don't even have to worry about security unless your user is rooted.

Loading JPEG from RAW resources

I need 6 large images in my app. And I don't need the quality and alpha channel provided by PNG. Is there a way to embed JPEG files into the raw resource and unfold them into SD card at first launch of the program? It will save me 3-4 MB in my APK. Thanks!
It's very easy. Put your file in res/raw filder and use:
InputStream is = getResources().openRawResource(R.raw.image);
BitmapFactory.decodeStream(is);
You can simply open the stream and do whatever you want with the data.
I think I don't understand your question: It seems that you want to hive off image files at first run...
Anyway, I suggest to put the files in the assets folder and not in the resource. You can access the assets as a file system and copy them to any (permitted) location.
Have a look here:
Difference between /res and /assets directories
and here (look at assets):
http://developer.android.com/tools/projects/index.html
EDIT:
My answer suggests to use assets instead of the resources but, you can't modify your apk at runtime, look here:
how we can remove a file from the assets folder at runtime in android?
Nothing prevents you to put JPEG images in the resource folders, or in the assets folder if you don't need the R.drawable.MY_IMAGE thingy.
However, the images would still be included in your APK, and cannot be removed from your application package even after you copied them to the SD card.
The only way is to download the images separately from a web server on your application first launch.
The Google Play Store also provides some facility if your application needs big files, but that seems a bit of an overkill

Save a (.txt) file to the Assets Folder in Android?

How to write to .txt file in assets folder.
How to get path assets folder ?
You can't. The assets folder is read-only at runtime.
Pick a different location to save your data, see Data Storage for more information.
The path of assets folder is file:///android_asset But this is read-only.
The assets folder is like folders res, src, gen, etc. These are all useful to provide different files as input to build system to generate APK file for your app.
All these are read-only while your app is running. At run-time you can only write to SD card.
I hope you understand my answer.
Not possible,
Better you choose internal storage to save your txt file. Internal Storage. Hope this will help you to understand.
No you can't do this, because of if you read and write both at runtime then everything could be change and application will behave unexpected which could be harmful or may be crashed. i suggest you to use internal memory, sqlite and app SharedPreferences etc.

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