1、在build.gradle 中添加zxing依赖。
implementation 'com.journeyapps:zxing-android-embedded:3.5.0'
implementation 'com.google.zxing:core:3.3.3'
2、创建扫码xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".sy.Sy_ScanQRCodeActivity">
<com.journeyapps.barcodescanner.CompoundBarcodeView
android:id="@+id/barcode_scanner"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</LinearLayout>
3、在xml对应的Activity文件中,设置隐藏顶部工具栏、设置检查摄像头权限后获取识别结果。拿到识别结果后根据自己的需求进行后续开发。
//隐藏顶部
if