Question

I am trying to write a application which i will take image from camera and use it. At first i used

Bitmap image = (Bitmap) data.getExtras().get("data");

However i noticed that this will just return thumbnail of the image. So i updated my code as:

public void takePhoto(){
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    File dir = context.getDir("directory", Context.MODE_PRIVATE);
    File photo = new File(dir, "Pic.jpg");
    mImageUri = Uri.fromFile(photo);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
    startActivityForResult(intent, 0);

}
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == 0){
        if(Activity.RESULT_OK == resultCode){
            Uri selectedImage = mImageUri;
            getContentResolver().notifyChange(selectedImage, null);
            ContentResolver cr = getContentResolver();
            Bitmap bitmap;
            try {
                bitmap=android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImage);
                displayIV.setImageBitmap(bitmap);
            } catch (Exception e) {
                // TODO: handle exception
            }

        }

    }
}

Problem is after upgrading the code it stopped calling onActivityResult function after i finish taking photo. After taking picture i am clicking DONE button on camera screen but it doesnt call the application back. The app stays in camera screen.

Any idea what i am doing wrong?

Was it helpful?

Solution

External storage write permissions needs to be add to manifest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top