Android扫码之ZXingLite

mac2025-03-31  8

ZXingLite for Android 是ZXing的精简版,基于ZXing库优化扫码和生成二维码/条形码功能,扫码界面完全支持自定义,也可一行代码使用默认实现的扫码功能。总之你想要的都在这里。

minSdkVersion 16 至少16以上

Gradle:

//AndroidX 版本 implementation 'com.king.zxing:zxing-lite:1.1.3-androidx' //Android 版本 implementation 'com.king.zxing:zxing-lite:1.1.3'

引入的库:

//AndroidX compileOnly 'androidx.appcompat:appcompat:1.0.0+' api 'com.google.zxing:core:3.3.3' //Android compileOnly 'com.android.support:appcompat-v7:28.0.0' api 'com.google.zxing:core:3.3.3'

布局示例

布局示例 (可自定义布局,布局内至少要保证有SurfaceView和ViewfinderView,控件id可根据重写CaptureActivity 的 getPreviewViewId 和 getViewFinderViewId方法自定义)

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <SurfaceView android:id="@+id/surfaceView" android:layout_width="match_parent" android:layout_height="match_parent"/> <com.king.zxing.ViewfinderView android:id="@+id/viewfinderView" android:layout_width="match_parent" android:layout_height="match_parent"/> </FrameLayout>

简单使用

//跳转的默认扫码界面 startActivityForResult(new Intent(context,CaptureActivity.class),requestCode); //生成二维码 CodeUtils.createQRCode(content,600,logo); //生成条形码 CodeUtils.createBarCode(content, BarcodeFormat.CODE_128,800,200); //如果直接使用CaptureActivity需在您项目的AndroidManifest中添加如下配置 <activity android:name="com.king.zxing.CaptureActivity" android:screenOrientation="portrait"/>

 

demo地址:https://download.csdn.net/download/weixin_42274773/11949574
最新回复(0)