二维码扫描

依赖
implementation ‘com.github.yuzhiqiang1993:zxing:2.2.1’
https://blog.csdn.net/yuzhiqiang_1993/article/details/78292004
//生成二维码
shengchengButton.setOnClickListener(new View.OnClickListener() {

        private Bitmap qrCode;

        @Override
        public void onClick(View v) {
            String s = shengchengText.getText().toString();
            BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
            qrCode = CodeCreator.createQRCode(s, 400, 400, null);
            img.setImageBitmap(qrCode);
        }
    });
   // 扫描二维码
    sao.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, CaptureActivity.class);
            startActivityForResult(intent, 99);
        }
    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 99 && resultCode == RESULT_OK) {
    if (data != null) {
        String content = data.getStringExtra(Constant.CODED_CONTENT);
        textSao.setText("扫描结果为:" + content);
    }
}

}

你可能感兴趣的:(二维码扫描)