Barcode Scanning is a technology for reading and decoding barcodes using a mobile device camera. Unlike laser scanners that require specialized equipment, camera-based scanners work on any smartphone with a camera. In mobile development, Barcode Scanning is implemented via ML Kit Barcode Scanning (Google), AVFoundation (Apple), ZXing (open-source) or Scandit (commercial SDK). According to Google ML Kit, 2025, the library processes 2+ billion scans per day with 98.5% accuracy.
Key Takeaways
Barcode Scanning is the process of optically recognizing barcodes using a camera. The algorithm captures an image, finds the code (localization), decodes it (data extraction) and returns a string value. Modern SDKs can scan codes of any orientation, size and lighting — the user just needs to point the camera.
Barcode formats are divided into two groups: 1D (linear) — EAN-13, UPC-A, Code 128, Code 39, ITF, Codabar — contain up to 20–30 characters, used for products and logistics; 2D (matrix) — QR Code, Data Matrix, PDF417, Aztec — contain up to 3000+ characters, used for links, tickets, documents. ML Kit supports 14 formats — all common 1D and 2D formats.
Data Matrix is a 2D code similar to QR but more compact. It is used in industry (parts marking), electronic tickets (IATA BCBP), medical samples. Data Matrix can hold up to 2335 characters and can be printed on very small surfaces — down to 2x2 mm. Unlike QR, Data Matrix has no finder patterns (squares in corners) and requires more precise camera calibration.
| Format | Type | Max Data | Application |
|---|---|---|---|
| EAN-13 | 1D | 13 digits | Retail products |
| QR Code | 2D | 4296 characters | Links, payments, tickets |
| Data Matrix | 2D | 2335 characters | Industry, medicine |
| PDF417 | 2D | 2710 characters | Documents, boarding passes |
| Code 128 | 1D | 80 characters | Logistics, transport |
QR Code is the most popular 2D format in mobile applications. It contains URLs, text, vCard, WiFi configuration, payment information (UPI, SBP). QR Code has 40 versions (from 21x21 to 177x177 modules) and 4 error correction levels (L: 7%, M: 15%, Q: 25%, H: 30%). For mobile apps use version 2–10 (25x25 – 57x57 modules) — the optimal balance of size and data capacity.
ML Kit Barcode Scanning is the primary SDK for Android applications. ML Kit automatically finds all codes in the image (unlike ZXing which requires the code to be in the center). The API returns a Barcode object with rawValue (text content), format (code type), boundingBox and cornerPoints (4 corner points of the code). ML Kit supports single-scan (one frame) and continuous-scan (video stream).
Multi-barcode mode — ML Kit can detect multiple codes in a single image. Enable via BarcodeScannerOptions.Builder(). In multi-mode, a list of Barcodes is returned. Use for inventory (scanning batches of products), recognizing multiple QR codes on a table. Multi-barcode is disabled by default — enable only if needed as it slows scanning by 20–30%.
// ML Kit Barcode Scanning multi-code mode
val options = BarcodeScannerOptions.Builder()
.setBarcodeFormats(
Barcode.FORMAT_QR_CODE,
Barcode.FORMAT_EAN_13,
Barcode.FORMAT_DATA_MATRIX
)
.enableAllPotentialBarcodes()
.build()
val scanner = BarcodeScanning.getClient(options)
scanner.process(inputImage)
.addOnSuccessListener { barcodes ->
barcodes.forEach { barcode ->
val type = barcode.valueType // URL, TEXT, PHONE...
val rawValue = barcode.rawValue
val displayValue = barcode.displayValue
}
}
Format filtering — mandatory optimization. setBarcodeFormats() limits the formats ML Kit will search for. If the app scans only QR codes — specify FORMAT_QR_CODE. This speeds up scanning by 2–3 times by excluding decoding algorithms for other formats. For retail scanners — FORMAT_EAN_13 | FORMAT_UPC_A. For logistics — FORMAT_CODE_128 | FORMAT_CODE_39 | FORMAT_PDF417.
ZXing (Zebra Crossing) is an open-source library in Java (Android) with ports to Swift, React Native, Flutter. ZXing was the de facto standard for scanning before ML Kit. It supports all popular formats, works on any device (including Huawei without Google Play), and does not require Google Play Services. Disadvantages: 2–3 times slower than ML Kit, does not find codes at the edge of the frame, no multi-barcode.
ML Kit vs ZXing — ML Kit wins in speed, accuracy and UX. ML Kit detects a code even if it occupies 10% of the frame and is in the corner. ZXing requires the code to occupy 50–80% of the frame and be in the center. ML Kit uses a neural network (MobileNetV2-SSD) for code localization, ZXing uses classic binarization and finder pattern search. According to Google (2025), ML Kit achieves 98.5% accuracy vs 92% for ZXing.
| Characteristic | ML Kit | ZXing |
|---|---|---|
| Accuracy | 98.5% | 92% |
| Speed | 15–30 ms | 50–150 ms |
| Multi-code | Yes | No |
| Google Play | Required | Not required |
| Code in corner | Detects | Does not detect |
When to choose ZXing: if the app must run on Huawei devices (without Google Play Services), on Android Go (limited memory), or if full offline operation without Play Services is needed. For all other cases — ML Kit is faster, more accurate, easier to integrate and provides a better UX thanks to multi-code and edge detection.
// ZXing Core: simple scanner
val reader = MultiFormatReader()
val bitmap = BitmapFactory.decodeResource(resources, R.drawable.test)
val source = RGBLuminanceSource(bitmap)
val binarizer = HybridBinarizer(source)
val binaryBitmap = BinaryBitmap(binarizer)
try {
val result = reader.decode(binaryBitmap)
Log.d("ZXing", result.text)
} catch (e: NotFoundException) {
// Code not found
}
Scandit as an alternative — a commercial SDK with 99.5% accuracy and 10–20 ms speed. It uses proprietary neural networks and does not require Google Play Services. Price — from $400/month (2019). Scandit dominates in retail and logistics (Walmart, FedEx). For most mobile apps ML Kit is sufficient — Scandit is justified only for enterprise tasks with high-volume scanning.
Apple AVFoundation provides native Barcode Scanning via AVCaptureMetadataOutput. Starting from iOS 7, AVFoundation supports QR code scanning, and since iOS 8 — all formats EAN, UPC, Code 128, PDF417. AVFoundation does not require additional SDKs — it is part of Foundation. Scanning runs through Apple Neural Engine on A12+ — speed 10–20 ms with minimal power consumption.
Advantages of AVFoundation: zero dependencies, automatic camera orientation handling, built-in light/dark mode support, background operation (with background modes). AVFoundation automatically adjusts autofocus and exposure for scanning — the developer only needs to subscribe to the captureOutput delegate. Disadvantage: fewer settings than ML Kit — cannot enable multi-barcode or format filtering.
import AVFoundation
class BarcodeScannerController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
private var captureSession: AVCaptureSession!
override func viewDidLoad() {
let metadataOutput = AVCaptureMetadataOutput()
captureSession.addOutput(metadataOutput)
metadataOutput.setMetadataObjectsDelegate(self, queue: .main)
metadataOutput.metadataObjectTypes = [.qr, .ean13, .code128]
}
func metadataOutput(_ output: AVCaptureMetadataOutput,
didOutput objects: [AVMetadataObject],
from connection: AVCaptureConnection) {
guard let code = objects.first as? AVMetadataMachineReadableCodeObject else { return }
print(code.stringValue ?? "")
}
}
ML Kit vs AVFoundation on iOS: ML Kit gives more control — you can configure formats, enable multi-barcode, filter codes by confidence. AVFoundation is faster on older devices (less overhead), but does not support Data Matrix, Aztec, PDF417 on iOS < 15. For iOS 15+ ML Kit is preferable. For iOS 12–14 use AVFoundation + fallback to ML Kit for unsupported formats.
Scandit is a commercial SDK for Barcode Scanning focused on retail, logistics and healthcare. Scandit uses proprietary neural networks trained on 10+ million barcode images in various conditions: glare, damage, low light, tilt up to 45°, reflections. Scandit scans codes at distances up to 15 meters (for PDF417 in warehouses) and on curved surfaces (cans, bottles).
Scandit features: SparkScan (single-scan for fast sequential scanning), MatrixScan (multi-barcode + AR highlighting of scanned items), PickList (product search by barcode with confirmation). Scandit supports 50+ formats, including GS1 DataBar and Composite Codes. Speed — 10–15 ms per code. Accuracy — 99.5% in standard lighting, 97% in poor lighting.
// Scandit MatrixScan (SDK license required)
val barcodeTracking = BarcodeTracking
.forDataCaptureContext(context)
.addListener(this)
.build()
barcodeTracking.addSessionListener { session, _ ->
session.trackedBarcodes.forEach { (trackingId, barcode) ->
val data = barcode.data
val symbolCount = barcode.symbolCount
}
}
Scandit vs ML Kit: Scandit is paid ($400+/month), but provides enterprise features: SparkScan (hardware button on corporate devices), MatrixScan (AR overlay for highlighting), PickList (voice confirmation). ML Kit is free and sufficient for 90% of mobile apps: retail scanners, QR readers, ticket apps. Scandit is justified only for logistics terminals with Zebra/Honeywell devices.
Barcode Scanning optimization includes camera, resolution and SDK settings. The main rule: fewer pixels — faster scanning. For ML Kit the optimal resolution is 480p (640x480) for video and 720p (1280x720) for photos. Increasing to 1080p slows processing by 2–3 times without accuracy improvement. Use CameraX with ImageAnalysis for automatic resolution management.
Focus and exposure are critical for scanning quality. ML Kit does not configure the camera automatically — the developer must enable continuous auto-focus and continuous auto-exposure via Camera2 or CameraX. Without autofocus, blurry codes reduce accuracy to 60–70%. For close-range scanning (5–15 cm) use camera macro mode if available.
Auto-zoom and finder overlay — user UX improvements. Auto-zoom magnifies the code when detected (like in Google Lens camera). Implemented by analyzing the code boundingBox and scaling the preview. Finder overlay is a graphic frame showing where to point the camera. For best UX, show the boundingBox of the found code and highlight it in green upon successful decoding.
// CameraX + ML Kit: optimized scanner
class BarcodeAnalyzer(private val scanner: BarcodeScanner) :
ImageAnalysis.Analyzer {
override fun analyze(image: ImageProxy) {
if (image.image == null) { image.close(); return }
val mediaImage = InputImage.fromMediaImage(image.image, image.imageInfo.rotationDegrees)
scanner.process(mediaImage)
.addOnSuccessListener { barcodes ->
barcodes.firstOrNull()?.let {
// Haptic + sound + code highlight
}
}
.addOnCompleteListener { image.close() }
}
}
User feedback: vibration (HapticFeedback), sound (MediaActionSound), visual highlighting (Canvas/Overlay). After a successful scan, add a 1000–1500 ms delay (throttling) before the next scan — this prevents duplicate triggers on the same code. For sequential scanning (batch scanning) use the SparkScan approach: each scan is recorded and announced, with a 300–500 ms delay.
Frequently Asked Questions
ML Kit Barcode Scanning is the best choice for Android: free, 98.5% accuracy, multi-code, detection in any part of the frame. If the app must run on Huawei devices without Google Play — use ZXing (open-source, lower accuracy). For enterprise logistics — Scandit (paid, 99.5% accuracy, SparkScan). For a simple QR scanner ZXing or ML Kit is sufficient.
ML Kit Barcode Scanning supports 14 formats: 1D — EAN-8, EAN-13, UPC-A, UPC-E, Code 39, Code 93, Code 128, ITF, Codabar; 2D — QR Code, Data Matrix, PDF417, Aztec. GS1 DataBar (RSS-14, RSS-Expanded) is also supported. The full list is in the Barcode.FORMAT_* documentation. To limit formats use setBarcodeFormats() — this speeds up scanning by 2–3 times.
Reduce camera resolution to 480p (640x480), enable continuous auto-focus, limit formats to needed ones (setBarcodeFormats), use FAST performance mode. For ML Kit specify only necessary formats — excluding extra formats speeds up scanning by 2–3 times. For ZXing — use HybridBinarizer instead of GlobalHistogramBinarizer (20% faster). For AVFoundation — specify metadataObjectTypes.
Yes, all local Barcode Scanning SDKs (ML Kit, ZXing, AVFoundation, Scandit) work fully offline. ML Kit requires internet only for the initial model download (downloaded mode), after which the model is cached on the device. AVFoundation is built into iOS, no internet required. ZXing is fully offline without Play Services. Cloud scanning (Google Cloud Vision) is not used in mobile apps.
ML Kit and Scandit have built-in correction for damaged codes thanks to neural network algorithms. ML Kit restores up to 30% of a damaged code (scratches, tears). Scandit — up to 50% thanks to training on defective codes. ZXing practically does not restore damaged codes — it requires a clear image. For scanning defective codes use Scandit or ML Kit with ACCURATE performance mode.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also