learntodroid / AndroidQRCodeScanner

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.
https://learntodroid.com/how-to-create-a-qr-code-scanner-app-in-android/
39 stars 31 forks source link

App crashing when the permission is already granted #4

Open fazy95 opened 2 years ago

fazy95 commented 2 years ago

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; }