I have have not found a practical example that specifically pertains to saving the file path of a image that you just took with the camera app to a SQLite database in your application.
I have seen code to save an image from a HTML source... no good! My issue is that I have the URI but honestly, I can't figure out with the available data (dev guide, Stack Overflow questions) how to insert that file path to my database column.
Here is my code where I try setting an edit text field so that the path is savable to the database. I tried this in the emulator:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
Bitmap x = (Bitmap) data.getExtras().get("data");
File storagePath = new File(Environment.getExternalStorageDirectory() +
"/DCIM/GPAA/");
storagePath.mkdirs();
File myImage = new File(storagePath,
System.currentTimeMillis() + ".jpg");
try {
FileOutputStream out = new FileOutputStream(myImage);
x.compress(Bitmap.CompressFormat.JPEG, 80, out);
Uri outputFileUri = Uri.fromFile(myImage);
mnotesText = (EditText)findViewById(R.id.notes);
mnotesText.setText (outputFileUri.toString());
((ImageView)findViewById(R.id.photoResultView)).setImageBitmap(x);
out.close();
Toast.makeText(Review.this,
"Image saved: " + outputFileUri.toString(),
Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
} catch (IOException e){
}
}
}
With this code the toast verifies that the string is available and correct. However the entry to the mnotesText.setText (outputFileUri.toString());
works in the emulator. But strangely enough will not work on the phone.