Last active
October 23, 2021 21:36
-
-
Save towcar/c002ccb0790fe65506668ba563321eec 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
@Override | |
public void onClick(View view) { | |
switch (view.getId()) { | |
case R.id.cameraBtn: { | |
isCameraCapture = true; | |
File photoFile = null; | |
try { | |
photoFile = createImageFile(); | |
} catch (IOException ex) { | |
// Error occurred while creating the File | |
} | |
if (photoFile != null) { | |
cameraUri = FileProvider.getUriForFile(this, | |
BuildConfig.APPLICATION_ID + ".provider", | |
photoFile); | |
} | |
Intent takePicture = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); | |
takePicture.putExtra(MediaStore.EXTRA_OUTPUT, cameraUri); | |
takePicture.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | |
takePicture.addFlags( Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | |
pickerLauncher.launch(takePicture); | |
break; | |
} | |
case R.id.libraryBtn: { | |
isCameraCapture = false; | |
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); | |
pickerLauncher.launch(intent); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment