Search code examples
androidandroid-activityqr-codezxing

zxing qr code scanner camera showing white screen


Good day! i'm having an issue with the qr code scanner in android marshmallow and nougat using the library that i have added as dependency in my project the camera shows white screen. Code runs perfectly in lollipop and kitkat. Please let me know if there was something i have missed or something i will do to make it work. I have paste my snippets of code down below. It is my pleasure if you give me some time to notice my concern. I have seen similar topic of my issue but it did not help me work out or i have implemented it wrong. Thank you in advance.

I have zxing jar library for generating qr code, and i used me.dm7.barcodescanner:zxing:1.8.4 for scanning qr codes:

dependency {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 compile files('libs/zxing-2.1.jar')
 compile('me.dm7.barcodescanner:zxing:1.8.4'){
    exclude group: 'com.google.zxing'
   }
}

The Activity for the opening of the camera:

public class ScanQRCodeActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
private String strDataEncrypted;
private ZXingScannerView mScannerView;
public static String strEncrypt;
public static String strEncrypted;
public static String strIV;
public static boolean isScanSuccess = false;

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);
    mScannerView = new ZXingScannerView(this);
    setContentView(mScannerView);
}

@Override
public void onResume() {
    super.onResume();
    mScannerView.setResultHandler(this);
    mScannerView.startCamera();
}

@Override
public void onPause() {
    super.onPause();
    mScannerView.stopCamera();
}

@Override
public void handleResult(Result result) {
    strDataEncrypted = result.getText();
    Log.wtf("handleResult", strDataEncrypted);
    String[] strSplit = strDataEncrypted.split("\\|\\|");
    strEncrypted = strSplit[0].trim();
    strIV = strSplit[1];
    CryptLibHelper cryptLibHelper = new CryptLibHelper();
    cryptLibHelper.decrypt(strEncrypted, strIV, new CryptLibHelper.CryptLibDecryptCallback() {
        @Override
        public void onDecryptFailed(String str_message) {
            Log.wtf("onDecryptFailed", str_message);
        }

        @Override
        public void onDecryptSuccess(String str_message) {
            if (str_message.contains("}")) {
                strEncrypt = str_message.replace("}", "");
                Log.wtf("onDecryptSuccess", strEncrypt);
            }
        }
    });
    onBackPressed();
    isScanSuccess = true;
    mScannerView.resumeCameraPreview(this);
}

}


Solution

  • Have you added CAMERA permission check in your app?? Since from marshmallow onwards you need to ask user for some permissions.

    You can first try to manually give permission to your app from device settings.