LibZXing ![](https://i-blog.csdnimg.cn/blog_migrate/58ef5907b3c868877b1e1240cf9bc049.png)
二维码扫描、生成库
转载请注明出处,http://blog.csdn.net/qq137722697
详细使用方法见demo
博客更新没有github快,最新版见github
效果图
图片比较大,请耐心等待
![这里写图片描述](https://github.com/jwkj/LibZXing/blob/master/qrcode.gif)
How to
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.jwkj:LibZXing:v1.0.4'
}
生成二维码
生成一个300*300不带logo的二维码
QRCodeManager.getInstance().createQRCode("二维码内容", 300, 300)
生成一个300*300有logo的二维码
QRCodeManager.getInstance().createQRCode("二维码内容", 300, 300,logoBitmap)
![这里写图片描述](https://img-blog.csdn.net/20170630221235823?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXExMzc3MjI2OTc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
识别二维码
方法一:自动解析结果(推荐)
在调用处的activity/fragment注册onActivityResult方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
QRCodeManager.getInstance().with(this).onActivityResult(requestCode, resultCode, data);
}
监听扫描按钮单击事件
public void onScanQR(View view) {
QRCodeManager.getInstance()
.with(this)
.setReqeustType(1)
.scanningQRCode(new OnQRCodeScanCallback() {
@Override
public void onCompleted(String result) {
controlLog.append("\n\n(结果)" + result);
}
@Override
public void onError(Throwable errorMsg) {
controlLog.append("\n\n(错误)" + errorMsg.toString());
}
@Override
public void onCancel() {
controlLog.append("\n\n(取消)扫描任务取消了");
}
});
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
方法二:手动解析结果
开始扫描二维码
QRCodeManager.getInstance().with(this).scanningQRCode(requestCode);
扫描结束之后,结果可以在调用处的activity/fragment的onActivityResult中拿到
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
TODO
最后
转载请注明出处,http://blog.csdn.net/qq137722697
github地址:https://github.com/huangdali/LibZXing/