条码扫描仪没有结果
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么您期望 resultCode 不是
-1
?resultCode
用于确定意图,即您调用结果活动的“原因”。仅此而已...我只是删除if (requestCode == 0)
因为它并不重要。Why do you expect the resultCode to be not
-1
? TheresultCode
is used to determine the intention, the "why" you have called the activity for result. Nothing more, nothing less... I would just remove theif (requestCode == 0)
as it isn't really important.您确定您没有查看
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 ofRESULT_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 be0xC0DE
actually. But, you don't need to bother with these details and getting them right if you just useIntentIntegrator.parseActivityResult()
from the project. See the javadoc which shows how to use this fully.