Search code examples
androidzxingbarcode-scanner

Decoding bitmap using Zxing library in android


I am integrating the zxing library to scan the barcode to my android app. I am doing this local to my application as illustrated in

http://code.google.com/p/zxing/source/browse/trunk/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java

But while running the app, it asks me to install the Barcode scanner app. Is it not possible to achieve this without installing of the app?

I have done a lot of research on how to achieve this, but I could not end up with satisfactory results.

I am trying to do this using this piece of code,

      IntentIntegrator integrator = new IntentIntegrator(TestActivity.this);
      integrator.addExtra("SCAN_WIDTH", 800);
      integrator.addExtra("SCAN_HEIGHT", 200);
      integrator.addExtra("RESULT_DISPLAY_DURATION_MS", 3000L);
      integrator.addExtra("PROMPT_MESSAGE", "Custom prompt to scan a product");
      integrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);

Please help me

Update :

I am using a different technique of zxing to scan now i.e. to capture image with the camera and then decoding it. I am able to capture the image with this code, but after capturing, I am trying to decode the bitmap of captured image using LuminanceSource, RGBLuminanceSource etc classes.

But the resulting binarybitmap,

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

appears to be null.

Can anybody tell me why is this? I have seen many posts saying that is is working for them but it is not working for me.

Can anybody please suggest me something.

Here is the link I referred, I am using the exact code in the accepted answer

Barcode/Qr Code Reader for Android


Solution

  • Finally I have found the answer for this. Using IntentIntegrator will ask you to install the scanner app manually and then will scan barcode using that.

    So, whoever do not want to use neither the app or the intent call can use one more activity provided in the library called CaptureActivity

        Intent intent = new Intent(MyActivity.this, CaptureActivity.class);
        startActivityForResult(intent, 1);
    

    This class is present in android folder of Zxing library which you have downloaded. Importing this android project into your application will integrate the Zxing library. Be careful about package names while importing.

    You can modify CaptureActivity according to your needs

    Note:

    It is very important to add core.jar or else you will be ending up with lot of errors.