Last active
September 25, 2018 17:30
-
-
Save ameliacv/fbe329626c51bd9587d8b8ce16b66883 to your computer and use it in GitHub Desktop.
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 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