扫描QR安卓应用

时间:2016-03-15 02:34:34

标签: android

我在创建QR阅读应用程序时遇到问题,可以阅读以下内容:enter image description here

但我无法阅读以下内容:

enter image description here

现在有些代码:

compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
compile 'com.google.zxing:core:3.2.1'


public void qrOperations(View view) {
    Log.d(TAG, "qrOperations has been called");
    new IntentIntegrator(this).initiateScan();
    IntentIntegrator integrator = new IntentIntegrator(this);
    integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
    integrator.setPrompt("Scan a barcode");
    integrator.setCameraId(0);  // Use a specific camera of the device
    integrator.setBeepEnabled(false);
    integrator.setBarcodeImageEnabled(true);
    integrator.initiateScan();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub

    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (scanResult != null) {

        // handle scan result
        contantsString =  scanResult.getContents()==null?"0":scanResult.getContents();
        Log.d(TAG,"scanResult.getContents():" +scanResult.getContents());

        if (!contantsString.equalsIgnoreCase("0")) {
            Log.d(TAG, "LOOKS GREAT!!!" + contantsString);
            Toast.makeText(this, "LOOKS GREAT!!!\n" + contantsString, Toast.LENGTH_LONG).show();

        }
        Log.d(TAG, "result: " + contantsString);


    }
    else{
        Toast.makeText(this, "Problem to secan the barcode.", Toast.LENGTH_LONG).show();
    }
}

有趣的是,当我尝试在“Toast”中调试时,我确实得到了结果,但没有在“Log”中???

0 个答案:

没有答案