1 Star 0 Fork 0

张东东大人 / zxing-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

zxing

一句话依赖就能实现扫一扫功能,包含闪光灯开关,选取本地图片解析,生成二维码(可带logo)功能等。

如果直接依赖不满足你的需求,需要自己修改样式或源码的话,可以将该库作为module集成到你的项目中,集成方法参考我的这篇博客:https://blog.csdn.net/yuzhiqiang_1993/article/details/52805057

版本说明: https://github.com/yuzhiqiang1993/zxing/releases

博客: http://blog.csdn.net/yuzhiqiang_1993/article/details/78292004

扫描二维码下载APK体验一下

扫描二维码

首先来看看效果图

下图分别为 完整示例,扫描二维码,扫描条码,闪光灯,解析二维码图片,解析条码图片,生成二维码,修改扫描框四个角的颜色,修改扫描框边线颜色

扫描二维码 扫描条码 闪光灯 解析二维码图片 解析条码图片 生成二维码图片

使用方法

1.添加依赖

先在 build.gradle(Project:XXXX) 的 repositories 添加 maven { url 'https://jitpack.io' } 一定要加上这个,否则会提示依赖失败

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

然后在 build.gradle(Module:app) 的 dependencies 添加:

最新版本:https://github.com/yuzhiqiang1993/zxing/releases

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'androidx.appcompat:appcompat:1.0.0'
   
   /*添加依赖*/
   implementation 'com.github.yuzhiqiang1993:zxing:2.2.5'
}

2.权限

需要申请的权限有:

Manifest.permission.CAMERA
Manifest.permission.READ_EXTERNAL_STORAGE

  项目中用到的所有权限

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

3.跳转到扫一扫界面:

1.使用默认配置项,两行代码即可

Intent intent = new Intent(MainActivity.this, CaptureActivity.class);
startActivityForResult(intent, REQUEST_CODE_SCAN);

2.自定义配置项

Intent intent = new Intent(MainActivity.this, CaptureActivity.class);
/*ZxingConfig是配置类
*可以设置是否显示底部布局,闪光灯,相册,
* 是否播放提示音  震动
* 设置扫描框颜色等
* 也可以不传这个参数
* */
ZxingConfig config = new ZxingConfig();
config.setPlayBeep(true);//是否播放扫描声音 默认为true
config.setShake(true);//是否震动  默认为true
config.setDecodeBarCode(true);//是否扫描条形码 默认为true
config.setReactColor(R.color.colorAccent);//设置扫描框四个角的颜色 默认为白色
config.setFrameLineColor(R.color.colorAccent);//设置扫描框边框颜色 默认无色
config.setScanLineColor(R.color.colorAccent);//设置扫描线的颜色 默认白色
config.setFullScreenScan(false);//是否全屏扫描  默认为true  设为false则只会在扫描框中扫描
intent.putExtra(Constant.INTENT_ZXING_CONFIG, config);
startActivityForResult(intent, REQUEST_CODE_SCAN);

4.接收扫描结果

注意:Constant.CODED_CONTENT引的是这个com.yzq.zxinglibrary.common.Constant

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // 扫描二维码/条码回传
    if (requestCode == REQUEST_CODE_SCAN && resultCode == RESULT_OK) {
        if (data != null) {

            String content = data.getStringExtra(Constant.CODED_CONTENT);
            result.setText("扫描结果为:" + content);
        }
    }
}

5.生成二维码


/*
* contentEtString:字符串内容
* w:图片的宽
* h:图片的高
* logo:不需要logo的话直接传null
* */

Bitmap logo = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
bitmap = CodeCreator.createQRCode(contentEtString, 400, 400, logo);
              

ok,搞定了,就是这么简单,如果你觉得还行的话,麻烦给个start呦,有什么问题和建议直接提Issues,谢谢。

MIT License Copyright (c) 2017[yuzhiqiang1993] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于zxing的扫一扫,优化了扫描二维码速度,集成最新版本的jar包(zxing-core.jar 3.3.3),集成简单,速度快,可配置颜色,还有闪光灯,解析二维码图片,生成二维码等功能 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/a200332/zxing-1.git
git@gitee.com:a200332/zxing-1.git
a200332
zxing-1
zxing-1
master

搜索帮助