嗨谁能教我怎么用zbar / zxing的QR code阅读器?我已经尝试了许多样品codeS在线,但没有似乎工作。顺便说一句即时通讯采用了android工作室。
Hi can anyone teach me how to use zbar/zxing for qr code reader? I have tried many of the sample codes online but none seems to work. Btw im using android studio.
推荐答案
我用 zxing-Android的嵌入式 。处理斑马线核心的你,会自动打开一个单独的线程的摄像头,并且甚至有自定义使用文档/例子。此外,作者经常(每周〜2周)提交和快速响应的问题。它会扫描QR的和酒吧codeS开箱即用的。
I used zxing-android-embedded. Handles the zxing-core for you, automatically opens the camera on a separate thread, and even has docs/examples for custom usage. Also, the authors commit often (every ~2 weeks) and respond fast to issues. It scans QR's and Barcodes out of the box.
添加权限相机在AndroidManifest.xml中:
Add the permissions for the Camera in your AndroidManifest.xml:
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
添加到您的build.gradle(APP):
Add this to your build.gradle (app):
repositories {
jcenter()
}
dependencies {
compile 'com.journeyapps:zxing-android-embedded:3.0.2@aar'
compile 'com.google.zxing:core:3.2.0'
}
在您的活动创建一个回调:
Create a callback in your Activity:
private BarcodeCallback callback = new BarcodeCallback() {
@Override
public void barcodeResult(BarcodeResult result) {
// Do something with the scanned QR code.
// result.getText() returns decoded QR code.
fooBar(result.getText());
}
@Override
public void possibleResultPoints(List<ResultPoint> resultPoints) {
}
};
的onCreate()
onCreate()
mBarcodeView = (BarcodeView) findViewById(R.id.barcode_view);
// Choose only one!!!
mBarcodeView.decodeSingle(callback);
// Or
mBarcodeView.decodeContinuous(callback);
onResume()
onResume()
mBarcodeView.resume();
的onPause()
onPause()
mBarcodeView.pause();
在你活动的XML布局,加上酒吧codeVIEW
In your Activity's XML layout, add the BarcodeView
<com.journeyapps.barcodescanner.BarcodeView
android:id="@+id/barcode_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
</com.journeyapps.barcodescanner.BarcodeView>
希望这有助于!
相关推荐
最新文章