开源软件名称(OpenSource Name):dm77/barcodescanner开源软件地址(OpenSource Url):https://github.com/dm77/barcodescanner开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):Project ArchivedJuly 1 2020 This project is no longer maintained. When I first started this project in late 2013 there were very few libraries to help with barcode scanning on Android. But the situation today is much different. We have lots of great libraries based on ZXing and there is also barcode scanning API in Google's MLKit (https://github.com/googlesamples/mlkit). So given the options I have decided to stop working on this project. IntroductionAndroid library projects that provides easy to use and extensible Barcode Scanner views based on ZXing and ZBar. ScreenshotsMinor BREAKING CHANGE in 1.8.4Version 1.8.4 introduces a couple of new changes:
ZXingInstallationAdd the following dependency to your build.gradle file.
Simple Usage1.) 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 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.)
// If you would like to resume scanning, call this method below:
mScannerView.resumeCameraPreview(this);
}
} Please take a look at the zxing-sample project for a full working example. Advanced UsageTake a look at the FullScannerActivity.java or FullScannerFragment.java classes to get an idea on advanced usage. Interesting methods on the ZXingScannerView include: // Toggle flash:
void setFlash(boolean);
// Toogle autofocus:
void setAutoFocus(boolean);
// Specify interested barcode formats:
void setFormats(List<BarcodeFormat> formats);
// Specify the cameraId to start with:
void startCamera(int cameraId); Specify front-facing or rear-facing cameras by using the For HUAWEI mobile phone like P9, P10, when scanning using the default settings, it won't work due to the "preview size", please adjust the parameter as below: mScannerView = (ZXingScannerView) findViewById(R.id.zx_view);
// this paramter will make your HUAWEI phone works great!
mScannerView.setAspectTolerance(0.5f); Supported Formats: BarcodeFormat.UPC_A
BarcodeFormat.UPC_E
BarcodeFormat.EAN_13
BarcodeFormat.EAN_8
BarcodeFormat.RSS_14
BarcodeFormat.CODE_39
BarcodeFormat.CODE_93
BarcodeFormat.CODE_128
BarcodeFormat.ITF
BarcodeFormat.CODABAR
BarcodeFormat.QR_CODE
BarcodeFormat.DATA_MATRIX
BarcodeFormat.PDF_417 ZBarInstallationAdd the following dependency to your build.gradle file.
Simple Usage1.) 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.)
// If you would like to resume scanning, call this method below:
mScannerView.resumeCameraPreview(this);
}
} Please take a look at the zbar-sample project for a full working example. Advanced UsageTake a look at the FullScannerActivity.java or FullScannerFragment.java classes to get an idea on advanced usage. Interesting methods on the ZBarScannerView include: // Toggle flash:
void setFlash(boolean);
// Toogle autofocus:
void setAutoFocus(boolean);
// Specify interested barcode formats:
void setFormats(List<BarcodeFormat> formats); Specify front-facing or rear-facing cameras by using the Supported Formats:
Rebuilding ZBar Libraries
Patch the localcharset.c file: vim libiconv-1.14/libcharset/lib/localcharset.c On line 48, add the following line of code:
Save the file and continue with steps below:
Open jni/Android.mk file and add fPIC flag to LOCAL_C_FLAGS. Open jni/Application.mk file and specify APP_ABI targets as needed.
Upon completion you can grab the .so and .jar files from the libs folder. CreditsAlmost all of the code for these library projects is based on:
Contributorshttps://github.com/dm77/barcodescanner/graphs/contributors LicenseLicense for code written in this project is: Apache License, Version 2.0 License for zxing and zbar projects is here: |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论