Barcode Scanner is a library that provides easy integration of Zxing library with your android applications.
You can download an arr from maven releases page.
Or use Gradle:
repositories {
maven { url 'https://github.com/softotalss/barcodescanner/raw/master/maven-repository' }
}
dependencies {
implementation 'com.google.zxing:core:x.x.x'
implementation 'com.github.softotalss:barcodescanner:1.0.2'
}
public class ScannerActivity extends AppCompatActivity implements BarcodeScannerView.ActivityCallback {
private ViewGroup mContentFrame;
private BarcodeScannerView mScannerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
initCamera();
}
@Override
public void onResume() {
super.onResume();
startCamera();
}
@Override
public void onPause() {
stopCamera();
super.onPause();
}
private void initCamera() {
mScannerView = new BarcodeScannerView(this);
mContentFrame.addView(mScannerView);
// Here setFormats
}
private void startCamera() {
if (mScannerView != null) {
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
}
private void stopCamera() {
if (mScannerView != null) {
mScannerView.stopCamera();
}
}
@Override
public void onResult(Result result) {
// Get barcode with result.getText()
}
@Override
public void onErrorExit(Exception e) {
// An error occurred with the camera, notify to user
}
// Use flash
void setFlash(boolean flag);
boolean isFlashOn();
public void toggleFlash();
// Read only specific formats
List<BarcodeFormat> formats = new ArrayList<>();
formats.add(BarcodeFormat.QR_CODE);
void setFormats(formats);
Use setFormats only right after initCamera
The library read barcodes faster in landscape mode, but in some cases you will need that your app always run in portrait mode. If it's this case, you can use the next config and simulate landscape mode even if your read activity is in portrait mode
void setLandscapeSimulated(boolean landscapeSimulated);
Alejandro Santana - @softotalss on GitHub
This project is based on:
Apache 2.0. See the LICENSE file for details.