I'm doing this:
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
final File storage = Environment.getExternalStorageDirectory();
final Uri uri = Uri.fromFile(new File(storage, System.currentTimeMillis() + ".jpg"));
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, id);
and to handle get that photo, I do this:
private String getLastImagePath() {
final String[] imageColumns = { MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA };
final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
final Cursor imageCursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns,
null, null, imageOrderBy);
if (imageCursor.moveToFirst()) {
final String fullPath = imageCursor.getString(imageCursor
.getColumnIndex(MediaStore.Images.Media.DATA));
return fullPath;
} else {
throw new RuntimeException();
}
}
However, I keep on getting messages like this one:
07-02 14:46:54.751: E/BitmapFactory(23119): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/IMG_20130702_144653.jpg: open failed: ENOENT (No such file or directory)
If I check the Gallery, the photo is not there, so my guess is that the Intent is ignoring the MediaStore.EXTRA_OUTPUT
value.
Is there anything I can do that does not involve writing my own Camera solution?
Nirmals solution works fine on all devices except on Android 4.x (Apilevel 15). Seems to be a bug, but
imageReturnedIntent.getData()
always returns null! (testet on emulator AND on device) The taken photo is not even saved on externaldir, so any attempt to get latestid
or greatestdate_added
fromContentResolver
will fail (returns the latest photo from card but not the taken photo)! Currently I have no solution for this problem...seems to be impossible to get the path for a taken picture on Apilevel 15 (while it's still possible to get the drawable and save by your own)...Use Like this:
Intent:
To fetch that result:
Add this in your manifest.xml.
Hope this will give you some solution.