"Access denied finding property 'camera.hal1.packagelist'" 在 LG V30 上打开 QR 扫描仪 Intent 时抛出错误?

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

来自这个问题,here

我目前正在开发一个需要通过设备的内置摄像头扫描二维码的应用程序,使用以下库:

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

我扫描二维码的逻辑如下,摘自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();

使用 View.OnClickListener() 在 Button 内部调用此代码,结果由 onActivityResult

处理

每当我 运行 这段代码并从扫描器得到结果时,扫描器 returns 什么都没有,并且异常被写入控制台,即 Access denied finding property "camera.hal1.packagelist"。权限已成功授予应用程序。有问题的权限是 CAMERAINTERNET 权限。

有问题的测试设备是 LG V30+ ThinQ 智能手机。

有办法解决这个问题吗?或者这个问题是否在所有具有双摄像头设置的智能手机上普遍存在,因此 'unfixable'?

更新

使用以下代码进行简单测试:

/** 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
}

(代码已经从上面post中取出这个answer。)

以上代码产生与上面显示的 IntentIntegrator 代码相同的结果,并抛出与之前相同的 Access denied finding property "camera.hal1.packagelist" 错误。

经过深思熟虑和大量实验,我找到了解决这个问题的方法。每次单击 QR 扫描按钮时,解决方案似乎来自 IntentIntegrator Class 的新声明。通过这个,我的意思是使用以下行授予对相机的访问权限

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

根据我的理解,显式声明对象实例化的可选参数(即 setBeepEnabled 等)会导致问题,因此拒绝应用程序实际使用相机的权限,即使权限硬件已经预先授予。

在此基础上,应在 IntentIntegrator 声明中声明和设置可选参数,而不是显式地在不同的行中。这样,应用程序仍然保留对相机硬件的访问权限,但现在可以满足其他可选参数和功能的需求。通过这个,我的意思是参数应该指定如下:

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

此修复似乎适用于所有双摄像头设置