How to fix Camera: Camera new cameraInitNormal:-13

I’ve integrated a QRCode scanner into my app and it worked fine on my old Android 5 device but throws the error

Camera: Camera new cameraInitNormal:-13

on Android 8. To fix this You have to integrate some code to check if permission is already granted by the user and in cas it is not request the rights for it at runtime.

This looks like this:

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    val scannerView = binding.scannerView
    val activity = requireActivity()

    if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA)
        != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.CAMERA), 50);

Now the user is asked every time when the camera feature shall be accessed: