不知道我在用 IntentIntegrator 做什么

发布于 2024-12-20 07:04:51 字数 1591 浏览 1 评论 0原文

扫描条形码后,我无法让 zxing 执行任何操作。我使用以下方式调用 zxing:

IntentIntegrator.initiateScan(MainActivity.this);

我的 onActivityResult 看起来像这样

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            if (format == "PRODUCT_CODE"){
                //If the barcode scanned is of the correct type then pass the barcode into the search method to get the product details
                Toast.makeText(getApplicationContext(),"You scanned " + contents, 3).show();
            }
            else{
                //If the barcode is not of the correct type then display a notification
                Toast.makeText(getApplicationContext(),"You didn't scan a product code", 3).show();
            }
        } else if (resultCode == RESULT_CANCELED) {
            //If the scan is cancelled then display a notification
            Toast.makeText(getApplicationContext(),"You cancelled the input", 3).show();
        }
    }

}

但每当我退出 zxing 时,什么都没有显示。我尝试使用zxing wiki中的示例 但每当我尝试用 MainActivity 或 MainActivity.this 替换 yourActivity 时,我都会收到错误(我被告知 MainActivity 无法解析为字符串,并且 MainActivity.this 构造函数 IntentIntegrator(MainActivity) 未定义)。

基本上我不知道我在做什么以及为什么它不起作用。任何帮助将不胜感激。

I'm having trouble getting zxing to do anything after scanning a barcode. I call the zxing using:

IntentIntegrator.initiateScan(MainActivity.this);

And my onActivityResult looks like this

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            if (format == "PRODUCT_CODE"){
                //If the barcode scanned is of the correct type then pass the barcode into the search method to get the product details
                Toast.makeText(getApplicationContext(),"You scanned " + contents, 3).show();
            }
            else{
                //If the barcode is not of the correct type then display a notification
                Toast.makeText(getApplicationContext(),"You didn't scan a product code", 3).show();
            }
        } else if (resultCode == RESULT_CANCELED) {
            //If the scan is cancelled then display a notification
            Toast.makeText(getApplicationContext(),"You cancelled the input", 3).show();
        }
    }

}

But whenever I exit zxing nothing is displayed. I tried using the example in the zxing wiki
but whenever I try to replace yourActivity with MainActivity or MainActivity.this I receive errors (I get told MainActivity cannot be resolved to a string and with MainActivity.this that The constructor IntentIntegrator(MainActivity) is undefined).

Basically I have no idea what I'm doing and why it's not working. Any help would be greatly appreciated.

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

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

发布评论

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

评论(1

寄居人 2024-12-27 07:04:51

这个问题和你的另一个问题完全相同。您不能使用 == 比较字符串,但必须使用 equals()

The problem is exactly the same as in your other question. You can't compare strings with ==, but must use equals().

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