@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();
      }
    }
 static {
   System.loadLibrary(Z_BAR_LIBRARY);
 }