一,增加远程依赖
app构建脚本中加:
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
二,注册表改一下
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.please_light">
<uses-permission android:name="android.permission.VIBRATE" />
<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.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Please_light">
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/Theme.Please_light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
tools:replace="android:screenOrientation"/>
</application>
</manifest>
三,启动扫描
public static final int SCAN_CODE=0X02;
..........
Intent intent=new Intent(context, CaptureActivity.class);
startActivityForResult(intent,SCAN_CODE);
............
四,扫描完成会返回结果接收
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK && data!=null){
IntentResult result= IntentIntegrator.parseActivityResult(resultCode,data);
String code=result.getContents();
Toast.makeText(context,code,Toast.LENGTH_LONG).show();
}
}
五.找了一天得资料,全他妈得跑不起来,我要有啃源码得时间我不会信你们得鬼。