Sandy Sandy - 1 year ago 50
Android Question

Image capturing issue in HTC mobile

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);

After capturing the image, i am using following code to get image:

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");

It works fine in all devices except HTC in landscape mode.

I am using portrait mode in my app. But when i capture a image in landscape mode in my HTC,i am getting imageUri null.
How to resolve this issue, it is only in HTC devices.

Answer Source

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("");
 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;