关于ZXing二维码扫描的时候偶然出现数字问题

今天在测试项目的时候发现,在多次扫描同一个生成二维码的时候,小米手机有机会偶然出现扫描的结果全是数字的情况,暂时没有想到到的解决方法,只能是在扫描出结果之后,判断下是否全是数字,如果是的话继续开始扫描,具体代码如下:

/**
 * A valid barcode has been found, so give an indication of success and show
 * the results.
 *
 * @param rawResult The contents of the barcode.
 * @param bundle    The extras
 */
public void handleDecode(Result rawResult, Bundle bundle) {

    if (!isAllNumer(rawResult.getText())){
        inactivityTimer.onActivity();
        beepManager.playBeepSoundAndVibrate();
        Intent resultIntent = new Intent();
        bundle.putInt("width", mCropRect.width());
        bundle.putInt("height", mCropRect.height());
        bundle.putString("result", rawResult.getText());
        resultIntent.putExtras(bundle);
        this.setResult(1000, resultIntent);
        CaptureActivity.this.finish();
    }else {
        handler.restartPreviewAndDecode();
    }

}

重新开启扫描的方法Zxing里面的CaptureActivityHandler里面有提供。

判断是否全是数字才用的是正则表达是,方法如下:

public static boolean isAllNumer(String str){

    Pattern pattern = Pattern.compile("[0-9]*");

    return pattern.matcher(str).matches();

}

 

你可能感兴趣的:(android扫描,Zxing)