如何停止扫描和存储来自 Google Vision API 的数据?

人气:499 发布:2022-10-16 标签: barcode-scanner qr-code android-intent android-studio google-vision

问题描述

我在我的项目中使用了 Google 的 Vision API BarcodeScanner.我想在扫描代码后中断扫描并将内容存储在另一个活动中.我怎样才能做到这一点 ?有这么多的类和互连":x

I'm using Google's Vision API BarcodeScanner on my project. I would like to interrupt scanning once a code has been scanned and store the content in another activity. How can i do that ? There are so many classes and 'interconnections' :x

谢谢!

推荐答案

因此,就停止扫描而言,我通过在我的 BarcodeDetector 上调用 .release() 使其工作 实例.我跟着这个例子 正如你所看到的,他们为 BarcodeDetector 设置了一个 Detector.Processor.处理器有一个 receiveDetections() 方法,所以我所做的只是调用 barcodeDetector.release() ,而barcodeDetector 是检测条形码的实例.它对我来说很好用,我还测试了扫描并在检测到后启动另一个活动,并且只添加了一个活动,所以它实际上只是检测到一个条形码然后停止.

So, as far as stopping the scanning goes, I got it working by calling .release() on my BarcodeDetector instance. I followed this example and as you can see they set a Detector.Processor<Barcode> for the BarcodeDetector. The processor has a receiveDetections() method, so what I did was just calling barcodeDetector.release() with barcodeDetector being the instance that detected the barcode. It works fine for me, I also tested the scanning and starting another activity after detection, and only one activity is added, so it really just detects one barcode and then stops.

要将内容保存在另一个活动中,您可以使用 Intent 在相同的 receiveDetections() 方法中启动另一个活动,然后使用 putExtra() 方法来获取其他活动所需的数据,尽管我真的不知道你想保存什么,因此 putExtra() 可能对你来说不够.

To save the content in another activity, you can start another activity in the same receiveDetections() method using an Intent, and then use the putExtra() method to get the data you need to the other activity, although I don't really know what you want to save and thus putExtra() might not suffice for you.

关于这个例子,向下滚动到4. 使用相机读取二维码",你会发现我在说什么.

concerning the example scroll down to "4. Reading a QR Code Using the Camera" there you will find what I am talking about.

516