8

I like decode QR Code directly in my application, I don't wont to redirect my application to other intent. I try very hard to find any API or Library, from which I can decode QR code, but I am not succeed in it.

Anybody have any idea how can I decode QR code in my application or Library file from which I can decode QR code.

Mohit Kanada
  • 15,274
  • 8
  • 31
  • 41
  • 2
    Here is a similar question with an accepted answer: http://stackoverflow.com/questions/5171294/decoding-a-qr-code-in-an-android-application – Mudassir Jun 29 '11 at 10:05

5 Answers5

13

Zxing is an excellent library for QR-codes. You will find what you need there, including an android sample project.

Mohammad Arman
  • 7,020
  • 2
  • 36
  • 50
uvesten
  • 3,365
  • 2
  • 27
  • 40
6

Here is an example how I manage to decode 1D Barcode and 2d QR Codes using Zxing libraryin Android.

QR DECODE

     Intent intent = new Intent("com.google.zxing.client.android.SCAN");
     intent.putExtra("SCAN_MODE", "QR_CODE_MODE");  
     startActivityForResult(intent, REQUEST_BARCODE);

     Toast toast = Toast.makeText(this, "Start scanning QR code", Toast.LENGTH_SHORT);
     toast.show();

BARCODE DECODE

     Intent intent = new Intent("com.google.zxing.client.android.SCAN");
     intent.putExtra("SCAN_MODE", "PRODUCT_MODE");  
     startActivityForResult(intent, REQUEST_BARCODE);

     Toast toast = Toast.makeText(this, "Start scanning Barcode", Toast.LENGTH_SHORT);
     toast.show();

This code is Working on Android Samsung Galaxy S (Version 2.2). If you want to check different Scan modes check this link: Zxing Intents.java

Best Regards

Iker
  • 2,018
  • 2
  • 29
  • 52
  • What is the value of REQUEST_BARCODE variable? Only this 3 lines are able to scan barcode or any extra class require? In my code I get a No Activity found exception? – Mohit Kanada Jul 19 '11 at 06:36
  • private static final int REQUEST_BARCODE = 0; Did you included the activity in the AndroidManifest.xml ? – Iker Jul 19 '11 at 12:23
4

You can also Use ZBar bar code reader here http://sourceforge.net/projects/zbar/?source=dlp

it's much faster than zxing and much easier to implement.

4

You can now use the BarcodeDetector inside the new Android Mobile Vision API

Here is an example https://github.com/Gnzlt/AndroidVisionQRReader

Gnzlt
  • 4,383
  • 2
  • 22
  • 24
  • 1
    Thank you! So many answers about using third party libraries. It was surprisingly hard to find a native way to do this. Could you please tell me from which API level is this supported? My app is using API 17: Android 4.2 (Jelly Bean). Can I still use the vision API? – Isuru Oct 28 '15 at 16:12
  • Of course you can! Luckily it is based on Google Play Services so you can use it even with API 9 (Gingerbread) – Gnzlt Oct 28 '15 at 17:39
  • That's awesome. Thank you! – Isuru Oct 29 '15 at 07:43
  • Hi again, can you please take a look at this [question](http://stackoverflow.com/q/33421415/1077789)? I was trying to get the Mobile Vision API working but I'm stuck here. I'd really appreciate it. – Isuru Nov 01 '15 at 15:19
  • Sorry for the inconvenience, I've just answered you ;) – Gnzlt Nov 02 '15 at 16:37
0
static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";


// Bar Code

public void scanBarCode(View v) {

        try {
            //start the scanning activity from the com.google.zxing.client.android.SCAN intent

            Intent intent = new Intent(ACTION_SCAN);

            intent.putExtra("SCAN_MODE", "PRODUCT_MODE");

            startActivityForResult(intent, 0);

        } catch (ActivityNotFoundException anfe) {

            //on catch, show the download dialog

            showDialog(AndroidBarcodeQrExample.this, "No Scanner Found", "Download a scanner code activity?", "Yes", "No").show();
        }
    }


// QR Code

    public void scanQR(View v) {

        try {

            //start the scanning activity from the com.google.zxing.client.android.SCAN intent

            Intent intent = new Intent(ACTION_SCAN);

            intent.putExtra("SCAN_MODE", "QR_CODE_MODE");

            startActivityForResult(intent, 0);

        } catch (ActivityNotFoundException anfe) {

            //on catch, show the download dialog

            showDialog(AndroidBarcodeQrExample.this, "No Scanner Found", "Download a scanner code activity?", "Yes", "No").show();
        }
    }
Lawrence Benson
  • 1,398
  • 1
  • 16
  • 33