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

时间:2016-07-30 11:13:57

标签: java android android-intent

我的Intent活动开始代码打开相机如下

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

注意: - 此功能属于扩展dialogfragment

的类

我的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);
    }
}

日志中显示的错误如下

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

此代码中存在什么问题。谢谢大家的时间。

1 个答案:

答案 0 :(得分:0)

从我所看到的,您的代码似乎没问题。但是,它依赖于ACTION_IMAGE_CAPTUREmany camera apps have bugs。您可能希望使用其他相机应用尝试您的应用,并查看结果。