Skip to content

Instantly share code, notes, and snippets.

@ameliacv
Last active September 25, 2018 17:30
Show Gist options
  • Save ameliacv/fbe329626c51bd9587d8b8ce16b66883 to your computer and use it in GitHub Desktop.
Save ameliacv/fbe329626c51bd9587d8b8ce16b66883 to your computer and use it in GitHub Desktop.
private static final int OPEN_THING = 99;
public void openGallery() {
int preference = ScanConstants.OPEN_MEDIA;
Intent intent = new Intent(this, ScanActivity.class);
intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, preference);
startActivityForResult(intent, OPEN_THING);
}
public void openCamera() {
int preference = ScanConstants.OPEN_CAMERA;
Intent intent = new Intent(this, ScanActivity.class);
intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, preference);
startActivityForResult(intent, OPEN_THING);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && data != null) {
if (requestCode == OPEN_THING) {
Uri uri = data.getExtras().getParcelable(ScanConstants.SCANNED_RESULT);
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
getContentResolver().delete(uri, null, null);
scannedImageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment