关于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();

}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值