i have tried this code to upload an image from gallery to sqllite database in my application but when my application tries to open gallery it gives FORCE TO CLOSE Error and
db.execSQL("CREATE TABLE images ("
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "data BLOB,"
+ "hash BLOB UNIQUE"
+ ");");
To convert the image to a BLOB, use the following code: (Note that we're compressing the image here)
private byte[] getBitmapAsByteArray(Bitmap bitmap)
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// Middle parameter is quality, but since PNG is lossless, it doesn't matter
bitmap.compress(CompressFormat.PNG, 0, outputStream);
return outputStream.toByteArray();
}