41

What do we have out there available to us (if anything) that we can call for QR data discovery and extraction on an image?

While there have been plenty of posts thus far referencing the ZXing library for QRCode scanning, I haven't found that to be a solution that works for me. Several others have been asking for QRCode scanning alternatives and I have not seen useful feedback. I thought I might ask the community once more what the other options might be for a QR code library that does not launch an activity and call outside our own applications. It should scan images from the Camera2 API in a very simplistic manner. It shouldn't be a complicated library. I hadn't seen examples or individuals speaking of it in this manner.

It actually puzzles me as to why there hasn't been native implementations of the QRCode functionality added into perhaps the Camera library or similar place within the Google SDK natively within the operating system.

Calling and requiring another application (or even requesting a download) is not an elegant solution and no users should be succumbed to doing such thing. As developers we should have access to a library capable of extracting a QRCode from an image or frame that we can then remove encoded data from.

Jay Snayder
  • 4,298
  • 4
  • 27
  • 53
  • 2
    You can easily add the zxing library to your application and create a customview to handle the cameraview and then pas that info to the zxing libray without opening any other application. – Aegis Dec 27 '13 at 14:51
  • 2
    FWIW here is my explanation of why it was never built into Android from when I was at Google: http://www.quora.com/QR-Codes/Why-havent-Google-or-Apple-embedded-a-QR-reader-in-their-Camera-apps – Sean Owen Dec 27 '13 at 15:54

6 Answers6

16

While Sean Owen and others that have worked on the original Zxing library had provided an approach to work with the barcode libraries for the past several years, Google has finally put out an official release with Google Play Services for handling qr and barcodes.

The barcode detection library is described here. The inclusion of these libraries will make for a smooth integration. I'll repost with some sample code for achieving these results from a captured image. At the moment, I wanted to update my answer for this official release. If this indeed does provide a nice way to get at this information (without jumping through hoops and complications), then I'll update with the source and check this off as an accepted answer.

The detection library that Google has provided within the past year has been a much easier library to work with. It allows for quick integration with the camera APIs and extracts the information with simplicity. This would be the component that I would suggest going forward with recognition. A quick snippet is demonstrated below for handling a Qr-code. A handful of pseudocode is left in there as well.

public final void analyzeFrameForQrCode(byte[] qrCodePictureF, int imageFormatF, XriteSize previewWindowSizeF)
{
    if(!qrCodeDetectionPossible() || qrCodePictureF == null || mIsAnalyzingQrCodeFrame)
    {
        return;
    }

    ... //Bitmap conversion code

    Frame frame = new Frame.Builder().setBitmap(pictureTaken).build();
    SparseArray<Barcode> barcodes = mBarcodeDetector.detect(frame);
    if(barcodes != null && barcodes.size() != 0)
    {
        Barcode qrCode = barcodes.valueAt(0);//barcodes.get(Barcode.QR_CODE);
        if(qrCode != null)
        {
             if(extractInformationFromQrCode(qrCode.rawValue)) {
                    mIsRequestingBarcodeDetection = false;
                    vibrateForQrCodeDiscovery();
                    ((Activity)mContext).runOnUiThread(new Runnable() {
                        @Override
                        public void run()
                        {
                            hideBarcodeDetection(true);
                        }
                    });
                }
            }
        }

     ... //Cleanup and code beyond Qr related material

   } 
}

There are of course other calls available that can be taken advantage of. But there are really only a couple lines in there. The service for analyzing the frames with the library are not there by default on devices however. So, you should check whether or not the library is available (such as when internet is not available) before calculating as well. This is a slight nuisance of it. I had assumed it would be available as updates for devices going forward as part of the support library or Google Services going out to all devices. But it needs the communication first with an external service to use these library calls. Once it does this one time then that device is good from that moment on.

In my small example, I pop a toast up after a check and then back out of the activity and let the user check their connection. This can be done with a small amount of sample code as well.

if(!mBarcodeDetector.isOperational())
{
    updateUserInstructions("The barcode library cannot be downloaded");
    return false;
}

Edit (Update):

A considerable amount of time has passed since working with the latest Google Play Services Vision libraries available for barcode detection. While the limitation for needing to download the library over the wifi is indeed a limitation, it is a one time process. And lets be honest...

...our devices will have a connection. The library itself is downloaded in the background so you don't even notice it happening unless there is trouble downloading it and then you would have to report an appropriate corrective measure such as enabling a connection to the internet for it.

One additional tidbit is that it is a little tricky sometimes with how you integrate the library into your application. Using it as a library project worked on some devices and then failed on others. Adding the jar to the build path worked across a broader number of devices (it could be all, but it solved a problem). So as such, I would do it using the secondary method when including it in your projects for now.

Jay Snayder
  • 4,298
  • 4
  • 27
  • 53
  • 5
    `But it needs the communication first with an external service to use these library calls` So it's very bad – fralbo May 30 '16 at 12:40
  • @2ndGAB Ideally, the library would not need this. I agree that this could have been done without. Perhaps in the future they will just fit this into their support library so that we can package it and not rely on the external component. This library is much cleaner than the Zxing library and works smoothly when integrated. – Jay Snayder Jun 02 '16 at 13:16
  • 1
    In fact I just found the Zxing implementation I expected [here](https://github.com/dm77/barcodescanner). Perfect! – fralbo Jun 03 '16 at 13:00
9

Android QRCode Scanner Library

This may help you, this library doesn't require any download or use of any external application. We can directly integrate this into your app and use it for scanning a QR code.

https://github.com/dm77/barcodescanner

This wiki will help you to integrate with your app,

https://github.com/dm77/barcodescanner/blob/master/README.md

VivekTamilarasan
  • 379
  • 3
  • 10
6

You can also check MobileVisionBarcodeScanner (note I'm the author of this package). It is powered by Google's mobile vision API. Also see the overview here .

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Belvi Nosakhare
  • 3,107
  • 5
  • 32
  • 65
5

I used this library in my app. It also works with xing but you don't need any third party applications. Additional it's really easy to use.

https://github.com/journeyapps/zxing-android-embedded

Maybe you searched something like this.

Daniel S.
  • 77
  • 2
  • 9
4

You've already found the library you're looking for, I think. See the core/ module:

https://github.com/zxing/zxing/tree/master/core

You're just looking at the Intent-based integration, but, in fact the core scanning is its own stand-alone library that you can embed into your own app.

I think Intent-based integration is best in most cases, simply because it is so simple, and, most people don't have the time to reimplement their own scanning UI and such on top of the core. Most devices have Barcode Scanner installed already, so it doesn't usually need a download.

Still, take your pick. That's why there are at least two ways to use it.

Pang
  • 9,564
  • 146
  • 81
  • 122
Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • 2
    After spending some time analyzing and playing around with it, I was able to get some results finicking with the QRCodeReader class and passing in a Bitmap of my own, but I had to do manual conversions with other classes such as BinaryBitmap and Binarizer classes. It doesn't seem like that much of a library than an assortment of classes. – Jay Snayder Dec 27 '13 at 17:29
  • I would expect to see some sort of class that returns with the Result info from a QRCodeReader with even Bitmap as an option for a parameter to pass in during construction of the Reader. Perhaps a QRResult field return with info in it. Not what I was expecting so far, but I did get a successful read with the library, so it has worked for me so far. – Jay Snayder Dec 27 '13 at 17:30
  • Not sure what you're referring to, but, here's an example of the whole process in Android: https://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/DecodeHandler.java#77 and in JavaSE: https://code.google.com/p/zxing/source/browse/trunk/javase/src/main/java/com/google/zxing/client/j2se/DecodeWorker.java#144 The core is a few lines of code, from platform-specific rep to `BinaryBitmap` to library call. Second comment seems to want: https://code.google.com/p/zxing/source/browse/trunk/core/src/main/java/com/google/zxing/qrcode/QRCodeReader.java#63 – Sean Owen Dec 27 '13 at 17:36
  • Better find another alternative. It doesn't work so good. – Boris Karloff Oct 19 '18 at 18:23
-6

Rather than QRCODE ZXing library integration You are able to open camera and scan QRCode from anywhere: The code i found below will may be helps to you for scanning QRCode :

try {
                Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes
                startActivityForResult(intent, 0);
            } catch (Exception e) {    
                Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
                Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
                startActivity(marketIntent);
            }

Please remember that You must have a barcode scanner application by "Zxing" in Mobile Phone else it will firstly redirect to Google play store link for download it.