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
Related
I want to implement an art game android application in Android Studio. But I'm confused about how to store the pictures? There will be 100 or more pictures of art works in game. The idea came to my mind is to minimize the sizes of pictures and adding them in drawable folder. Is there any efficient way to do that?
Thanks
First of all use TinyPng to compress your images without loosing ANY quality, I said ANY and I mean it.
and second don't put them in drawable because android will increase there sizes when you will generate signed APK, instead you should put them in raw directory which you can create in res directory, like res/raw.
Raw directory works same as drawable and any files in this directory gets resource Ids just like drawables so you can access files in it just like R.raw.yourimage.
I work on applications which includes hundreds of images and this is the best approach I have used.
Hope it helps.
If you are concerned with the space the 100 images takes up you could use a tool like photoshop or similar so compress your images to desired size (publish to web in photoshop).
Other than that I dont see why you shouldnt just save them in a drawable folder.
My Android app creates a folder on the users device's external storage on launch:
File images = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "rapical" + File.separator);
images.mkdirs();
I have around 16 image icons (.png) that I would like to place in this folder the first time the user opens the app.
What is the best practice to do this? Should I place them in the drawable folder initially and then copy them over to the newly created images folder? Not sure what approach to take!
There are two separate issues here:
What to do with images that the user adds to your app?
What to do with your starter images, for your default foods?
Using external storage for the user-added images has some implications:
Your app can survive that image no longer existing, since the user, or other apps, can delete that file at any point
Your user does not mind that the image will get picked up by other apps, such as photo galleries
Unless you specifically want these images to be user-manipulable outside of your app, I suggest that you use internal storage for the "re-sized, compressed and stored" user-supplied images. The original image might be on external storage (I assume that you are using ACTION_GET_CONTENT and/or ACTION_OPEN_DOCUMENT to get the image), but your modified copy would be private to your app.
I sincerely hope that you are using an image-loading library, like Picasso, for loading these images, since they will handle things like background threads and ListView/RecyclerView image recycling and stuff for you.
In that case, what you store in the SQLite database for your default foods needs to be something that the image-loading library can interpret, to bring in the image that you want.
In that case, I would suggest using assets/ to ship the images and file:///android_asset/... values in the database. file:///android_asset/ points to what amounts to assets/ in your project, so if you have assets/chicken_pad_thai.jpg in the project, Picasso (and any decent image-loading library) would be able to interpret file:///android_asset/chicken_pad_thai.jpg) and load the image.
This saves you from making duplicate copies of the images, saving the user disk space and time on first launch. It also means that if you replace the images in your app (e.g., you get a better photo representing chicken pad thai), the user will start seeing the updated image, without you having to do some extra work to realize that you shipped a new image and have to copy that image out to a file somewhere.
Now, suppose that you really do want the user-supplied images to be on external storage. In that case:
Probably rather than the directory that you chose, I would go with getExternalFilesDir() (a method on Context), as on API Level 19+, you do not need WRITE_EXTERNAL_STORAGE as a permission
If you want the user to be able to manipulate the images of the default foods, then copy those out to that location on first run
I need to make an application, which will be a gallery of several pictures, supplied with the application when downloading app from Play store.
Could you suggest how this is best done in the future to facilitate the addition of new images?
I know how to do to gallery took the images from a folder on your device, but how to put these images together with the application from Play Store? We need them as a resource to unpack?
Thank you!
You have 2 basic options.
Download images from internet on runtime - supplied by your server which you can control and therefore add new images without the need of updating the application.
Or you can just put images into your /drawable folder within app and every time you add new image there you update your app on play store.
if you put all the image in the drawable folder then the application is going to be very big. I would suggest putting the images on a image hosting cdn like cloudinary then use an image downloader to pick the images from the url and cache them on the device like Picasso or Universal Image Loader. Also you dont want to be shipping updates just because you want to add a few images.
I think there are 2 ways to do it:
(1) Put the pictures to web server. The apps can download the new picture from web server and store to device's local memory.
(2) Put the images to /Asset folder and submit app update to Google Play when you want to add more pictures to the Apps.
I'm not sure what you mean as a resource to unpack, but the simplest option is to include them as drawables.
If you do not want to do that, you can include them in the assets or raw resources directories. Assets is often used for some images raw might be used if you were for instance including some other format to unpack as you said, bit that comes with its own issues.
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...
I am creating an app that is fully concentrated on images. If I keep on adding the images the size of the application increases. I don't know what would be the exact size of the app but I think it might increase than 20 MB. I don't want such file size of the APK, because it is a simple and information based read only app.
So I have come up with an idea such that during the installation an SQLite DB would be created and in that the images would be stored from the drawable folder. That means the images would be transferred from the drawable to the SQLiteDB. The images in drawable folder will be deleted. This would make the app size smaller. Is this solution feasible?
After the app is installed, you cannot delete files from the drawable directory.