1

Hi when I do something like this

 Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }

In onActivityResult I get thumbnail of the image from the data intent from the camera app

Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
mImageView.setImageBitmap(imageBitmap);

And I use that bitmap something like this.

But What if I want the imageuri so that I can get the full size image from it. I tried getting the image uri from the intent something like above

            Uri uri = data.getData();
            if (uri != null) {
                Log.d(TAG, uri.toString());
            }else{
                Log.d(TAG,"uri is null");
            }

Doing like this I get uri is null in my logcat.So can anyone let me know how to get the image uri.I dont want to use EXTRA_OUTPUT and specify my own path.Thanks in advance

krishna
  • 609
  • 8
  • 21

3 Answers3

0

There is a well documented bug, which occurs in low resolution devices. Check this thread for the workaround.

Community
  • 1
  • 1
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
0

There's a bug with that intent in some devices. Take a look at this to know how to workaround it.

Community
  • 1
  • 1
Narendra Singh
  • 3,990
  • 5
  • 37
  • 78
0

In some devices, the Uri is null in onActivityForResult(). So you need to set Uri to placing the captured image.

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // If there any applications that can handle this intent then call the intent.
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        Uri fileUri = Uri.fromFile(getOutputMediaFile());
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        startActivityForResult(takePictureIntent, CAMERA_PICKER);
    }

public File getOutputMediaFile() {
        // To be safe, you should check that the SDCard is mounted
        // using Environment.getExternalStorageState() before doing this.

        File mediaStorageDir;
        // If the external directory is writable then then return the External pictures directory.
        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
            mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyApp");
        } else {
            mediaStorageDir = Environment.getDownloadCacheDirectory();
        }

        // Create the storage directory if it does not exist
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                Log.d("MyCameraApp", "failed to create directory");
                return null;
            }
        }

        // Create a media file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
        File mediaFile;
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");

        return mediaFile;
    }
Krishna V
  • 1,801
  • 1
  • 14
  • 16