jucajl
jucajl

Reputation: 1195

Save image in SQLite database from Android

I have a question about saving images in an SQLite database location in the app.

I made an app for iOS where users can snap a photo or grab an existing one from the app that saves them in a local bank in own app, since the IOS does not have so many problems with disk space.

On Android already have code that takes the photo or use an existing one, now wanted to know how save them in SQLite database. (?)

I've been reading about and some suggest saving the image in SD card and insert into the database only the image path, but if for some reason it is excluded from the SD card will have an error in your application for the path referenced no longer exists.

What would be the ideal solution for this?

Upvotes: 1

Views: 4552

Answers (2)

Marius M
Marius M

Reputation: 496

You should only keep the name of the picture in the database and store the picture on the internal storage, not on the sdcard, save them in the first place as private to your application only.

Upvotes: 2

Flávio Faria
Flávio Faria

Reputation: 6605

The ideal solution is to store it in the SD card. Storing in DB won't keep the user from deleting it. You'll also lose this information if the user clears the app data. All databases are deleted when the user does it.

Anyway, if you choose the SQLite solution, you can use a blob field. Remember that some versions of SQLite won't support large blob data. Check this out:

http://effbot.org/zone/sqlite-blob.htm

I also suggest this:

http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html

Upvotes: 1

Related Questions