Most probably it could be possible that you must have forgot to add Runtime Permissions to access Camera API and thus resulting in App Crash when you try to open camera. Below is the code snipped which you can use to do the same:
public void showCamera(View view) {
// BEGIN_INCLUDE(camera_permission)
// Check if the Camera permission is already available.
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
// Camera permission has not been granted.
requestCameraPermission();
} else {
// Camera permissions is already available, show the camera preview.
Log.i(TAG,
"CAMERA permission has already been granted. Displaying camera preview.");
showCameraPreview();
}
// END_INCLUDE(camera_permission)
}
private void requestCameraPermission() {
// BEGIN_INCLUDE(camera_permission_request)
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.CAMERA)) {
// Provide an additional rationale to the user if the permission was not granted
// and the user would benefit from additional context for the use of the permission.
// For example if the user has previously denied the permission.
} else {
// Camera permission has not been granted yet. Request it directly.
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA},
REQUEST_CAMERA);
}
// END_INCLUDE(camera_permission_request)
}
Here is Google Runtime Permission Model Video to have an better understanding.
Also check official documentation for further details.
Hope this helps.