android基于ZXing和ZBar的二维码扫描项目
Android库项目,提供基于ZXing和ZBar易于使用,可扩展的条码扫描器的用法。
ZXing
安装:
添加下面的依赖关系到你的build.gradle文件。
compile 'me.dm7.barcodescanner:zxing:1.7.2'
简单的用法:
1)添加摄像头权限进AndroidManifest.xml文件:
<uses-permission android:name="android.permission.CAMERA" />
2.) A very basic activity would look like this:
public class SimpleScannerActivity extends Activity implements ZXingScannerView.ResultHandler { private ZXingScannerView mScannerView; @Override public void onCreate(Bundle state) { super.onCreate(state); mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view setContentView(mScannerView); // Set the scanner view as the content view } @Override public void onResume() { super.onResume(); mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results. mScannerView.startCamera(); // Start camera on resume } @Override public void onPause() { super.onPause(); mScannerView.stopCamera(); // Stop camera on pause } @Override public void handleResult(Result rawResult) { // Do something with the result here Log.v(TAG, rawResult.getText()); // Prints scan results Log.v(TAG, rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.) } }
请看看一个完整的工作示例zxing/sample 项目。
ZBar
安装
添加下面的依赖关系到你的build.gradle文件。
compile 'me.dm7.barcodescanner:zbar:1.7.2'
简单用法
1) Add camera permission to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.CAMERA" />
2.) A very basic activity would look like this:
public class SimpleScannerActivity extends Activity implements ZBarScannerView.ResultHandler { private ZBarScannerView mScannerView; @Override public void onCreate(Bundle state) { super.onCreate(state); mScannerView = new ZBarScannerView(this); // Programmatically initialize the scanner view setContentView(mScannerView); // Set the scanner view as the content view } @Override public void onResume() { super.onResume(); mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results. mScannerView.startCamera(); // Start camera on resume } @Override public void onPause() { super.onPause(); mScannerView.stopCamera(); // Stop camera on pause } @Override public void handleResult(Result rawResult) { // Do something with the result here Log.v(TAG, rawResult.getContents()); // Prints scan results Log.v(TAG, rawResult.getBarcodeFormat().getName()); // Prints the scan format (qrcode, pdf417 etc.) } }
相关推荐
82103253 2012-11-10
87497718 2012-11-10
82103253 2012-02-13
Litchi 2020-06-05
85580695 2020-04-07
zxingli 2020-01-03
89367267 2013-07-17
Litchi 2013-09-02
Litchi 2013-12-30
Litchi 2012-02-01
Litchi 2016-08-02
Android进阶 2019-06-27
87497718 2018-01-02
flyrunlx 2017-01-10
87497718 2016-09-26
82103253 2016-09-14