条码扫描仪没有结果

发布于 2025-01-03 11:16:16 字数 1122 浏览 5 评论 0原文


我正在使用 ZXING IntentIntegrator 来读取 URL。 我设法使用以下方法启动条形码扫描仪:

IntentIntegrator integrator = new IntentIntegrator(List8.this);
dialog = integrator.initiateScan();

条形码扫描仪指示已找到 URL 并将我重定向回我的应用程序,在其中我使用以下方法检索信息:

@Override
protected 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");
                Toast.makeText(getApplicationContext(), contents, Toast.LENGTH_LONG).show();
                // Handle successful scan
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }


      }

问题是,即使已找到 URL,requestCode 仍为 -1 并且意图没有数据。
有谁知道我的问题的根源是什么?

聚苯乙烯
我尝试实现 onActivityResultListener 但出现以下错误:

The return type is incompatible with PreferenceManager.OnActivityResultListener.onActivityResult(int, int, 
     Intent)

I'm using ZXING IntentIntegrator in order to read a URL.
I managed to launch the barcode scanner using:

IntentIntegrator integrator = new IntentIntegrator(List8.this);
dialog = integrator.initiateScan();

The barcode scanner indicated that a URL has been found and redirects me back to my application where I retrieve the information using:

@Override
protected 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");
                Toast.makeText(getApplicationContext(), contents, Toast.LENGTH_LONG).show();
                // Handle successful scan
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }


      }

The problem is that even thought a URL has been found the requestCode is -1 and the intent has no data.

Does anyone have any idea what's the source of my problem?

P.S.

I tried implementing onActivityResultListener but got the following error:

The return type is incompatible with PreferenceManager.OnActivityResultListener.onActivityResult(int, int, 
     Intent)

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

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

发布评论

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

评论(2

弥繁 2025-01-10 11:16:16

为什么您期望 resultCode 不是 -1resultCode 用于确定意图,即您调用结果活动的“原因”。仅此而已...我只是删除 if (requestCode == 0) 因为它并不重要。

Why do you expect the resultCode to be not -1? The resultCode is used to determine the intention, the "why" you have called the activity for result. Nothing more, nothing less... I would just remove the if (requestCode == 0) as it isn't really important.

☆獨立☆ 2025-01-10 11:16:16

您确定您没有查看 resultCode 吗? RESULT_OK 的值实际上是 -1 (http://developer.android.com/reference/android/app/Activity.html#RESULT_OK)。

如果您使用集成代码,则 requestCode 实际上将为 0xC0DE。但是,如果您只使用项目中的 IntentIntegrator.parseActivityResult() ,则无需费心处理这些细节并确保它们正确。请参阅 javadoc,它展示了如何充分使用它。

Are you sure you aren't looking at resultCode? The value of RESULT_OK is in fact -1 (http://developer.android.com/reference/android/app/Activity.html#RESULT_OK).

If you are using the integration code, then requestCode will be 0xC0DE actually. But, you don't need to bother with these details and getting them right if you just use IntentIntegrator.parseActivityResult() from the project. See the javadoc which shows how to use this fully.

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