Search code examples
javaandroidandroid-cameraqr-codeandroid-camera2

"Access denied finding property 'camera.hal1.packagelist'" error thrown when open QR Scanner Intent on LG V30?


Coming from this question, here

I am currently developing an application that needs to scan QR Codes via the Device's built-in camera, using the following libraries:

implementation 'com.google.zxing:core:3.3.3'
implementation 'com.journeyapps:zxing-android-embedded:3.5.0'

The logic I am using to scan the QR Code is as follows, which has been taken from this tutorial:

   IntentIntegrator integrator = new IntentIntegrator(QR_Activity.this);
   integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
   integrator.setPrompt("Scan");
   integrator.setCameraId(0);
   integrator.setBeepEnabled(false);
   integrator.setBarcodeImageEnabled(false);
   integrator.initiateScan();

This code is being called inside a Button using View.OnClickListener(), and the result is being handled by onActivityResult

Whenever I run this code and get the result back from the scanner, the scanner returns nothing, and a exception is written to the console, namely Access denied finding property "camera.hal1.packagelist". Permissions have been successfully granted to the application. The permissions in question are the CAMERA and INTERNET permissions.

The test device in question is a LG V30+ ThinQ Smartphone.

Is there a way to get around this issue? Or is this problem prevalent on all smartphones that have a dual camera setup, and therefore 'unfixable'?

UPDATE

Conducting a simple test using the following code:

/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance(){
    Camera c = null;
    try {
        c = Camera.open(); // attempt to get a Camera instance
    }
    catch (Exception e){
        // Camera is not available (in use or does not exist)
    }
    return c; // returns null if camera is unavailable
}

(The code has been taken from this answer from the above post.)

The above code yields the same results as the IntentIntegrator code shown above, and throws the same Access denied finding property "camera.hal1.packagelist" error as before.


Solution

  • After a lot of deliberation and a lot of experimentation, I have found a solution to this problem. The solution seems to come from a new declaration of the IntentIntegrator Class every time the QR Scanning Button is clicked. By this, I mean that the access to the camera is granted using the following line

    new IntentIntegrator(MyActivity.this).initiateScan();
    

    From my understanding, declaring the optional parameters of the object's instantiation explicitly (i.e. setBeepEnabled and so on) is causing the problem, and therefore denies the application permission to actually use the camera, even though permissions to the hardware have already been granted beforehand.

    Building on this, the optional parameters should be declared and set within the IntentIntegrator declaration, and not explicitly on different lines. This way, the application still retains access to the camera hardware, but can now cater for other optional parameters and features. By this, I mean the parameters should be specified as the following:

    new IntentIntegrator(MyActivity.this).setBeepEnabled(false).initiateScan();
    

    This fix appears to work on all dual camera setups