I'm a newbie and couldn't find anywhere, concise information regarding which approach I should be taking when working with images.

The thing is I'm developing an app whose main purpose is to keep track of things, for each of whose entry you can have an associated image. This image is to be selected via gallery through an intent with ACTION_GET_CONTENT and receiving it in onActivityResult(...).

This last part became somewhat complex since from KitKat when you do something like:

Uri uri = data.getData();

and then uri.getPath() or uri.toString() you get something like /document/image:151. This path for sure you can't save it to SQLite DB, or if you could it wouldn't be of any use.

This brings me to my real question. Which is the best way to store this?

  1. Duplicate the file in your sd app folder from the stream
  2. Create methods with content resolvers for getting the real path (probably using as guide aFileChooser lib from Paul Burke)
  3. Save the image as a bit array directly into DB. (this one sounds like a bad practice from my experience, but I've seen a lot of people doing it)
  4. Other (specify)
  • I don't know what you mean by "concise" information, but the to store images in db or not has been debated often. There are pros and cons that you have to apply to your app; no one else is going to know as much about it as you do to tell you exactly what to do. – JeffO Nov 5 '15 at 16:51
  • @JeffO by "concise" I mean there is no list of pros and cons nor use cases for each approach – user202937 Nov 5 '15 at 19:22
  • Can you provide a link you looked at? This one on this site (and it's a duplicate) seem to have a few: programmers.stackexchange.com/questions/261243/… – JeffO Nov 5 '15 at 19:26
  • It seems i need to refine my search skills. Thanks – user202937 Nov 6 '15 at 1:28

URI is a universal means to identify resources. It's not just meant for files. So, naturally the URI string doesn't look like a path.

You can save that path into SQL DB. You just can't create a File instance using that String.

From what I understand, you need the images to be displayed as part of entries in some list.

URIs should be openable as a stream using ContentResolver.

You should refer to this question :


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.