android项目中使用zxing扫码(二)

在上一篇文章中,直接使用zxing的源码。

这一篇,将使用别人已经打包好的aar包。

aar下载:https://github.com/journeyapps/zxing-android-embedded


把这些代码添加到项目的 build.gradle 文件里面,在重新编译一次,as会自动下载并加压aar,然后添加到外部库里面。

repositories {
    jcenter()
}

dependencies {
    compile 'com.journeyapps:zxing-android-embedded:3.0.1@aar' compile 'com.google.zxing:core:3.2.0' }


再然后直接输入这行代码,开始扫码

new IntentIntegrator(this).initiateScan(); // `this` is the current Activity

作者的项目中有几个例子,可以去看一下。

Samples:

  • ContinuousCaptureActivity: continuously scan and display results (instead of a once-off scan).
  • ToolbarCaptureActivity: Same as the normal CaptureActivity, but with a Lollipop Toolbar.
注:在我的手机上运行扫码,直接出现一个全屏的扫码界面,扫码的范围很大很大,建议根据自己的需求去定制。

你可能感兴趣的:(android项目中使用zxing扫码(二))