i am using following code for capturing the image in Android:
String fileName = "image.jpeg";
//create parameters for Intent with filename
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,"Image captured by camera");
//imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState)
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
//create new Intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAMERA_PIC_REQUEST);
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if( requestCode == CAMERA_PIC_REQUEST)
{
if(resultCode == Activity.RESULT_OK)
{
if(imageUri == null)
imageUri = data.getData();
String filePath = getPath(imageUri);
UploadContentToServer(filePath, "image.jpeg");
//getBytesFromFile(filePath);
}
}
}
I had the same issue on my galaxy s2 when trying to capture images with the camera. Try specifying the real path in the intent and then get the path down in your onActivityResult. Extracting the uri directly from the Intent data didnt work for me in image capture either.
Here is an example of what I mean:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
fileName = dateFormat.format(new Date()) + ".jpg";
File photo = new File(Environment.getExternalStorageDirectory(), fileName);
Intent cameraintent = new Intent("android.media.action.IMAGE_CAPTURE");
cameraintent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
imageURICamera = Uri.fromFile(photo);
startActivityForResult(cameraintent, 1);
And now getting the foto again in onActivityResult:
realPath = Environment.getExternalStorageDirectory() + "/" + fileName;