0

I am using this code it is working fine in 1.6 but it is crashing in 4.4?

 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                fileUri = new ExternalStorage(getApplicationContext()).getAlbumStorageDir(); // create a file to save the image
                intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
                // start the image capture Intent
                startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);


    /*in onActivityResult*/
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                Uri uri = data.getData();
                try {
                    Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
                    ImageView imageView = (ImageView) findViewById(R.id.image);
                    imageView.setImageBitmap(bitmap);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (resultCode == RESULT_CANCELED) {
            } else {
            }
        }

I have gone through several post but all I didn't find correct one.

  • Hi dude.., this link may help you same problem is faced here also. Check it out. http://stackoverflow.com/questions/9890757/android-camera-data-intent-returns-null – KURUMADDALI ANURAG Sep 26 '15 at 12:43

1 Answers1

0

There is no requirement for ACTION_IMAGE_CAPTURE to return a Uri via onActivityResult().

You know where the image should be stored, as you are providing that via EXTRA_OUTPUT. Use the value you put into EXTRA_OUTPUT, rather than data.getData().

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491