1

I am implementing Qr code scanner to camera application similar to ios11. I am scanning the Qr code when focus ring appears in the camera app.

/**
     * Show AF target in center of preview.
     */
    private void startPassiveFocus() {
        // TODO: make mFocusController final and remove null check.
        if (mFocusController == null) {
            return;
        }

        // TODO: Some passive focus scans may trigger on a location
        // instead of the center of the screen.
        mFocusController.showPassiveFocusAtCenter();

        if(decodeFrameTask != null){
            if(decodeFrameTask.getStatus() == AsyncTask.Status.RUNNING){
                // QR scan currently in progress
                stopQRCodeReader();
            }
        } else {
            startQrCodeReader();
        }
    }

I am calling asynchronously to decode the zxing Reader

  public DecodeFrameTask(CaptureModule view, AppController apController, CameraActivity mActivity) {
        mCaptureModule = new WeakReference<>(view);
        appController = apController;
        runAsync = 0;
        activity = mActivity;
    }

    protected Result doInBackground(byte[]... params) {
        final CaptureModule view = mCaptureModule.get();
   final PlanarYUVLuminanceSource source =
                    view.mCameraManager.buildLuminanceSource(activity.getScreenPreviewByteData(),  appController.getCameraAppUI().getSurfaceWidth(),
                            appController.getCameraAppUI().getSurfaceHeight());

            final HybridBinarizer hybBin = new HybridBinarizer(source);
            final BinaryBitmap bitmap = new BinaryBitmap(hybBin);

          try {
                return view.mQRCodeReader.decode(bitmap);
            } catch (ChecksumException e) {
                Log.d(TAG, "ChecksumException", e);
            } catch (NotFoundException e) {
                Log.d(TAG, "No QR Code found");
            } catch (FormatException e) {
                Log.d(TAG, "FormatException", e);
            } finally {
                view.mQRCodeReader.reset();
            }
        }
        return null;
    }



protected void onPostExecute(Result result) {
            super.onPostExecute(result);

            runAsync = 1;
            if(result != null){
                Log.d(TAG, "QR Text ----->", result.getText());
            }else if(result == null){
                Log.d(TAG, "Errorreading QRcode ");
            }
}
public void startQrCodeReader() {
    mQRCodeReader = new QRCodeReader();
    if(mAppController != null) {
        decodeFrameTask = new DecodeFrameTask(this, mAppController, mActivity);
        decodeFrameTask.execute();
    }

}



public void stopQRCodeReader() {
        if (decodeFrameTask != null) {
            decodeFrameTask.cancel(true);
            decodeFrameTask = null;
        }
    }

I am getting result as null.Please let me know where I am going wrong using zxing library to camera application

winchester100
  • 147
  • 3
  • 13
  • Possible duplicate of [Using ZXing to create an android barcode scanning app](https://stackoverflow.com/questions/2050263/using-zxing-to-create-an-android-barcode-scanning-app) – Aniruddha K.M Oct 09 '17 at 09:25
  • @war_Hero: please read my question.I am working on system camera app not stand alone application – winchester100 Oct 09 '17 at 09:32
  • @war_Hero: This is the link for camera app https://android.googlesource.com/platform/packages/apps/Camera2/ – winchester100 Oct 09 '17 at 09:40
  • This is [link](https://github.com/dm77/barcodescanner) of a well working demo – ADM Oct 09 '17 at 10:06
  • @ADM: I used the same link to integrate into my app.But unfortunately i am getting result as null when i scan in camera app – winchester100 Oct 09 '17 at 10:40
  • Well i previously used the same lib and ZXingScannerView in my activity . Its working fine – ADM Oct 09 '17 at 11:51
  • @ADM :did u implement that in system app camera2 api? – winchester100 Oct 09 '17 at 11:57
  • In my case there will be no scannerView. I need to focus directly using focus ring view when you open your camera similar to IOS11 – winchester100 Oct 09 '17 at 12:04
  • @ADM :can you please help me out – winchester100 Oct 10 '17 at 11:31
  • Well I haven't done scanning like that particular scenario. But Zxing provide a method where you can pass a bitmap object to it and it will return you the QR code . Try [this](https://stackoverflow.com/a/14178993/4168607). – ADM Oct 10 '17 at 12:07
  • @ADM thanks for link, let me check how it will be helpful for my scenario – winchester100 Oct 10 '17 at 12:22
  • Check this so thread too [link](https://stackoverflow.com/questions/14861553/zxing-convert-bitmap-to-binarybitmap) . i thing its what you need.Good luck – ADM Oct 10 '17 at 12:27

0 Answers0