Java源码示例:com.yzq.zxinglibrary.android.CaptureActivity

示例1
/**
 * 扫描二维码
 */
private void scanQRCode() {
    RequestPermission.with(this).permissions(Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE)
            .request(new RequestPermission.Callback() {
                @Override
                public void onGranted() {
                    Intent intent = new Intent(activity, CaptureActivity.class);
                    startActivityForResult(intent, REQUEST_CODE_SCAN);
                }

                @Override
                public void onDenied() {
                    Toast.makeText(activity, "没有打开相机的权限", Toast.LENGTH_SHORT).show();
                }
            });
}
 
示例2
@Override
public void onClick(View v) {

    Intent intent = new Intent(getActivity(), CaptureActivity.class);
    getActivity().startActivityForResult(intent, 1111);
}
 
示例3
public DecodeThread(CaptureActivity activity, ResultPointCallback resultPointCallback) {

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

        hints = new Hashtable<>();

        Vector<BarcodeFormat> decodeFormats = new Vector<BarcodeFormat>();

        /*是否解析有条形码(一维码)*/
        if (activity.config.isDecodeBarCode()) {
            decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
        }
        decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
        decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);

        hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);

        hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
        hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);

    }
 
示例4
DecodeHandler(CaptureActivity activity, Map<DecodeHintType, Object> hints) {
    multiFormatReader = new MultiFormatReader();
    multiFormatReader.setHints(hints);
    this.activity = activity;
}