我试图捕获图像并希望获得Uri。但是我将Uri对象变为null。我知道还有另一种方法可以通过将照片保存到某个位置然后调用startActivityForResult
方法来拍照,但我想这样做!
这里有什么问题!?
(这里我通过对话框调用它,所以dismiss()方法就在那里并通过片段实例调用startActivityForResult
!)
mTakeCameraImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mFragment.startActivityForResult(intent, CAMERA_REQUEST);
dismiss();
}
});
OnActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case CAMERA_REQUEST:
if (resultCode == RESULT_OK) {
Uri selectedImage = data.getData();
Picasso.get().load(selectedImage).into(ImageButton);
}
break;
}
}