Created
August 18, 2017 19:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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