ML KIT条形码扫描仪不停止检测到
我正在尝试使用条形码扫描仪(RawValue和Format)从Camerax和ML套件中获取两个值,但是当检测到第一个时,我无法停止扫描并将数据插入房间。我的代码插入在房间中的代码插入数量是许多元素,因为在此过程中检测到许多条形码(相同的条形码很多次),
这是我在ProcessImageProxy函数中的addonSuccessListener:
scanner.process(inputImage).addOnSuccessListener { barcodeList ->
processBarcode(barcodeList)
}
这是我保留数据的实际方法:
private fun processBarcode(barcodeList: List<Barcode>) {
if (barcodeList.isNotEmpty()) {
with (barcodeList.first()) {
activityCameraScannerViewModel.rawValue = this.rawValue.toString()
activityCameraScannerViewModel.format = this.format.toString()
activityCameraScannerViewModel.setNewCard()
val intent = Intent(applicationContext, MainActivity::class.java)
intent.putExtra("rawValue", this.rawValue.toString())
intent.putExtra("format", this.format.toString())
startActivity(intent)
}
}
}
代码的实际结果很多。插入物(其中的随机数)。 感谢任何帮助。如果有人需要更多代码,我将编辑该问题。 谢谢。
I'm trying to get two values from cameraX and ML Kit using the barcode scanner (rawValue and format) but I can't stop the scan and insert data into room when the first one is detected. My code inserts in room as many elements as many barcodes are detected in the process (the same barcode many times)
This is my addOnSuccessListener in the processImageProxy function:
scanner.process(inputImage).addOnSuccessListener { barcodeList ->
processBarcode(barcodeList)
}
And this is my actual method to keep data:
private fun processBarcode(barcodeList: List<Barcode>) {
if (barcodeList.isNotEmpty()) {
with (barcodeList.first()) {
activityCameraScannerViewModel.rawValue = this.rawValue.toString()
activityCameraScannerViewModel.format = this.format.toString()
activityCameraScannerViewModel.setNewCard()
val intent = Intent(applicationContext, MainActivity::class.java)
intent.putExtra("rawValue", this.rawValue.toString())
intent.putExtra("format", this.format.toString())
startActivity(intent)
}
}
}
The actual result of code is a lot of inserts (random number of them).
I would appreciate any help. If anybody need more code I will edit the question.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需分辨率:
将扫描仪作为processbarcode函数的参数和调用
scanner.close()
完成代码:
Simply resolution:
Pass scanner as parameter of processBarcode function and call
scanner.close()
Complete code:
如果使用相机提供商,请使用:
If you use a camera provider, use: