Get Path of image from ACTION_IMAGE_CAPTURE Intent

This is how it works on 2.2 (different than on previous versions). When starting intent

        String fileName = "temp.jpg";  
        ContentValues values = new ContentValues();  
        values.put(MediaStore.Images.Media.TITLE, fileName);  
        mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);  
        startActivityForResult(intent, CAPTURE_PICTURE_INTENT);

you need to remember mCapturedImageURI.

When you capture image, in onActivityResult() use that URI to obtain file path:

            String[] projection = { MediaStore.Images.Media.DATA}; 
            Cursor cursor = managedQuery(mCapturedImageURI, projection, null, null, null); 
            int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
            cursor.moveToFirst(); 
            String capturedImageFilePath = cursor.getString(column_index_data);

UPDATE: On new Android devices you would not need MediaStore.EXTRA_OUTPUT, but you rather deduce image/video URI from data.getData() received from onActivityResult(…, Intent data), as nicely described under

Android ACTION_IMAGE_CAPTURE Intent

However, since this part is subject to manufacturer adaptation, you may still encounter phones where “old” approach may be useful.

Leave a Comment