Search code examples
androidandroid-camerazxingbarcode-scannerautofocus

zxing barcode scanner autofocus not working


I'm able to successfully integrate barcode scanner using zxing library to make a standalone scanner. The problem that is coming in my application is the autofocus. Camera in my app is taking the initial focus and is not resetting. for eg. if initially I point my camera to dark surface and then I focus it to the page having the barcode, the text on the page is not even visible. the contrast is too high. and this contrast is not resetting like in barcode scanner app by zxing.

I have seen other apps like pvr cinemas which are using zxing library and on my device they are working fine in regards to this issue. Their focus is getting reset.

I have followed this tutorial


Solution

  • I had commented out the part

    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args);
    

    Thanks for pointing out AutofocusManager I added

    if (Build.VERSION.SDK_INT >= 11 ) {
                             // changed to 11 as Build.VERSION_CODES.HONEYCOMB is not
                             // accessible on android platform prior to 3.0
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args);
    } else {
        task.execute(args);
    }
    

    in HoneycombAsyncTaskExecInterface

    Now its working fine. Thanks @Sean Owen