Cant Pick Picture From Gallery. Result Code Always Cancelled
The complete code of my Fragment: public class ProfileEditPictureFragment extends BaseFragment implements OnClickListener { private ImageView imageView = null; private
Solution 1:
Try ACTION_PICK like this
IntentgalleryIntent=newIntent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
And on Activity result
protectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
&& null != data) {
UriselectedImage= data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursorcursor= getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
intcolumnIndex= cursor.getColumnIndex(filePathColumn[0]);
imgDecodableString = cursor.getString(columnIndex);
cursor.close();
ImageViewimgView= (ImageView) findViewById(R.id.imgView);
imgView.setImageBitmap(BitmapFactory
.decodeFile(imgDecodableString));
} else {
Toast.makeText(this, "You haven't picked Image",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
.show();
}
}
Post a Comment for "Cant Pick Picture From Gallery. Result Code Always Cancelled"