I was trying to get an image from my Album ... this code below, works perfectly on an Activity but when I use it from a fragment ... it doesn't crash, it just doesn't reach the "onActivityResult" method ... could anyone give a suggestion to whats going on
@Override
public void onClick(View v) {
if (v.getId() == mCIB.getId()) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(i, ""), RESULT_LOAD_IMAGE);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && data != null) {
Uri selectedImage = data.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]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
//BitmapFactory.decodeFile(picturePath)
mCIB.setBitmapDrawable((BitmapDrawable) BitmapDrawable.createFromPath(picturePath), picturePath);
try {
mCIB.createImagePath();
mCIB.addImageToDB();
} catch (IOException e) {
e.printStackTrace();
}
}
}