public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    Camera.Size size = parameters.getPreviewSize();

    Image barcode = new Image(size.width, size.height, "Y800");
    barcode.setData(data);

    int result = mScanner.scanImage(barcode);

    if (result != 0) {
      mCamera.cancelAutoFocus();
      mCamera.setPreviewCallback(null);
      mCamera.stopPreview();
      mPreviewing = false;
      SymbolSet syms = mScanner.getResults();
      for (Symbol sym : syms) {
        String symData = sym.getData();
        if (!TextUtils.isEmpty(symData)) {
          Intent dataIntent = new Intent();
          dataIntent.putExtra(SCAN_RESULT, symData);
          dataIntent.putExtra(SCAN_RESULT_TYPE, sym.getType());
          setResult(Activity.RESULT_OK, dataIntent);
          finish();
          break;
        }
      }
    }
  }
    @SuppressWarnings("ConstantConditions")
    public void onPreviewFrame(byte[] data, Camera incomingCamera) {
      try {
        if (System.currentTimeMillis() > lastSnapshotTime) {
          lastSnapshotTime = System.currentTimeMillis() + SNAPSHOT_DELAY;

          Camera.Parameters cameraParameters = incomingCamera.getParameters();
          Camera.Size previewSize = cameraParameters.getPreviewSize();
          Image barcode = new Image(previewSize.width, previewSize.height, GREY_COLOR_SPACE);
          barcode.setData(data);

          if (scanner.scanImage(barcode) != 0) {
            SymbolSet scannerResults = scanner.getResults();

            if (vibrator != null) vibrator.vibrate(VIBRATE_TIME);

            for (Symbol symbol : scannerResults)
              if (scannerListener == null)
                Toast.makeText(getActivity(), symbol.getData(), Toast.LENGTH_LONG).show();
              else scannerListener.onDataReceive(symbol.getData(), symbol.getType());
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
        public void onPreviewFrame(byte[] data, Camera camera) {
          Camera.Parameters parameters = camera.getParameters();
          Size size = parameters.getPreviewSize();

          Image barcode = new Image(size.width, size.height, "Y800");
          barcode.setData(data);

          int result = scanner.scanImage(barcode);

          String strScanResult = "";

          if (result != 0) {
            previewing = false;
            mCamera.setPreviewCallback(null);
            mCamera.stopPreview();

            SymbolSet syms = scanner.getResults();
            for (Symbol sym : syms) {
              // scanText.setText("barcode result " + sym.getData());
              strScanResult += sym.getData();
              barcodeScanned = true;
            }

            Intent myIntent = new Intent(MainActivity.this, ValidateBarCodeResult.class);
            myIntent.putExtra("barcode_result", strScanResult);
            startActivity(myIntent);
          }
        }
示例#4
0
        public void onPreviewFrame(byte[] data, Camera camera) {
          Camera.Parameters parameters = camera.getParameters();
          Camera.Size size = parameters.getPreviewSize();

          Image barcode = new Image(size.width, size.height, "Y800");
          barcode.setData(data);

          int result = scanner.scanImage(barcode);

          if (result != 0) {
            previewing = false;
            mCamera.setPreviewCallback(null);
            mCamera.stopPreview();

            SymbolSet syms = scanner.getResults();

            playBeepSoundAndVibrate(); // 播放声音和振动代表成功获取二维码

            for (Symbol sym : syms) {
              // 将扫描后的信息返回
              String resultStr = sym.getData();
              Log.i(TAG, "resultStr: " + resultStr);
              if (resultStr.isEmpty() || !resultStr.substring(0, 7).equalsIgnoreCase("http://")) {
                // Message msg = new Message();
                // msg.what = MSG_SCANRESULT_NONE;
                // myHandler.sendMessage(msg);
                MyApp.showToast(mContext, "二维码信息内容不符合房产投票项目的要求, 请联系管理人员!");
                Intent intent = new Intent();
                intent.putExtra("downloadfile", "");
                setResult(RESULT_OK, intent);
                finish();
              } else {
                downLoadDBFile(resultStr);
                //      mLoginSqldb.close();
                //       mVoteSqldb.close();
                Intent intent = new Intent();
                intent.putExtra("downloadfile", mDownloadfile);
                setResult(RESULT_OK, intent);
                finish();
              }
            }
          }
        }
        public void onPreviewFrame(byte[] data, Camera camera) {
          Camera.Parameters parameters = camera.getParameters();
          Size size = parameters.getPreviewSize();

          Image barcode = new Image(size.width, size.height, "Y800");
          barcode.setData(data);

          int result = scanner.scanImage(barcode);

          if (result != 0) {
            previewing = false;
            mCamera.setPreviewCallback(null);
            //  mCamera.stopPreview();

            SymbolSet syms = scanner.getResults();
            for (Symbol sym : syms) {
              scanText.setText("barcode" + sym.getData());

              barcodeScanned = true;
              launchIntent(syms);
            }
          }
        }