Android 中的条码扫描仪无法扫描

发布于 2025-01-01 17:02:24 字数 424 浏览 4 评论 0原文

我想制作一个应用程序,其中用户扫描产品中的条形码,然后 Android 手机将显示有关该产品的一些详细信息(来自数据库)。 我已经在我的 Android 手机上安装了 ZXing 条码扫描仪,我用它来调试我的应用程序。当我使用 ZXing 应用程序时,它会扫描条形码。 但是,当我使用我在另一篇文章中找到的以下代码从我的 Android 项目中打开 ZXing 时,它不会扫描条形码。我可以在手机摄像头中看到红线,但不会显示绿点“读取”条形码。

在 Android 应用程序中单击按钮时调用条形码扫描仪

为什么会发生这种情况? 提前致谢

I want to make an application in which the user scans a barcode from a product and then the android phone will show some details about the product (from a database).
I have installed ZXing barcode scanner on my android phone which i use for debugging my applications. When i use the ZXing application it scans the barcodes.
But when i open the ZXing from my android project with the following code which i found in another post here, it doesn't scan the barcode.I can see the red line in my phone's camera but it doesn't show the green dots that 'read' the barcode.

Calling barcode scanner on a button click in android application

Why could this happen?
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

过期以后 2025-01-08 17:02:24

尝试下面的代码。
这是我自己使用过的工作代码。

public class MyTestActivity extends Activity {
    @Override
      public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
    Button b = new Button(this);
    b.setText("Scan");
    b.setWidth(100);
    LinearLayout ll = new LinearLayout(this);

     b.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            startActivityForResult(intent, 0);
        }   
    });

        ll.addView(b);
        setContentView(ll);

    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {

//        IntentResult scanResult = IntentIntegrator.parseActivityResult(
//                  requestCode, resultCode, intent);

        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String contents = intent.getStringExtra("SCAN_RESULT");
                String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

                Dialog d = new Dialog(this);
                LinearLayout ll = new LinearLayout(this);
                TextView tv = new TextView(this);
                tv.setText(contents+" "+format);
                ll.addView(tv);
                d.setContentView(ll);
                d.show();          
            }
        }
    }
       }

希望有帮助

try the code below.
It's working code I've used it myself.

public class MyTestActivity extends Activity {
    @Override
      public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
    Button b = new Button(this);
    b.setText("Scan");
    b.setWidth(100);
    LinearLayout ll = new LinearLayout(this);

     b.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            startActivityForResult(intent, 0);
        }   
    });

        ll.addView(b);
        setContentView(ll);

    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {

//        IntentResult scanResult = IntentIntegrator.parseActivityResult(
//                  requestCode, resultCode, intent);

        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String contents = intent.getStringExtra("SCAN_RESULT");
                String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

                Dialog d = new Dialog(this);
                LinearLayout ll = new LinearLayout(this);
                TextView tv = new TextView(this);
                tv.setText(contents+" "+format);
                ll.addView(tv);
                d.setContentView(ll);
                d.show();          
            }
        }
    }
       }

hope it helps

万劫不复 2025-01-08 17:02:24

请仅使用我们提供的预打包集成代码(如下所述),而不是调试您的 Intent 代码:http://code.google.com/p/zxing/wiki/ScanningViaIntent

Rather than debug your intent code, please just use the pre-packaged integration code we provide as described here: http://code.google.com/p/zxing/wiki/ScanningViaIntent

别再吹冷风 2025-01-08 17:02:24

谢尔盖,上面的代码适用于 QR 码,不适用于条形码,您测试过条形码吗?

请让我知道任何使用 Zxing lib 处理条形码的人。

Sergey, above code will work for QR code, not for Barcode, have you tested for barcode.

Please let me know anyone work on barcode with Zxing lib.

微暖i 2025-01-08 17:02:24

我遇到了同样的问题,要解决更改

intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); 

intent.putExtra("PRODUCT_MODE", "QR_CODE_MODE");

I had the same problem, to solve change the

intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); 

to

intent.putExtra("PRODUCT_MODE", "QR_CODE_MODE");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文