Android QR Code Scanner is an Android App is written in Java that uses the Android Jetpack CameraX library for previewing the camera and image analysis along with the ZXing open-source bar code scanning library.
The code actually crashes when the permission of accessing the camera is already given. The following functions solved that issue for me. Please make a check before requesting a camera in the onCreate function.
private boolean isCameraPermissionGranted(){
int selfPermission= ContextCompat.checkSelfPermission(getBaseContext(), Manifest.permission.CAMERA);
return selfPermission==PackageManager.PERMISSION_GRANTED;
}
The code actually crashes when the permission of accessing the camera is already given. The following functions solved that issue for me. Please make a check before requesting a camera in the onCreate function. private boolean isCameraPermissionGranted(){ int selfPermission= ContextCompat.checkSelfPermission(getBaseContext(), Manifest.permission.CAMERA); return selfPermission==PackageManager.PERMISSION_GRANTED; }