简体   繁体   中英

Cant get image bundle data in onActivityResult

My Intent activity starting code to open camera is as follow

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
      getActivity().startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
  }

Note:- This functionality is in a class extending dialogfragment class

My OnActivityResult method,which is in the Activity class,is as follows

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("sdf",""+data);
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        mimageView = (ImageView) findViewById(R.id.profileimageView4);
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        //mimageView.setImageBitmap(imageBitmap);
    }
}

The error showing in the log is as follows

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://media/external/images/media/22615 flg=0x1 }} to activity {www.vyrazu.com.purpleknights/www.vyrazu.com.purpleknights.Profile}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.os.Bundle.get(java.lang.String)' on a null object reference

What is the problem in this code.Thanks everyone for your time.

From what I can see, your code appears to be fine. However, it relies on ACTION_IMAGE_CAPTURE , and many camera apps have bugs . You might wish to try your app with a different camera app and see what the results are.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM