How to stop scanning and store data from Google's Vision API?

末鹿安然 提交于 2019-12-07 15:17:08

问题


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

Thanks !


回答1:


If you are using CameraSourcePreview as in the sample code, you can call its "release()" method to shut down the camera and the associated barcode detector. If you are using the CameraSource directly without the preview, then you can call "release()" directly on that instance.

See this other question which discusses passing the result back:

How to capture barcode values using the new Barcode API in Google Play Services?




回答2:


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.

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.

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



来源:https://stackoverflow.com/questions/32558923/how-to-stop-scanning-and-store-data-from-googles-vision-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!