I have a project that uses Fragments, I have a button which directs me to the image gallery, there I have to select an image and it shows in an image view, however I can not.
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();
}
}
}