0
I have a project that uses Fragments, I have a button that directs me to the image gallery, there I have to select an image and show in an image view, but I’m not getting.
btnGaleria.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,0);
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == IMAGEM_INTERNA) {
if (requestCode == IMAGEM_INTERNA && resultCode == Activity.RESULT_OK) {
Uri imagemSelecionada = intent.getData();
String[] colunas = {MediaStore.Images.Media.DATA};
Cursor cursor = getContext().getContentResolver().query(imagemSelecionada, colunas, null, null, null);
cursor.moveToFirst();
int indexColuna = cursor.getColumnIndex(colunas[0]);
String pathimg = cursor.getString(indexColuna);
cursor.close();
Bitmap bitmap = BitmapFactory.decodeFile(pathimg);
this.image_selecionada.setImageBitmap(bitmap);
}
else{
Toast.makeText(getActivity(), "Imagem não existe!", Toast.LENGTH_SHORT).show();
}
}
}
If you are going to base what you posted here of the code ta bone, bro, see, start by checking two veses for "requestCode" in
if (requestCode == IMAGEM_INTERNA)
and then inside thatif
Voce checks again for it, then Voce uses this value contained in "IMAGEN_INTERNA" in the methodpublic void onActivityResult(...) {...}
Voce must pass this value by the call of the Intent and by what I could see Voce passes 0 by its Intent. checks that there and trains more expensive– Armando Marques Sobrinho