Teo
Teo

Reputation: 3213

How decode QR code image from preview android?

I initialized the camera and I start it into preview mode. For the preview I take the source code from http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html

Now I want decode the QR code with zxing library from the preview, but I haven't any idea as to do.. Can you hlep me?

Upvotes: 0

Views: 832

Answers (1)

Skies
Skies

Reputation: 415

if you want decode QR code with zwing, you need to use this 2 classes :

IntentIntegrator.java
IntentResult.java

Call the Intent like this in your Activity:

IntentIntegrator intentScan = new IntentIntegrator(this);
Collection<String> desiredBarcodeFormat = Collections.unmodifiableCollection(Arrays.asList("QR_CODE"));
intentScan.initiateScan();

You receive the result in your Activity with this method :

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case IntentIntegrator.REQUEST_CODE:
        if (resultCode == RESULT_OK) {
            IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
            if (scanResult != null)
               String out = scanResult.getContents();
        }
    }
}

Link to documentation :

http://code.google.com/p/zxing/wiki/ScanningViaIntent

Link to classes :

http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/

Upvotes: 1

Related Questions