Zxing扫描二维码

一、开源项目地址:https://github.com/zxing/zxinghtml

二、jar包下载地址:http://repo1.maven.org/maven2/com/google/zxing/core/ 能够选择版本号,而后下载。android

三、导入demo:  导入android 文件夹便可。git

四、网上精简版demo:  http://blog.csdn.net/xiaanming/article/details/10163203 github

    http://www.cnblogs.com/dolphin0520/p/3355728.html 网络


效果图:maven

caution:ide

  1. 手机横竖屏问题ui

    位置:CameraConfigurationManager.initFromCameraParametersthis

    修改代码:if (width < height) {
        camera.setDisplayOrientation(90);//添加的代码
       int temp = width;
       width = height;
       height = temp;
      }google

    位置:CameraManager.getFramingRectInPreview

    修改代码: WindowManager manager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE);
      Display display = manager.getDefaultDisplay();
      int width = display.getWidth();
      int height = display.getHeight();
      if (width<height) {
       System.out.println("竖屏");
       rect.left = rect.left * cameraResolution.y / screenResolution.x;
       rect.right = rect.right * cameraResolution.y / screenResolution.x;
       rect.top = rect.top * cameraResolution.x / screenResolution.y;
       rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;
      }

      if (width>height) {
       System.out.println("横屏");
       rect.left = rect.left * cameraResolution.x / screenResolution.x;
       rect.right = rect.right * cameraResolution.x / screenResolution.x;
       rect.top = rect.top * cameraResolution.y / screenResolution.y;
       rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;
      }

2.扫描结果对话框

   位置:CaptureActivity.handleDecode

  修改代码:if (!TextUtils.isEmpty(result)) {
   AlertDialog.Builder builder = new AlertDialog.Builder(this);
         builder.setMessage(result)
                .setPositiveButton("肯定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                     //请求网络,发送数据
                     new AsyncTask<String, Void, String>() {
                    @Override
                     protected String doInBackground(String... params) {
                          AccessToServer accessToServer=new AccessToServer  ("
http://192.168.254.1:8080/ZxingWeb/sendScancode");
                         return   accessToServer.doPost(new String[]{"content"}, new String[]{result});
                     }
                       protected void onPostExecute(String result) {
                        //System.out.println(result);
                   };
             }.execute();
          //页面跳转打开网页
             Intent mIntent=new Intent(CaptureActivity.this,WebViewActivity.class);
            mIntent.putExtra("url", result);
             startActivity(mIntent);
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    finish();              //这个地方很是关键,若是不finish()的话,第二次扫描可能要好长时间,或者扫不出来
                    }
                });
        builder.create().show();

         
   /*Intent intent = new Intent();
   intent.putExtra("scan_result", rawResult.getText());
   setResult(RESULT_OK, intent);*/
  } else {
   setResult(RESULT_CANCELED);
  }
  // finish();           //记得要注释掉

3.扫描灵敏度问题

  距离二维码多远能扫描出来?

  多长时间能扫出来?