Skip to content

Instantly share code, notes, and snippets.

@towcar
Last active October 23, 2021 21:36
Show Gist options
  • Save towcar/c002ccb0790fe65506668ba563321eec to your computer and use it in GitHub Desktop.
Save towcar/c002ccb0790fe65506668ba563321eec to your computer and use it in GitHub Desktop.
@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