利用com.journeyapps:zxing-android-embedded:3.6.0实现扫码
 
在配置文件中进行如下配置:
implementation 'com.google.zxing:core:3.4.0'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
 
给integrator添加RequestCode,如下红色
private void scan_qrcode()
{
    IntentIntegrator integrator = new IntentIntegrator(ScanActivity.this);
    integrator.setCaptureActivity(CaptureActivityAnyOrientation.class)
    .setRequestCode(SCAN_CODE)
    .setOrientationLocked(true)
    .setPrompt(getString(R.string.s_scan_text))
    .setBarcodeImageEnabled(false)
    .setBeepEnabled(false)
    .initiateScan();
}
 
发现在onActivityResult中怎么也获取不到二维码数据,后来发现是用错了方法。
不应该用IntentIntegrator.parseActivityResult(requestCode,resultCode, intent)
而是要用IntentIntegrator.parseActivityResult(resultCode, intent)
onActivityResult代码如下:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
    if (resultCode == RESULT_OK)
    {
        if (requestCode == SCAN_CODE)
        {
            IntentResult scanResult = IntentIntegrator.parseActivityResult(resultCode, intent);
            final String qrContent = scanResult.getContents();
            tv_result.setText(qrContent);
        }
    }
    super.onActivityResult(requestCode, resultCode, intent);
}
GitHub 加速计划 / zx / zxing
12
1
下载
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
最近提交(Master分支:2 个月前 )
50799640 Bumps [org.apache.maven.plugins:maven-release-plugin](https://github.com/apache/maven-release) from 3.1.1 to 3.2.0. - [Release notes](https://github.com/apache/maven-release/releases) - [Commits](https://github.com/apache/maven-release/compare/maven-release-3.1.1...maven-release-3.2.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-release-plugin dependency-version: 3.2.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 4 天前
132ba33d Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 4 天前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐