I'm trying to grab an image from the galleries/photos and insert it in my EditText and sending it only after I click on the send button. I believe the title is self explanatory.
Before opening this question thread, I tried to collect as much information from all others related questions found here in OverFlow.
So far here is what I have:
public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
Bitmap yourSelectedImage = null;
switch(requestCode) {
case Constant.SELECT_IMAGE:
if (resultCode == RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
try {
yourSelectedImage = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), selectedImage);
} catch (IOException e) {
e.printStackTrace();
}
if (yourSelectedImage != null) {
typeMessageEditText.setCompoundDrawables(new BitmapDrawable(getResources(), yourSelectedImage)
,null, null, null);
}
}
}
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case (R.id.insertPhotoImage):
onStartGalleryPhotos();
break;
default:
break;
}
}
private void onStartGalleryPhotos() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, Constant.SELECT_PICTURE), Constant.SELECT_IMAGE);
}
}
DEBUG:
typeMessageEditText is my EditText where I'm trying to get the image inserts. I tried debugging the onActivityResult and I'm seeing that the URI is actually being retrieved so I believe that part is working. However, when I convert my bitmap into a drawable and insert it in my EditText, nothing is actually showing in my EditText in my emulator.