zxing-android-embedded
Barcode scanner library for Android, based on the ZXing decoder
Top Related Projects
Barcode Scanner Libraries for Android
Code scanner library for Android, based on ZXing
Modification of ZXING Barcode Scanner project for easy Android QR-Code detection and AR purposes
a simple QRCode generation api for java built on top ZXING
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
Quick Overview
ZXing Android Embedded is a barcode scanning library for Android applications. It's based on the ZXing ("Zebra Crossing") open-source project and provides an easy-to-use interface for integrating barcode scanning functionality into Android apps.
Pros
- Easy integration with Android projects
- Supports a wide range of barcode formats
- Customizable UI and scanning options
- Active maintenance and community support
Cons
- Larger app size due to embedded scanner
- May have performance issues on older devices
- Limited to Android platform only
- Some advanced features require additional configuration
Code Examples
- Basic barcode scanning:
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0); // Use a specific camera of the device
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
- Handling scan results:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
- Customizing scanner appearance:
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setOrientationLocked(false);
integrator.setCaptureActivity(CustomScannerActivity.class);
integrator.initiateScan();
Getting Started
- Add the dependency to your app's
build.gradle
:
dependencies {
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
}
- Add the following to your
AndroidManifest.xml
:
<uses-permission android:name="android.permission.CAMERA" />
- Initiate a scan in your activity:
new IntentIntegrator(this).initiateScan();
- Handle the scan result in
onActivityResult
as shown in the code examples above.
Competitor Comparisons
Barcode Scanner Libraries for Android
Pros of barcodescanner
- Simpler implementation with fewer dependencies
- Supports a wider range of barcode formats out of the box
- Easier to customize UI elements
Cons of barcodescanner
- Less actively maintained (last update in 2018)
- May have compatibility issues with newer Android versions
- Limited documentation and community support
Code Comparison
zxing-android-embedded:
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0);
integrator.initiateScan();
barcodescanner:
ZXingScannerView mScannerView = new ZXingScannerView(this);
setContentView(mScannerView);
mScannerView.setResultHandler(this);
mScannerView.startCamera();
Both libraries offer straightforward implementation, but barcodescanner provides a more concise setup. However, zxing-android-embedded offers more configuration options and is better suited for complex scanning scenarios.
zxing-android-embedded is generally recommended for most projects due to its active maintenance, extensive documentation, and better compatibility with modern Android development practices. barcodescanner might be suitable for simpler projects or those requiring specific customizations, but its lack of recent updates is a significant drawback.
Code scanner library for Android, based on ZXing
Pros of code-scanner
- Lightweight and focused solely on barcode scanning
- Easier to integrate with modern Android development practices
- More frequent updates and active maintenance
Cons of code-scanner
- Less comprehensive documentation compared to zxing-android-embedded
- Smaller community and fewer third-party resources available
- May lack some advanced features present in zxing-android-embedded
Code Comparison
code-scanner
val scannerView = findViewById<CodeScannerView>(R.id.scanner_view)
val codeScanner = CodeScanner(this, scannerView)
codeScanner.decodeCallback = DecodeCallback {
runOnUiThread { Toast.makeText(this, it.text, Toast.LENGTH_SHORT).show() }
}
scannerView.setOnClickListener { codeScanner.startPreview() }
zxing-android-embedded
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0);
integrator.initiateScan();
Both libraries offer straightforward integration, but code-scanner provides a more modern, Kotlin-friendly approach. zxing-android-embedded uses an intent-based system, which may be more familiar to developers working with older Android codebases.
Modification of ZXING Barcode Scanner project for easy Android QR-Code detection and AR purposes
Pros of QRCodeReaderView
- Simpler implementation with fewer dependencies
- More lightweight and focused specifically on QR code reading
- Easier to customize and integrate into existing projects
Cons of QRCodeReaderView
- Less actively maintained (last update was in 2019)
- Limited to QR codes only, while zxing-android-embedded supports multiple barcode formats
- Fewer features and configuration options compared to zxing-android-embedded
Code Comparison
QRCodeReaderView:
qrCodeReaderView = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
qrCodeReaderView.setOnQRCodeReadListener(this);
qrCodeReaderView.setQRDecodingEnabled(true);
qrCodeReaderView.setAutofocusInterval(2000L);
qrCodeReaderView.startCamera();
zxing-android-embedded:
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
integrator.setPrompt("Scan a QR Code");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
Both libraries offer straightforward implementation, but zxing-android-embedded provides more configuration options out of the box. QRCodeReaderView focuses on simplicity and ease of use for QR code scanning, while zxing-android-embedded offers a more comprehensive barcode scanning solution with additional features and customization options.
a simple QRCode generation api for java built on top ZXING
Pros of QRGen
- Multi-platform support: Works on Java SE, Android, and Google App Engine
- Simpler API for generating QR codes
- Supports various output formats (PNG, SVG, etc.)
Cons of QRGen
- Limited to QR code generation only
- Less actively maintained (last update over 2 years ago)
- Fewer customization options for QR code appearance
Code Comparison
QRGen:
QRCode.from("Hello, World!").file();
zxing-android-embedded:
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
integrator.initiateScan();
QRGen focuses on simple QR code generation, while zxing-android-embedded provides a more comprehensive barcode scanning and generation solution for Android. The zxing-android-embedded library offers more features and customization options, particularly for scanning barcodes, but may have a steeper learning curve. QRGen is easier to use for basic QR code generation tasks but lacks advanced functionality and platform-specific optimizations for Android.
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
Pros of zxing
- More comprehensive barcode support, including 1D and 2D formats
- Wider platform compatibility, including Java SE and Android
- Larger community and more frequent updates
Cons of zxing
- Requires more setup and configuration for Android-specific use
- Larger library size, which may impact app size
- May require additional dependencies for Android integration
Code Comparison
zxing:
MultiFormatReader reader = new MultiFormatReader();
Result result = reader.decode(binaryBitmap);
String contents = result.getText();
zxing-android-embedded:
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
integrator.initiateScan();
zxing provides a more low-level API for barcode scanning, allowing for greater customization but requiring more setup. zxing-android-embedded offers a simpler, Android-specific implementation with an intent-based approach, making it easier to integrate into Android apps but with less flexibility.
zxing-android-embedded is specifically tailored for Android development, providing a more streamlined experience for Android developers. It includes pre-built UI components and handles camera permissions, making it quicker to implement barcode scanning in Android apps.
Both libraries are based on the zxing core, but zxing-android-embedded focuses on simplifying the integration process for Android developers, while zxing offers a more versatile solution for various platforms and use cases.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ZXing Android Embedded
Barcode scanning library for Android, using ZXing for decoding.
The project is loosely based on the ZXing Android Barcode Scanner application, but is not affiliated with the official ZXing project.
Features:
- Can be used via Intents (little code required).
- Can be embedded in an Activity, for advanced customization of UI and logic.
- Scanning can be performed in landscape or portrait mode.
- Camera is managed in a background thread, for fast startup time.
A sample application is available in Releases.
By default, Android SDK 24+ is required because of zxing:core
3.4.x.
SDK 19+ is supported with additional configuration, see Older SDK versions.
Adding aar dependency with Gradle
Add the following to your build.gradle
file:
// Config for SDK 24+
repositories {
mavenCentral()
}
dependencies {
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
}
Older SDK versions
By default, only SDK 24+ will work, even though the library specifies 19 as the minimum version.
For SDK versions 19+, one of the changes below are required. Some older SDK versions below 19 may work, but this is not tested or supported.
Option 1. Downgrade zxing:core to 3.3.0
repositories {
mavenCentral()
}
dependencies {
implementation('com.journeyapps:zxing-android-embedded:4.3.0') { transitive = false }
implementation 'com.google.zxing:core:3.3.0'
}
Option 2: Desugaring (Advanced)
This option does not require changing library versions, but may complicate the build process.
This requires Android Gradle Plugin version 4.0.0 or later.
See Java 8+ API desugaring support.
Example for SDK 21+:
android {
defaultConfig {
minSdkVersion 21
}
compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}
SDK 19+ additionally requires multiDex. In addition to these gradle config changes, the Application class must also be changed. See for details: Configure your app for multidex.
android {
defaultConfig {
multiDexEnabled true
minSdkVersion 19
}
compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation "androidx.multidex:multidex:2.0.1"
}
Hardware Acceleration
Hardware acceleration is required since TextureView is used.
Make sure it is enabled in your manifest file:
<application android:hardwareAccelerated="true" ... >
Usage with ScanContract
Note: startActivityForResult
is deprecated, so this example uses registerForActivityResult
instead.
See for details: https://developer.android.com/training/basics/intents/result
startActivityForResult
can still be used via IntentIntegrator
, but that is not recommended anymore.
// Register the launcher and result handler
private final ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(),
result -> {
if(result.getContents() == null) {
Toast.makeText(MyActivity.this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MyActivity.this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
});
// Launch
public void onButtonClick(View view) {
barcodeLauncher.launch(new ScanOptions());
}
Customize options:
ScanOptions options = new ScanOptions();
options.setDesiredBarcodeFormats(ScanOptions.ONE_D_CODE_TYPES);
options.setPrompt("Scan a barcode");
options.setCameraId(0); // Use a specific camera of the device
options.setBeepEnabled(false);
options.setBarcodeImageEnabled(true);
barcodeLauncher.launch(options);
See BarcodeOptions for more options.
Generate Barcode example
While this is not the primary purpose of this library, it does include basic support for generating some barcode types:
try {
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.encodeBitmap("content", BarcodeFormat.QR_CODE, 400, 400);
ImageView imageViewQrCode = (ImageView) findViewById(R.id.qrCode);
imageViewQrCode.setImageBitmap(bitmap);
} catch(Exception e) {
}
To customize the generated barcode image, use the setBackgroundColor
and setForegroundColor
functions of the
BarcodeEncoder
class with a @ColorInt
value to update the background and foreground colors of the barcode respectively. By default, the barcode has a
white background and black foreground.
Changing the orientation
To change the orientation, specify the orientation in your AndroidManifest.xml
and let the ManifestMerger
to update the Activity's definition.
Sample:
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation" />
ScanOptions options = new ScanOptions();
options.setOrientationLocked(false);
barcodeLauncher.launch(options);
Customization and advanced options
See EMBEDDING.
For more advanced options, look at the Sample Application, and browse the source code of the library.
This is considered advanced usage, and is not well-documented or supported.
Android Permissions
The camera permission is required for barcode scanning to function. It is automatically included as part of the library. On Android 6 it is requested at runtime when the barcode scanner is first opened.
When using BarcodeView directly (instead of via IntentIntegrator / CaptureActivity), you have to
request the permission manually before calling BarcodeView#resume()
, otherwise the camera will
fail to open.
Building locally
./gradlew assemble
To deploy the artifacts the your local Maven repository:
./gradlew publishToMavenLocal
You can then use your local version by specifying in your build.gradle
file:
repositories {
mavenLocal()
}
Sponsored by
License
Licensed under the Apache License 2.0
Copyright (C) 2012-2022 ZXing authors, Journey Mobile
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Top Related Projects
Barcode Scanner Libraries for Android
Code scanner library for Android, based on ZXing
Modification of ZXING Barcode Scanner project for easy Android QR-Code detection and AR purposes
a simple QRCode generation api for java built on top ZXING
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot