zxing-android-embedded
https://github.com/journeyapps/zxing-android-embedded
使用方法github上有,下面就是简单翻译了一下
超简单应用的demo源码 :https://gitee.com/zheyiw/zxing-demo
1,gradle插件需要3.0.1版本以上
classpath ‘com.android.tools.build:gradle:3.0.1’
2,依赖,如下两个
implementation ‘com.android.support:design:25.3.1’
implementation ‘com.journeyapps:zxing-android-embedded:3.6.0’
3,调用扫描
public final void doScan(View v) {
//Activity中这样使用
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
//Fragment中这样使用
//IntentIntegrator.forFragment(this).initiateScan();
}
4,获取返回结果
public void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null) {
if (result.getContents() == null) {
toast("没有扫描到结果");
} else {
String code = result.getContents();
code = code + "\n";
vHello.setText(code);
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
5,可以了
6,定制扫描框
添加zxing_barcode_scanner.xml就可以了,
本例中的扫描框大小为250dp
7,竖屏扫描
在AndroidManifest.xml加入如下代码
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation" />
这样调用就可以了
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setOrientationLocked(false);
integrator.initiateScan();