Skip to content

Instantly share code, notes, and snippets.

@Tarelochkin
Created August 18, 2017 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tarelochkin/981b22dd625ff44385a60ba8b3d2f7c0 to your computer and use it in GitHub Desktop.
Save Tarelochkin/981b22dd625ff44385a60ba8b3d2f7c0 to your computer and use it in GitHub Desktop.
Pick an image from the gallery and show it in the activity window
private void pickImage() {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("image/*");
startActivityForResult(i, PICK_PHOTO_FOR_PRODUCT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_PHOTO_FOR_PRODUCT && resultCode == Activity.RESULT_OK) {
if (data == null) {
Toast.makeText(this, R.string.error_loading_image, Toast.LENGTH_SHORT).show();
return;
}
try {
InputStream is = getContentResolver().openInputStream(data.getData());
mBitmap = BitmapFactory.decodeStream(is);
mItemImageView.setImageBitmap(mBitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment