Skip to content

Commit ebd2a86

Browse files
Support additional barcode formats in scanner (#17)
* Support additional barcode formats in scanner Expanded barcode scanning to include CODE_128, CODE_39, CODE_93, UPC_E, and QR_CODE formats in both the service and camera preview. This allows the app to recognize a wider variety of barcodes beyond EAN-8 and EAN-13. * Remove QR code support from barcode scanning QR code format has been removed from the list of supported barcode formats in both BarcodeScannerService and CameraPreview. Only UPC_E and other code formats are now scanned. --------- Co-authored-by: Vishal Paliwal <paliwalvishal16@gmail.com>
1 parent d964406 commit ebd2a86

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

app/src/main/java/lc/fungee/IngrediCheck/model/source/mlkit/BarcodeScannerService.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,17 @@ class MlKitBarcodeScanner : BarcodeScannerService {
7676
val image = InputImage.fromBitmap(bmp, 0)
7777
val scanner = BarcodeScanning.getClient()
7878
val barcodes = scanner.process(image).await()
79-
barcodes.firstOrNull { it.rawValue?.isNotBlank() == true &&
80-
(it.format == Barcode.FORMAT_EAN_8 || it.format == Barcode.FORMAT_EAN_13)
79+
barcodes.firstOrNull {
80+
it.rawValue?.isNotBlank() == true &&
81+
(
82+
it.format == Barcode.FORMAT_EAN_8 ||
83+
it.format == Barcode.FORMAT_EAN_13 ||
84+
it.format == Barcode.FORMAT_CODE_128 ||
85+
it.format == Barcode.FORMAT_CODE_39 ||
86+
it.format == Barcode.FORMAT_CODE_93 ||
87+
it.format == Barcode.FORMAT_UPC_E
88+
)
89+
//added more types of barcode to scan and + QR code
8190
}?.rawValue
8291
} catch (t: Throwable) {
8392
Log.e("Barcode", "Error detecting barcode from image", t)

app/src/main/java/lc/fungee/IngrediCheck/ui/view/component/CameraPreview.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ fun CameraPreview(
152152
// Use cases shared across modes
153153
val options = remember {
154154
BarcodeScannerOptions.Builder()
155-
.setBarcodeFormats(Barcode.FORMAT_EAN_8, Barcode.FORMAT_EAN_13)
155+
.setBarcodeFormats(
156+
Barcode.FORMAT_EAN_8,
157+
Barcode.FORMAT_EAN_13,
158+
Barcode.FORMAT_CODE_128,
159+
Barcode.FORMAT_CODE_39,
160+
Barcode.FORMAT_CODE_93,
161+
Barcode.FORMAT_UPC_E
162+
)
156163
.build()
157164
}
158165
val scanner = remember { BarcodeScanning.getClient(options) }

0 commit comments

Comments
 (0)