How do you start your Activity and from where? If you pass your result trough your MainActivity, you can try to make a new function in your DialogFragment like this:
public void onMyActivityResult(Context main, int resultCode... an so on){
main.getContentResolver.......
}
Edit: i have done it in this way:
Get the Activity in onCreate:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivity = (MainActivity) this.getActivity();
}
then:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_GALLERY && resultCode == Activity.RESULT_OK) {
...
Uri selectedImage = data.getData();
String path = getRealPathFromURI(selectedImage);
...
reloadImages();
}
super.onActivityResult(requestCode, resultCode, data);
}
and:
private String getRealPathFromURI(Uri contentURI) {
Cursor cursor = mActivity.getContentResolver().query(contentURI, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file
// path
return contentURI.getPath();
} else {
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
String path = cursor.getString(idx);
cursor.close();
return path;
}
}