繁体   English   中英

无法将QR Code阅读器的结果识别为字符串

[英]It can't recognize the result of the QR Code reader as a string

我有一个QR码阅读器,当它扫描二维码并获取文本时,我希望该代码使用if函数检查该文本并显示特定图像。 但是由于某种原因,它总是卡在if函数中...好像它无法识别result.getText().ToString()作为字符串... \\

public void processPicture(CameraEvent event) {
        updateLayout("Please wait...");

        if (event.getIndex() == 0) {
            if (event.getData() != null && event.getData().length > 0) {
                byte[] data = event.getData();
                Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

                int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
                //copy pixel data from the Bitmap into the 'intArray' array
                bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());

                LuminanceSource source = new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray);

                BinaryBitmap bbmap = new BinaryBitmap(new HybridBinarizer(source));
                Reader reader = new QRCodeReader();
                int DelayTime = 5000;
                boolean error = false;
                try {

                    Result result = reader.decode(bbmap);
                    Log.d(Constants.LOG_TAG, result.getText());
                    qc = result.getText().toString();

                   // updateLayout(result.getText());
                    if( qc == "zoi"){
                        Bundle iconBundle = new Bundle();
                        iconBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.image);
                        iconBundle.putString(Control.Intents.EXTRA_DATA_URI,
                                getUriString(R.drawable.zoiko));
                        currentlyTakingPicture = false;
                        showLayout(R.layout.layout, new Bundle[] {iconBundle});
                    }
                } catch (NotFoundException e) {
                    updateLayout("QR Code Not Found");
                    error = true;
                    e.printStackTrace();
                } catch (ChecksumException e) {
                    e.printStackTrace();
                    updateLayout(new String[] {
                            "QR Code looks corrupted",
                            "Maybe try again?"
                    });
                    error = true;
                } catch (FormatException e) {
                    e.printStackTrace();
                    updateLayout("That's not a QR Code");
                    error = true;
                }

                if (error) {
                    try {
                        Thread.sleep(DelayTime);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    currentlyTakingPicture = false;
                    updateLayout(DEFAULT_TEXT);
                }
            }
        }
    }

我认为您应该使用.equals()方法与String进行比较。 因此,如果您的条件是-

if(result.getText().toString().equals("zoi")){
//your code here
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM