Question

I'm developing an Android application using Zxing library to read QR codes. Now I'm almost done and only one question is left.

I need app to stop scanning for 10 seconds after certain event. I have put the thread to sleep 10 seconds and it's not the way I wanted. I want to app to act as everything is normal. But it shouldn't let users know that it's not scanning anything.

Can you explain how to do that. I can use timer method. But which method in Zxing should I stop for 10 seconds?

Was it helpful?

Solution 2

I made it working as I expected. All the decoding things are done by handleDecode method in Capture activity class. So I initialized a boolean variable inside onCreate,

boolean isTensecondsFinished = ture;

Then I check the isTensecondsFinished variable for decode QR code. Just like this,

public void handleDecode(Result rawResult, Bitmap barcode) {
    inactivityTimer.onActivity();
    lastResult = rawResult;
    ResultHandler resultHandler = ResultHandlerFactory.makeResultHandler(
            this, rawResult);

    boolean fromLiveScan = barcode != null;
    if (fromLiveScan) {
        // historyManager.addHistoryItem(rawResult, resultHandler);
        // Then not from history, so beep/vibrate and we have an image to
        // draw on
        if (isTenSecondsFinished) {
            isTenSecondsFinished = false;
            Timer tenSecondsTimer = new Timer();
            tenSecondsTimer.schedule(new TimerTask() {

                @Override
                public void run() {
                    isTenSecondsFinished = true;

                }
            }, 10 * 1000);
                            //Do the decoding stuff here then.
                    }
            }
}

I think this is the simplest solution.

OTHER TIPS

Check the file InactivityTimer.java, there is this line:

private static final int INACTIVITY_DELAY_SECONDS = 5 * 60;

There you can see the timeout is set to 5 minutes. Just mofify this value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top