1

I want to implement QR Code Reader for android. I used This Solution but it only opens camera, captures image but do nothing. I would like to know the best to do it (DISREGARDING intent integrator from zxing)

Community
  • 1
  • 1
user3917800
  • 127
  • 3
  • 10

4 Answers4

5

Since the questioner states that he/she wants to do it without ZXing I'll throw in my favorite option: use Google's own version available through Google Play services in the namespace com.google.android.gms.vision.barcode. This solution is fast robust and accurate and it supports all standard formats.

To get up and running in no time give Android QR Code Reader Made Simple a chance! This will give you full control of the source code and you can easily continue to build further on the code provided or equally easily implement it in you existing project.

Give it a try!

Algar
  • 5,734
  • 3
  • 34
  • 51
4

Download zxing in your mobile. And use the following..

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

Override the following function

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1)
            if (resultCode == Activity.RESULT_OK) {
                String contents = data.getStringExtra("SCAN_RESULT");
                String format = data.getStringExtra("SCAN_RESULT_FORMAT");
                Toast.makeText(getApplicationContext(), contents, Toast.LENGTH_SHORT).show();
                // TODO: Do something here with it
            }// if result_ok
    }// onactivityresult

It's 100% working..

Answer might be outdated.

Nabin
  • 11,216
  • 8
  • 63
  • 98
0

I had the same issue in the past, and the solution was to download the source code of Zxing (https://github.com/zxing/zxing) and integrate it inside my application, like this you don't have to use intent. Believe me, it's not much difficult;)

axl coder
  • 739
  • 3
  • 19
-1

Edit build.gradle (App) file & add below dependencies:

compile 'com.journeyapps:zxing-android-embedded:3.4.0'

Declare below variable in Activity class:

IntentIntegrator qrScan;

In OnCreate method write below code:

        qrScan = new IntentIntegrator(this);
    qrScan.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);

your button function like below:

    public void startScan(View view) {
    qrScan.initiateScan();
}

Now it will start Scanning but it requires below method to read result: So ovveride the OnActivityResult method like below of the same Activity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (result != null) {
        if (result.getContents() == null) {
            Toast.makeText(this, "Result Not Found", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, result.getContents() ,Toast.LENGTH_LONG).show();
            txt.setText(result.getContents());
            qrScan.initiateScan();
        }
    }
}

Please refer below link it will give you more idea in Simple form. https://www.simplifiedcoding.net/android-qr-code-scanner-tutorial/

Mahadev Mane
  • 810
  • 8
  • 11