How to decode QR code

2019-01-22 09:49发布

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.

5条回答
甜甜的少女心
2楼-- · 2019-01-22 10:18

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

查看更多
Summer. ? 凉城
3楼-- · 2019-01-22 10:18
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();
        }
    }
查看更多
Root(大扎)
4楼-- · 2019-01-22 10:21

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

查看更多
Explosion°爆炸
5楼-- · 2019-01-22 10:21

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

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

查看更多
劫难
6楼-- · 2019-01-22 10:36

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.

查看更多
登录 后发表回答