I resolved this multiple detection of Barcode
at the same time, exploring the sample code and some logical implementation.
Solution : stop mPreview
and start again after 1 second delay
Create callback listener
public interface BarCodeDetectListener { void onBarCodeDetect(Barcode barcode); }
BarcodeGraphicTracker
When a Barcode
device is detected inside the onNewItem()
callback on Barcodefragment
class BarcodeGraphicTracker extends Tracker<Barcode> { ... ... private BarcodeGraphic mGraphic; private BarCodeDetectListener barCodeDetectListener; ... @Override public void onNewItem(int id, Barcode item) { mGraphic.setId(id); barCodeDetectListener.onBarCodeDetect(item); } }
Barcodefragment
@SuppressLint("NewApi") public class SurveyBarCodeFragment extends Fragment implements BarCodeDetectListener { ... private CameraSourcePreview mPreview; private CameraSource mCameraSource; ... @Override public void onBarCodeDetect(final Barcode barcode) { new Handler().post(new Runnable() { @Override public void run() { mPreview.stop();
source share