android studio zbar,Zbar and Zxing in android studio

问题

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.

回答1:

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.

Add the permissions for the Camera in your AndroidManifest.xml:

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 resultPoints) {

}

};

onCreate()

mBarcodeView = (BarcodeView) findViewById(R.id.barcode_view);

// Choose only one!!!

mBarcodeView.decodeSingle(callback);

// Or

mBarcodeView.decodeContinuous(callback);

onResume()

mBarcodeView.resume();

onPause()

mBarcodeView.pause();

In your Activity's XML layout, add the BarcodeView

android:id="@+id/barcode_view"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_centerVertical="true"

android:layout_centerHorizontal="true">

Hope this helps!

来源:https://stackoverflow.com/questions/31736605/zbar-and-zxing-in-android-studio

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值