QRScaner
QRScaner copied to clipboard
base on camreaX and zxing finish scaner
QRScaner
简介
基于CameraX beta版本和zxing对二维码扫描进行封装
修正了preview分辨率过低的问题,同时参照camreaview的方式对scanview进行了一次调整
功能介绍
-
二维码距离远自动放大
-
自动对焦
-
单击focus
-
双击放大
简单使用
- 引入依赖
implementation 'com.github.leifzhang:QrCodeLibrary:0.0.1'
- 在布局xml中加入AutoZoomScanView
<com.kronos.camerax.qrcode.AutoZoomScanView
android:id="@+id/scanView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
- 先申请camera权限并绑定lifecycle
AndPermission.with(this)
.runtime()
.permission(Permission.Group.CAMERA)
.onGranted { permissions: List<String?>? ->
scanView.bindWithLifeCycle(this@MainActivity)
}
.onDenied { permissions: List<String?>? -> }
.start()
- 二维码结果回调,之后重新打开分析逻辑
scanView.setOnQrResultListener { view: View, s: String ->
Toast.makeText(
this@MainActivity, s,
Toast.LENGTH_LONG
).show()
scanView.reStart()
}
简单的可以直接参考sample内