How to implement imageswitcher code in android application? - android

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 .

Related

Upload images in Gridview from Assets folder via sqlitedatabase browser

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

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

How to display any of 50 small images stored locally with application in a single dedicated folder

I want my program to be able to list all the 50 images that are in a local directory and access them at run time. I have tried to store them under the res folder, such as in Drawable, but have found out, according to one source, Ivan Memruk (here) that you can't refer to res folder subfolders by their folder names, because the folder names are all ignored -- you have to just use unique names for all your images and then refer to them by that name and using the whole R and resource id thing.
Also, according to that same article by Ivan, you can use subfolders under the assets folder, but then you can only access the images in them using an input stream, and (apparently) that is not of much use for accessing images.
Whoo, well all that said, does anyone have any other thoughts on an easy way to list all the images in a folder? I don't want to use the SD card by the way as my images will be shipped with the application.
Thanks in advance and thanks to the people who answered before I updated my question.
Store the images in drawables folder. But maintaining their identifiers (R.drawable) is a problem. You can get the identifiers anytime from :
getResources().getIdentifier(imageName,"drawable", context.getPackageName());
This will return R.drawable value of image.
The advantage of storing images in drawable folder is you can store resolution specific and orientation specific images.
You may use the assets folder for this purpose, remember not to name the images folder within assets as images, otherwise some extra images will come up in the image list when asked for. Instead try to give a unique name like app_images, etc.

How to download a image to a drawable folder from a url?

I would like to add a image to a xml image view, and needs to be updated on timely basis.Whether is there a possibilty of updating directly to the drawables or how to do it from device memory i.e. downloading & calling from internal memory to the xml imageview.Kindly help me with an example or a snippet.Thank you.
Not possible. You will have to save image either to the SD CARD or the
data/data/package folder. You can not write/save image in drawable/res. Sorry.
You cannot update drawable folder.Only thing you can do is save the image in sdcard or in application memory ie /data/data//image.png.To set the image dynamically you can get reference of your image in your activity using findviewbyid and then set its image wherever required.
Research a bit before you ask a question...
During runtime you do not have access to your projects folders, as they are compiled to .apk file and that file runs on the device, now how on earth can you modify those folders while your app is running?
Try downloading it to your SD card or internal memory instead...

get images from memory card and store in drawable folder

I made a application in which many images are shown,
all images are pre-stored in drawable folder of resources,
but if i want to add new picture then how can i do this,
it should read from memory card but only once, after that it automatically load.
If I understand correctly, you want to upload images yourself to the app instead of letting user use images or..?
If it's you, who should upload new images, you can download them to the app with a check if there are new ones.
If it's the user, you can check their gallery on the sd card, but unfortunatly I don't think it's possible to store these in the drawable folder.
You mean you want a dynamic drawable folder? You cannot do that since APK file is read only...
you cant do this, because it is an impossible act, Drawable folder is meant to make the Application Environment when it is deployed, it is a one way process. you can copy Drawble image to external path

Categories

Resources