首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BarCode搜索器Zxing

BarCode搜索器Zxing
EN

Stack Overflow用户
提问于 2012-06-27 19:37:23
回答 1查看 1.2K关注 0票数 0

我想在点击按钮时扫描二维码,问题是当我在我的设备上运行代码时,Activity Result Intent变量总是返回0。

如何知道条形码读取器是否正常工作?我目前在设备屏幕上看到了黄色的圆点。

下面是我的代码:

代码语言:javascript
复制
private OnClickListener scanner = new OnClickListener() {
    public void onClick(View v) {
        IntentIntegrator.initiateScan(BarCodeScannerActivity.this);
    }
}; 

protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
     IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
     if (scanResult != null) {
           // handle scan result
           String s = "http://www.google.com/search?q=";
           s += scanResult.getContents();

           Intent myIntent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
           startActivity(myIntent1);
     }

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-28 19:08:49

你在代码中有错误

你应该有

代码语言:javascript
复制
@Override
  public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    if (result != null) {
      String contents = result.getContents();
      if (contents != null) {
        showDialog(R.string.result_succeeded, result.toString());
      } else {
        showDialog(R.string.result_failed, getString(R.string.result_failed_why));
      }
    }
  }

您不会像onCreateonStart那样覆盖onActivityResult

相反,您编写的onActivityResult像普通方法一样,这是最常见的错误。

另外,如果你能提到integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);integrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);,那就更好了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11225298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档