How to place an image into
ImageView
from Gallery
private int PICK_IMAGE_REQUEST = 1;
private void openGallery() {
tvGallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
// Show only images, no videos or anything else
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
});
}
OnActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
/*camera preview*/
if (resultCode != RESULT_CANCELED) {
if (requestCode == 0) {
Bitmap bp = (Bitmap) data.getExtras().get("data");
previewView.setImageBitmap(bp);
}
/*gallery preview*/
else {
Uri uri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
Log.d(TAG, String.valueOf(bitmap));
ImageView previewView = (ImageView) findViewById(R.id.imgPostIssue);
previewView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
solved Placing an Picture in ImageView selected from Gallery