How to Add an Android Barcode Scanner Library
| Developers
:format(jpeg))
Integrating a barcode scanner into your Native Android app isn’t as easy as you think.
It requires more than setting camera permissions and capturing camera images. You also need to consider UX and performance principles.
Here’s a familiar development scenario: you’re creating a Native Android application, a journey of long days and unending bugs, and there’s a nagging thought at the back of your mind. The app’s barcode scanning functionality — a small but critical part of your app — will inevitably face testing by real users in real-world situations you hadn’t considered. You have no idea whether the feedback will be good or bad, and the team’s focus is taken up by other features.
The trick to choosing the right barcode scanner library for your app and avoiding common barcode scanning challenges is understanding what barcode scanning users want, and what they need to make them productive in the long term.
Whether you’re a UX expert or not, this blog explains the key user and performance principles to successfully integrate an Android barcode scanner library into your Native Android app. We’ve included a step-by-step tutorial for deploying Scandit SparkScan for Native Android, a pre-built barcode scanning component that puts a minimalistic UI on top of any Android application.
To create a native Android barcode scanner, we’ll walk through these steps using a sample application:
- Add the SparkScan SDK for Android to your project.
- Create a Data Capture Context instance.
- Change supported symbologies for your use case.
- Change the scanning mode.
- Customize the user interface.
- Register a listener for new barcode scans.
If you want a head start with barcode scanning, download and run one of our Android samples on your development device now.
Start barcode scanning on Native Android
Add enterprise-class barcode scanning fast with SparkScan.
Why UX matters for Android barcode scanning
Integrating a barcode scanning library for Android is like trying to solve the platform’s hardware fragmentation issues. The complexity (often unexpected) can be overwhelming if you don’t have the tools or expertise to deliver the best user experience. Read our blog on how barcode scanners work to learn the technical factors behind barcode scanning and symbologies.
Happy users need more than a camera and event handler
While barcode scanning may seem easy, there can be significant downstream problems with user adoption if you don’t get navigation, interaction and feedback right.
Open-source options often require you to develop your own user interface (UI), incurring all the research, development, and testing costs. Paid libraries tend to include pre-built UI components that reduce your reliance on UX expertise and effort.
Understanding the UX workflows below will help you choose the best Native Android barcode scanner library for your application development. The following video demonstrates how SparkScan for Android enables you to build rich UIs without worrying about image capture logic, barcode decoding, or UX workflows. For example, SparkScan comes pre-built with a collapsed floating button that users swipe or tap to activate a camera preview for barcode scanning. You can adjust the location of this preview on screen directly behind the hardware camera for easier aiming.
Starting the scanning process
Android users don’t want to navigate through complex menus or switch between the app and a different interface when scanning barcodes. For enterprise apps in particular, an inconvenient and disconnected experience incurs job performance hits that can impact operations.
Good UX requires a seamless transition from the main application into scanning mode. The following video demonstrates how the Scandit SparkScan Native Android barcode scanner API enables users to swipe or tap a collapsed floating button to activate the scanner. It then provides a large, semi-transparent button to capture barcodes.
In-camera aiming assist
Aiming a smartphone camera is a difficult task in situations where the barcode is far away from the device, or when users must bend or lie down to scan packages in hard-to-reach placements.
It’s also challenging when packages have multiple barcodes printed on them. As a number of barcodes will be in the camera’s field of view at the same time, the user is forced to spend time aiming and selecting the right one.
Features like on-screen guides, visual hints, or even augmented reality (AR) overlays help users position the camera correctly.
Here are two examples of desirable in-app features:
- A viewfinder to help the user understand that scanning is live and position the camera appropriately.
- Restricting the scan area to help capture barcodes in cluttered areas. This also improves performance on low-end Android devices.
Like all Scandit software, SparkScan for Android includes context-based AI scanning that reduces unwanted scans by up to 100%. This feature is known as Smart Scan Intention and it uses contextual data, such as device movement and barcode characteristics, to capture the correct barcode even with imprecise aiming.
Strong and clear feedback
Your Android app should provide immediate and unambiguous feedback on the success or failure of a barcode scan. A delayed or confusing response leads to user frustration, especially in loud environments or locations where it’s hard to see the device’s screen.
Helpful feedback mechanisms include visual and auditory cues such as:
- Drawing a symbol, like a brush overlay, at the location of the detected barcode to confirm that your app scanned the intended item.
- Playing a sound and vibrating the device when the scanner performs a capture.
Supporting different scan modes
Allowing users to choose between single scans and continuous scanning modes helps them adapt to different situations where the number or configuration of barcodes varies (such as a warehouse or retail store).
SparkScan has two modes built into its Native Android barcode scanner SDK:
- Single scan: the user triggers the scanner for every barcode, providing greater control over the scanning experience.
- Continuous scan: The user triggers the scanner once and the app scans multiple barcodes without further interaction, reducing user fatigue.

Testing the Scandit Android SDK is easy
Integrate with just a few lines of code or use our samples.
Which barcode scanner is best for Native Android?
An open-source Android barcode scanner library that’s hard to use or slow to scan may be sufficient if you’re scanning at a low frequency. However, it’s likely not best suited for an environment such as a warehouse processing thousands of items daily. Like any Android app, performance is as much about your chosen library as the code you write around it.
Here are some considerations to think about when selecting your scanner SDK.
1. Scanner performance
Whether deployed in an enterprise or commercial environment, you should consider and measure against the following performance requirements:
- Accuracy: Relying on barcode scanning for inventory management, asset tracking, quality control, and similar operations requires a barcode scanning library that ensures the right items are selected, picked, and tracked. Also look for advanced features that improve accuracy, such as context-based scanning to capture the right data on every scan and reduce the number of unwanted scans.
- Speed: A barcode scanning library that captures and processes images fast on Android devices means faster business operations.
- Multi-modal data capture: Advanced libraries can extract barcode and text data simultaneously, which reduces the overall scanning time and the likelihood of manual input errors. Scandit’s Android Barcode Scanner SDK achieves this through multi-modal data capture, making data entry up to seven times faster than scanning labels separately.
- Handling tough barcodes: A barcode may be torn, partially obscured, wrapped in plastic, under low light, or reflecting light to cause camera glare — your Android library should be able to handle all these conditions.
- Capturing multiple barcodes simultaneously: Employees may need to scan multiple barcodes at once or in quick succession, such as a worker in a fulfillment center required to scan a product barcode and a location barcode fast to meet shipping times. SDKs for single scanning don’t have the intelligence to distinguish between multiple labels in the camera’s field-of-view and track them over time. Multiple barcode scanning libraries, such as Scandit MatrixScan, can identify and track tens of codes simultaneously, without getting confused by device movement or duplicates.
- Field-of-view and distance: Scanners often have to deal with barcodes on objects of various sizes, shapes, and distances from the device. An SDK like Scandit allows users to scan tiny barcodes and electronic shelf labels (ESLs) comfortably from far away without compromising speed or accuracy.
Read our blog on optimizing barcode scanning app performance to get a list of features to look for when comparing performance between libraries.
2. Device support
Enterprises often have a diverse fleet of Android-based employee devices — especially in Bring-Your-Own-Device (BYOD) situations — with different camera specifications and processor architectures.
Your barcode scanner library must be compatible with a wide range of Android devices. This ensures employees have a consistent user experience and avoids the need to retrain on every new device. (You can see SparkScan’s system requirements here.)
It must also be optimized for performance on your Android models so users don’t have to wait for scan results to complete. Given the wide range of Android devices and camera specifications, performance optimization can be difficult to find with most open-source packages.
Users want apps to launch quickly, render smoothly, and require little memory and battery usage.
We list important performance tests below to gauge how your scanning solution performs.
3. Support for different development frameworks
For developers using a cross-platform development framework, check that your barcode scanner library supports it. The Scandit SDK is also available for Native iOS, JavaScript, Cordova, Xamarin and Xamarin.Forms, .NET (iOS/Android and MAUI), React Native, Flutter, Capacitor, and Titanium.
4. Advanced scanning features
As your users become familiar with barcode scanning and as operations change, you will see bug reports and requests to improve features. Managers may want performance improvements and users may desire UI tweaks to make their jobs easier.
Choosing an Android barcode scanner SDK that has optional features built-in makes it easier to scale. Ideally, you can get the software integrated fast for the initial release and extend capabilities over time.
Scandit’s Android barcode scanning library includes these features:
- Support for scanning multiple barcodes at once and tracking them over time with MatrixScan. This reduces the time it takes to capture inventory counts, pick and pack items, and other high-volume barcode scenarios.
- Smart Label Capture to embed multi-modal data capture (reading barcodes and printed text simultaneously) into your Android app. This feature extracts data up to 7 times faster for labels containing different items such as pricing, serial numbers, and item weights.
- Augmented reality (AR) with MatrixScan Find to help users find the right item among many items with minimal effort.
5. Support
Any business-level app requires enterprise-level developer support. For your barcode scanner, look for:
- Android-specific code samples to help you get started and familiarize yourself with the SDK.
- Documentation that includes tutorials and API reference guides.
- Regular updates (verify the release cadence by looking at the release notes) to ensure you have the latest features, bug fixes, and security patches.
- Options for technical help from developers familiar with the software and its users.
Scandit’s Enterprise-Level Success Team helps you go from free trial to day-to-day operations in production. They can ensure your Android barcode scanning integration goes smoothly and fine-tune the application software for high-volume scanning.
6. Security and privacy
You must determine how your Android barcode scanner SDK protects sensitive information in transit and at rest. At a minimum, it must comply with your organization’s security and privacy policies and with the applicable standards for your industry.
Scandit takes a security by design approach to all its software, where you have complete control over data collection and processing. This means:
- All image processing happens on the device to ensure confidentiality and high availability of scanning.
- Any data you choose to share with Scandit is encrypted during transit and at rest.
- Scandit is ISO 27001:2022 Certified and compliant with applicable privacy regulations that include GDPR and CCPA.
How do I create a barcode scanner for Native Android?
SparkScan allows developers to add pre-built and intuitive barcode scanner capabilities, along with a minimalistic UI that floats on top of any Android (or iOS) app.
The SparkScan Native Android barcode scanner SDK is built upon well-researched UX principles and optimized through feedback from thousands of customers across various environments. SparkScan’s interface includes a small camera preview window and a large, moveable, semi-transparent trigger button that users can drag to any screen position. When not in use, the preview window disappears and the trigger button collapses to occupy minimum space on the user’s screen.
Get started with SparkScan for Native Android
The fastest way to see if SparkScan will work for you is to run one of our Android barcode scanning examples from GitHub on your development device.
The prerequisites for these steps are:
- The latest stable version of the Android SDK (for example, through the latest Android Studio).
- An Android project with target SDK version 23 (Android 6, Marshmallow) or higher.
- A valid Scandit Data Capture SDK license key. You can sign up for a free test account at ssl.scandit.com.
1. Add the SparkScan SDK to your project
Before setting up SparkScan, you need to obtain a valid Scandit Data Capture SDK license key:
If you already have a paid subscription, contact support@scandit.com for a new license key.
SparkScan is part of the Scandit Data Capture SDK, which is distributed as AAR libraries in the official Scandit maven repository.
You must add a reference to com.scandit.datacapture:core, which contains the shared functionality used by the other data capture modules.
To add SparkScan barcode-related functionality, add a reference to com.scandit.datacapture:barcode (the ScanditBarcodeCapture API)
1. To add SparkScan using Gradle
Add mavenCentral() repository to the build.gradle file:
repositories { mavenCentral() }
Add the necessary artifacts as dependencies to the app’s build.gradle as required:
dependencies { implementation "com.scandit.datacapture:core:[version]" implementation "com.scandit.datacapture:barcode:[version]" }
Note that the core module depends on okhttp version 4.9.2. If your project already implements a different version of okhttp (within the supported version range specified in the requirements page), make sure to exclude the group from the Gradle implementation of the core module:
implementation("com.scandit.datacapture:core:[version]") { exclude group: "com.squareup.okhttp3" }
2. To add SparkScan using Maven
Add the mavenCentral repository to the pom.xml file:
<repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Maven Central</name> <url>https://repo1.maven.org/maven2</url> </repository> </repositories>
Add the necessary artifacts as dependencies as required:
<dependency> <groupId>com.scandit.datacapture</groupId> <artifactId>core</artifactId> <version>[version]</version> </dependency> <dependency> <groupId>com.scandit.datacapture</groupId> <artifactId>barcode</artifactId> <version>[version]</version> </dependency>
3. Additional steps and considerations
If you’re using the androidx.fragments dependency and experience a situation where a scanning fragment navigates to another scanning fragment with an incompatible mode, make sure you’re using version 1.3.0+ of the dependency. If not, you may run into an incompatible modes error, as the new fragment gets resumed before the previous is paused and for some time, incompatible modes may be enabled in the DataCaptureContext simultaneously. This leads to empty results in sessions.
The Scandit SDK uses content providers to initialize scanning capabilities. If your content providers depend on the Scandit SDK, choose an initOrder lower than 10 to make sure the SDK is ready first. If not specified, initOrder is zero by default and you have nothing to worry about.
For more information, read the official Android <provider> documentation.
Camera permissions for Android: When using the Scandit Data Capture SDK, you must set the camera as the frame source for barcode, text, and label capture. To do this, you must request camera permissions in your application before starting scanning. To see how to achieve this, take a look at our samples.
If you’re integrating SparkScan into a Compose view hierarchy, follow these steps:
- Create an AndroidView to wrap the SparkScanView instance, initialized as described below.
- Monitor the view lifecycle so you can call the view lifecycle methods in SparkScanView when necessary. You can do this using a combination of DisposableEffect and the onRelease callback of AndroidView.
2. Create a new Data Capture Context instance
The next step to add barcode scanner capabilities to your Android application is to create a new Data Capture Context. The context expects a valid Scandit Data Capture SDK license key during construction.
DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --");
3. Configure the SparkScan Mode
The SparkScan Mode is configured through SparkScanSettings, allowing you to register one or more listeners that are informed whenever a new barcode is scanned.
For this blog, we set up SparkScan for scanning EAN13 codes. Change this to the symbologies for your use case (for example, Code 128, Code 39).
SparkScanSettings settings = new SparkScanSettings(); HashSet symbologies = new HashSet<>(); symbologies.add(Symbology.EAN13_UPCA); settings.enableSymbologies(symbologies);
Next, create a SparkScan instance with the settings initialized in the previous step:
SparkScan sparkScan = new SparkScan(settings);
4. Create the SparkScan View
The SparkScan built-in user interface includes the camera preview and scanning UI elements. These guide the user through the scanning process.
The SparkScanView appearance can be customized through SparkScanViewSettings.
SparkScanViewSettings viewSettings = new SparkScanViewSettings(); // setup the desired appearance settings by updating the fields in the object above
Adding a SparkScanView automatically adds the scanning interface (camera preview and scanning UI elements) to your application.
Next, add a SparkScan View to your view hierarchy by constructing a new SparkScan view. The SparkScan view is automatically added to the provided parentView:
SparkScanView sparkScanView = SparkScanView.newInstance(parentView, dataCaptureContext, sparkScan, viewSettings);
See SparkScan Workflow Options for instructions on how to change the scanning mode, set camera preview behavior, and set the scanning behavior to either single scan or continuous scan.
Additionally, call sparkScanView.onPause() and sparkScanView.onResume() in your Fragment/Activity onPause and onResume callbacks. You have to call these to ensure the correct functioning of the SparkScanView.
@Override protected void onPause() { sparkScanView.onPause(); super.onPause(); } @Override protected void onResume() { sparkScanView.onResume(); super.onResume(); }
5. Register the listener to be informed when a new barcode is scanned
To keep track of the scanned barcodes, implement the SparkScanListener interface and register the listener to the SparkScan mode.
// Register self as a listener to monitor the SparkScan session. sparkScan.addListener(this);
SparkScanListener.onBarcodeScanned() is called when a new barcode is scanned. This result is retrieved from the first object in the provided barcodes list: SparkScanSession.newlyRecognizedBarcodes. Note that this list only contains one barcode entry.
@Override public void onBarcodeScanned( @NonNull SparkScan sparkScan, @NonNull SparkScanSession session, @Nullable FrameData data ) { // Gather the recognized barcode Barcode barcode = session.getNewlyRecognizedBarcodes().get(0); // This method is invoked from a recognition internal thread. // Run the specified action in the UI thread to update the internal barcode list. runOnUiThread(() -> { // Update the internal list and the UI with the barcode retrieved above this.latestBarcode = barcode }); }
6. Customize the scanning UI with advanced configurations
You can customize the SparkScan UI and UX using advanced configurations. This includes changing UI element colors (i.e. icons, buttons, toolbar), the trigger button icon, the size of the preview window, and more.
The graphic illustrates different examples of how you can adjust colors, positions, and sizes to suit different UX scenarios.
How to test the performance of barcode scanning on Native Android
The best way to test a potential Android barcode scanning API is to try it out in the real world. Whether you installed SparkScan or another barcode scanning library, here are several performance-testing questions to ask yourself:
- Is there clear guidance, feedback, and helpful hints to foster a smooth workflow rather than a confused, error-prone activity?
- Can you scan barcodes in different orientations, such as upside down and sideways? Flip the phone upside down to see how the scanner performs.
- Can you scan barcodes with reflections and glare?
- Can you scan barcodes at a distance? Are you able to zoom in if needed?
- Do you receive scanning feedback in loud environments and while wearing headphones?
You can also use our barcodes sample sheet for quick evaluation. Our developer guide on how to measure barcode scanning performance provides a systematic, use-case-based approach to validate your Android app against requirements.
Your Native Android barcode scanner SDK is more than just a technical choice
Prioritizing UX when selecting and implementing an Android barcode scanner library makes your life easier. Simplified usage, fewer user frustrations, and rapid adaptability to growing business demands pave the way toward increased adoption and productivity.
Next: Dive deeper into how to make a barcode scanning app performant →