-2

I have an activity in which i am calling intent of camera on click, but when I capture image and get back to the activity result my Image view reference is null. I am getting URI correctly. This happens in android Lollipop.

Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
               startActivityForResult(captureIntent, 1);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {

        if (requestCode == 1) {
            Bundle extras = data.getExtras();

            Bitmap thePic = extras.getParcelable("data");
            //retrieve a reference to the ImageView
            Log.i("dataa",String.valueOf(thePic));
            Log.i("dataaimg",String.valueOf(image));
            Log.i("dataaimgno",String.valueOf(imageno));
            image.setImageBitmap(thePic); // here is the problem image reference is null when get back here
        }

    }  

This code is working fine in versions below lollipop.

fadden
  • 51,356
  • 5
  • 116
  • 166

1 Answers1

0

Try this:

private static final int CAPTURE_IMAGE_ACTIVITY_REQ = 0;

Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAPTURE_IMAGE_ACTIVITY_REQ );


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQ) {
        if (resultCode == RESULT_OK) {

        Bitmap bp = (Bitmap) data.getExtras().get("data");
        image = setImageBitmap(bp);
}
}
Veeresh Charantimath
  • 4,641
  • 5
  • 27
  • 36