【问题标题】:Identifying scanned QR code using Google Mobile Vision API使用 Google Mobile Vision API 识别扫描的二维码
【发布时间】:2026-01-13 18:10:02
【问题描述】:

我正在使用 Google Mobile Vision Api 扫描条码,而且运行速度非常快。但现在我想识别条形码,无论它们是用于 Wifi、联系人、SMS 还是其他。

我尝试了一种自己的方法来识别扫描的条形码类型,但这是使用一些 If-else。那么,有没有一种方法可以直接识别扫描的条形码类型?

就像Zxing Wiki 一样,每种类型的条形码都有一个选项。但我没有找到任何 google mobile vision api。

这是我正在使用的代码:

1. 将 rawValue 传递给另一个活动

@Override
    public void onRetrieved(final Barcode barcode) {
        runOnUiThread(new Runnable() {
           @Override
           public void run() {
               Intent intent = new Intent(QRScanner.this, BarcodeResult.class);
               intent.putExtra("Barcode", barcode.rawValue);
               QRScanner.this.finish();
               startActivity(intent);
           }
       });

2。识别条码

        textView1 = intent.getStringExtra("Barcode");
        if(textView1.startsWith("BEGIN:VCARD")) {
            VCard vcard = Ezvcard.parse(textView1).first();
            String str = ""+vcard.getFormattedName().getValue();
            String no = "";
            List<Telephone> list = vcard.getTelephoneNumbers();
            if(list.size()>1){

                for(int i=0;i<list.size();i++)
                    no = ""+list.get(i)+"\n"+no;
            }
            else if(list.size()==1) {
                no = list.get(0).toString();
            }
            if(!no.equals(""))
               str = str+"\n"+no;
            textView.setText(str);
        }

此代码运行良好,可以识别 VCard 条码,但为每种类型的条码添加 If-else 是一个问题,需要时间。因此,如果我缺少解决方案,请分享。

【问题讨论】:

    标签: android qr-code google-vision


    【解决方案1】:

    您可以使用barcode.valueFormat 变量来识别它。将此值传递给另一个活动后,您可以执行以下操作:

    if(valueFormart == Barcode.CONTACT_INFO){
       VCard vcard = Ezvcard.parse(textView1).first();
       ...
    }
    

    【讨论】: