我从对话框片段拍照。而且我需要像startActivityForResult(takePictureIntent, actionCode);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch (requestCode) {
case SELECT_PHOTO:
getActivity();
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getActivity().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
setPic();
}
break;
case ACTION_TAKE_PHOTO_B: {
getActivity();
if (resultCode == Activity.RESULT_OK) {
handleBigCameraPhoto();
}
break;
}
}
}
不要调用此方法。有没有这样的方法可以在对话框片段中使用?
答案 0 :(得分:17)
尝试这样:
从片段开始活动:
getActivity().startActivityForResult(intent, code);
将结果返回片段:
父活动中的(片段调用活动):
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
fragmentObject
.onActivityResult(requestCode, resultCode, data);
}
答案 1 :(得分:0)
您需要做的就是实现托管活动的onActivityResult
并按如下所示调用其基类实现...
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
//this makes sure the child fragments receive this event
super.onActivityResult(requestCode, resultCode, data);
...
}
您实际上并不需要引用这些片段。调用活动的基类实现将确保所有片段都收到对onActivityResult