简体   繁体   English

无法在onActivityResult中获取图像包数据

[英]Cant get image bundle data in onActivityResult

My Intent activity starting code to open camera is as follow 我打开相机的Intent活动开始代码如下

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 注意:-此功能在扩展dialogfragment类的类中

My OnActivityResult method,which is in the Activity class,is as follows 我的OnActivityResult方法位于Activity类中,如下所示

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 . 但是,它依赖于ACTION_IMAGE_CAPTURE ,并且许多相机应用程序都有bug You might wish to try your app with a different camera app and see what the results are. 您可能希望将其与其他相机应用程序一起尝试,看看结果如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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