com.google.zxing.activity.CaptureActivity Java Examples

The following examples show how to use com.google.zxing.activity.CaptureActivity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DecodeThread.java    From QrCodeLib with MIT License 6 votes vote down vote up
DecodeThread(CaptureActivity activity,
             Vector<BarcodeFormat> decodeFormats,
             String characterSet,
             ResultPointCallback resultPointCallback) {

    this.activity = activity;
    handlerInitLatch = new CountDownLatch(1);

    hints = new Hashtable<DecodeHintType, Object>(3);

    if (decodeFormats == null || decodeFormats.isEmpty()) {
        decodeFormats = new Vector<BarcodeFormat>();
        decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
        decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
        decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
    }

    hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);

    if (characterSet != null) {
        hints.put(DecodeHintType.CHARACTER_SET, characterSet);
    }

    hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
}
 
Example #2
Source File: MainActivity.java    From QrCodeLib with MIT License 6 votes vote down vote up
private void startQrCode() {
    // 申请相机权限
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        // 申请权限
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission
                .CAMERA)) {
            Toast.makeText(this, "请至权限中心打开本应用的相机访问权限", Toast.LENGTH_SHORT).show();
        }
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, Constant.REQ_PERM_CAMERA);
        return;
    }
    // 申请文件读写权限(部分朋友遇到相册选图需要读写权限的情况,这里一并写一下)
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        // 申请权限
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission
                .WRITE_EXTERNAL_STORAGE)) {
            Toast.makeText(this, "请至权限中心打开本应用的文件读写权限", Toast.LENGTH_SHORT).show();
        }
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, Constant.REQ_PERM_EXTERNAL_STORAGE);
        return;
    }
    // 二维码扫码
    Intent intent = new Intent(MainActivity.this, CaptureActivity.class);
    startActivityForResult(intent, Constant.REQ_QR_CODE);
}
 
Example #3
Source File: MainActivity.java    From vmqApk with MIT License 6 votes vote down vote up
public void startQrCode(View v) {
    // 申请相机权限
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        // 申请权限
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, Constant.REQ_PERM_CAMERA);
        return;
    }
    // 申请文件读写权限(部分朋友遇到相册选图需要读写权限的情况,这里一并写一下)
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        // 申请权限
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, Constant.REQ_PERM_EXTERNAL_STORAGE);
        return;
    }
    // 二维码扫码
    Intent intent = new Intent(MainActivity.this, CaptureActivity.class);
    startActivityForResult(intent, Constant.REQ_QR_CODE);
}
 
Example #4
Source File: DecodeThread.java    From vmqApk with MIT License 6 votes vote down vote up
DecodeThread(CaptureActivity activity,
             Vector<BarcodeFormat> decodeFormats,
             String characterSet,
             ResultPointCallback resultPointCallback) {

  this.activity = activity;
  handlerInitLatch = new CountDownLatch(1);

  hints = new Hashtable<DecodeHintType, Object>(3);

  if (decodeFormats == null || decodeFormats.isEmpty()) {
  	 decodeFormats = new Vector<BarcodeFormat>();
  	 decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
  	 decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
  	 decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
  }
  
  hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);

  if (characterSet != null) {
    hints.put(DecodeHintType.CHARACTER_SET, characterSet);
  }

  hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
}
 
Example #5
Source File: MainActivity.java    From QrCodeDemo4 with MIT License 6 votes vote down vote up
private void startQrCode() {
    // 申请相机权限
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        // 申请权限
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, Constant.REQ_PERM_CAMERA);
        return;
    }
    // 申请文件读写权限(部分朋友遇到相册选图需要读写权限的情况,这里一并写一下)
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        // 申请权限
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, Constant.REQ_PERM_EXTERNAL_STORAGE);
        return;
    }
    // 二维码扫码
    Intent intent = new Intent(MainActivity.this, CaptureActivity.class);
    startActivityForResult(intent, Constant.REQ_QR_CODE);
}
 
Example #6
Source File: DecodeThread.java    From QrCodeDemo4 with MIT License 6 votes vote down vote up
DecodeThread(CaptureActivity activity,
             Vector<BarcodeFormat> decodeFormats,
             String characterSet,
             ResultPointCallback resultPointCallback) {

  this.activity = activity;
  handlerInitLatch = new CountDownLatch(1);

  hints = new Hashtable<DecodeHintType, Object>(3);

  if (decodeFormats == null || decodeFormats.isEmpty()) {
  	 decodeFormats = new Vector<BarcodeFormat>();
  	 decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
  	 decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
  	 decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
  }
  
  hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);

  if (characterSet != null) {
    hints.put(DecodeHintType.CHARACTER_SET, characterSet);
  }

  hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
}
 
Example #7
Source File: MainActivity.java    From CodeScaner with MIT License 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == Constant.REQ_QRCODE && data != null) {
        byte[] result = data.getByteArrayExtra(CaptureActivity.KEY_RESULT);
        if (result == null || result.length == 0) {
            tvReuslt.setText("");
            btnCopy.setVisibility(View.GONE);
            return;
        }
        String payCode = new String(result);
        tvReuslt.setText(payCode);
        btnCopy.setVisibility(View.VISIBLE);
    } else {
        tvReuslt.setText("");
        btnCopy.setVisibility(View.GONE);
    }
}
 
Example #8
Source File: CaptureActivityHandler.java    From QrCodeLib with MIT License 5 votes vote down vote up
public CaptureActivityHandler(CaptureActivity activity, Vector<BarcodeFormat> decodeFormats,
                              String characterSet) {
    this.activity = activity;
    decodeThread = new DecodeThread(activity, decodeFormats, characterSet,
            new ViewfinderResultPointCallback(activity.getViewfinderView()));
    decodeThread.start();
    state = State.SUCCESS;
    // Start ourselves capturing previews and decoding.
    CameraManager.get().startPreview();
    restartPreviewAndDecode();
}
 
Example #9
Source File: CaptureActivityHandler.java    From vmqApk with MIT License 5 votes vote down vote up
public CaptureActivityHandler(CaptureActivity activity, Vector<BarcodeFormat> decodeFormats,
                              String characterSet) {
  this.activity = activity;
  decodeThread = new DecodeThread(activity, decodeFormats, characterSet,
      new ViewfinderResultPointCallback(activity.getViewfinderView()));
  decodeThread.start();
  state = State.SUCCESS;
  // Start ourselves capturing previews and decoding.
  CameraManager.get().startPreview();
  restartPreviewAndDecode();
}
 
Example #10
Source File: CaptureActivityHandler.java    From QrCodeDemo4 with MIT License 5 votes vote down vote up
public CaptureActivityHandler(CaptureActivity activity, Vector<BarcodeFormat> decodeFormats,
                              String characterSet) {
  this.activity = activity;
  decodeThread = new DecodeThread(activity, decodeFormats, characterSet,
      new ViewfinderResultPointCallback(activity.getViewfinderView()));
  decodeThread.start();
  state = State.SUCCESS;
  // Start ourselves capturing previews and decoding.
  CameraManager.get().startPreview();
  restartPreviewAndDecode();
}
 
Example #11
Source File: MainActivity.java    From CodeScaner with MIT License 5 votes vote down vote up
private void getPermission() {
    //第二个参数是需要申请的权限
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        //权限还没有授予,需要在这里写申请权限的代码
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 2);
    } else {
        //权限已经被授予,在这里直接写要执行的相应方法即可
        startActivityForResult(new Intent(MainActivity.this, CaptureActivity.class), Constant.REQ_QRCODE);
    }
}
 
Example #12
Source File: MainActivity.java    From CodeScaner with MIT License 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == 2) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            startActivityForResult(new Intent(MainActivity.this, CaptureActivity.class), Constant.REQ_QRCODE);
        } else {
            // Permission Denied
            Toast.makeText(MainActivity.this, "Permission Denied", Toast.LENGTH_SHORT).show();
        }
    }
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
 
Example #13
Source File: DecodeHandler.java    From QrCodeLib with MIT License 4 votes vote down vote up
DecodeHandler(CaptureActivity activity, Hashtable<DecodeHintType, Object> hints) {
    multiFormatReader = new MultiFormatReader();
    multiFormatReader.setHints(hints);
    this.activity = activity;
}
 
Example #14
Source File: DecodeHandler.java    From vmqApk with MIT License 4 votes vote down vote up
DecodeHandler(CaptureActivity activity, Hashtable<DecodeHintType, Object> hints) {
  multiFormatReader = new MultiFormatReader();
  multiFormatReader.setHints(hints);
  this.activity = activity;
}
 
Example #15
Source File: DecodeHandler.java    From QrCodeDemo4 with MIT License 4 votes vote down vote up
DecodeHandler(CaptureActivity activity, Hashtable<DecodeHintType, Object> hints) {
  multiFormatReader = new MultiFormatReader();
  multiFormatReader.setHints(hints);
  this.activity = activity;
}