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.掃描靈敏度問題

  距離二維碼多遠能掃描出來?

  多長時間能掃出來?

相關文章
相關標籤/搜索