捕获图像时,Uri路径是空的?

时间:2013-01-23 09:45:05

标签: android image camera

Uri路径是null?如何获取图像URI路径?我的代码是:

ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "Image File name");
mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intentPicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intentPicture.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(intentPicture,CAMERA_PIC_REQUEST);

OnActivityResult方法

if (requestCode == CAMERA_PIC_REQUEST && resultCode == RESULT_OK) {
 String videoPath = getRealPathFromURI(mCapturedImageURI);

}

但是静止图像路径是null(空指针异常)

1 个答案:

答案 0 :(得分:0)

您需要在使用之前初始化mCapturedImageURI。检查返回onActivityResult的意图:

@Override  
public void onActivityResult(int reqCode, int resultCode, Intent data)
{  
  // data will contain your URI
}