I have an camera Activity like this:
public void startCamera()
{
Log.d("ANDRO_CAMERA", "Starting camera on the phone...");
String fileName = "testphoto.jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,
"Image capture by camera");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, IMAGE_CAPTURE);
}
What should I do to save this image to a SQLite database?
I have code like this:
fileName = helper.getKdStore(c) + "_" + System.currentTimeMillis() + ".jpg";
_path = Environment.getExternalStorageDirectory().toString() + "/DCIM/Camera/" + fileName;
In start camera:
Cursor c = helper.getById(almagId);
c.moveToFirst();
File file = new File(_path, null);
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, IMAGE_CAPTURE);
System.out.println(file);
Dbhelper helper = new Dbhelper(this);
SQLiteDatabase db = helper.getWritableDatabase();
db.execSQL("update alfamapp set gambar ='"+file+"' where kdstore='"+helper.getKdStore(c)+"'");
db.close();
helper.close();
System.out.println(db);
and I create method public void load() to display my image:
detGam.setImageDrawable(Drawable.createFromPath(_path));
but my application can’t display the image. Thank you for your help.
Saving Image in to sqlite is bad idea, however if you still want to go further, there here is code