I am working on a project where I am having an ExpandableListView populated with Items and SubItems. When I click on SubItems, I have to populate relative images into the gridView. All the images are saved in Assets folder and I have to put there path in an external SqliteDatabase which I have created using sqlitedabase browser.
So my question is, How to save Path of images in database from Assets folder.
BitmapFactory.decodeFile("file:///android_asset/image/test.jpg")
Though storing Images in the Assets is not the best way to go. You will not be able to take advantage of the Android resource management system. So unless you have a compelling reason to do this, I'd suggest that you take a look at using the res folder and the resources system.
BitmapFactory has a method to decode a file via the decodeFile method.
Android lets you access a file in the assets folder via the file:///android_asset/{path} path.
if your file in assest>image folder and your image name is test.jpg
then file:///android_asset/ is original path plus you need to mention remaining structure like file:///android_asset/image/test.png
Related
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
I want to get images name from database and images are stored in the resource folder
Could you show me how to do it.
I tried few methods but none works.
You cant do it, resource folder is read only folder, and the R.java also generated at compiled time, not in runtime. You can save the image in sd card or cache memory .
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
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.
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.