Zxing scans the QR code

 
Summary
android Zxing scan QR code horizontal and vertical screen scanning sensitivity

1. Open source project address: https://github.com/zxing/zxing

2. The jar package download address: http://repo1.maven.org/maven2/com/google/zxing/core/  You can select the version number and download it.

3. Import demo: Import the android folder.

4. Online Lite demo:   http://blog.csdn.net/xiaanming/article/details/10163203 

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

 

Effect picture:

caution:

  1. mobile phone screen problem

    位置:CameraConfigurationManager.initFromCameraParameters

    Modify the code: if (width < height) {
        camera.setDisplayOrientation(90);//Added code
       int temp = width;
       width = height;
       height = temp;
      }

    Location: 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. Scan result dialog

   位置: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(); //This place is very critical. If you don't finish(), the second scan may take a long time, or it may not be scanned
                    }
                });
        builder.create().show();

          
   /*Intent intent = new Intent();
   intent.putExtra("scan_result", rawResult.getText());
   setResult(RESULT_OK, intent);*/
  } else {
   setResult(RESULT_CANCELED);
  }
  // finish(); // remember to comment it out

3. Scanning sensitivity problem

  How far can the QR code be scanned?

  How long does it take to scan out?

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326559016&siteId=291194637