How to grab images from a folder on Android?

Asked

Viewed 1,016 times

2

I made an example of a ListView where it is used ArrayList to fill in the TextView and ImageView. But I’m improving it by taking data from a Mysql database, with respect to the `Textview all right, but as I would pull the images, I didn’t want to put the images in the database but upload to the mobile device that will use APK.

  • I didn’t quite understand your question in case you want to download the images to the application?

  • That’s right @claudsan, I wanted to send the images to the app, I don’t know if I’m right, but for that I would just throw in the drawable folder, right? but how do I have an index to fetch the images when popular the listview? Let me show how I am doing in the manual option:

  • public static final Integer[] images = {
 R.drawable.img1,
 R.drawable.img2,
 R.drawable.img3,
 R.drawable.img4};

  • @Jamesortiz The folder res/drawable/ is used to save files that are included there at project time, not at application runtime. In other words, you won’t be able to save images that your app downloads to it. When downloading an image from the bank, you will have to save it to a file on the device’s file system (internal memory or sd card).

  • @Piovezan the best way then would be to store the images in MYSQL?

  • @Jamesortiz First you stated that the images would come from a remote server (Mysql), now you’re asking if it’s the best way to store? On the remote server you can save as you prefer, in a database or as a file, available from a link to an image or even as a return of a webservice (REST for example).

  • @Piovezan, I think I expressed myself badly, I apologize. I have the database but only with text and would like to know how to work with the images. I found interesting the idea of the link, I will search if I find some help in Google on this. Grateful

  • @Jamesortiz I think the idea of the same link is better, and also in the case of the text it is better to come via webservice. Making the application connect to a remote database is not recommended, it is better for the webservice to do so and make it available in some format (JSON, XML, plain text or binary data, as the case may be).

  • @Jamesortiz Give a look here http://stackoverflow.com/questions/15549421/how-to-download-and-save-an-image-in-android this one in English but it has the full example I think will suit.

Show 4 more comments

1 answer

2


You cannot save images downloaded by your app to the folder res/drawable/ because it is intended to save images available to the application at project time, that is, before it is compiled. You will have to download them from somewhere and save them in the file system of your device, either in the internal memory or in the sd card. Also, making your application connect directly to a remote database to get data is not recommended, it is better to leave this connection to a web service (REST for example) that will make this data available to the application through a URL.

  • It’s definitely one of the best options for @Jamesortiz

Browser other questions tagged

You are not signed in. Login or sign up in order to post.