question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IntentIntegrator always returns result -1

See original GitHub issue

First of all, I’m far from an Android professional when it comes to programming so I hope this is actually an issue worth reporting, but I felt it being strange that the result code is “error” when it should be “success” for a successful qr-code detection and data read.

This is my findings;

Description of the problem:

Initializing a new IntentIntegrator and then scanning a QR-code always returns -1 (error), even if the data is complete and has been read successfully.

Which library version are you using?

implementation "com.journeyapps:zxing-android-embedded:3.6.0"
implementation "com.google.zxing:core:3.3.3"

Which phone/tablet are you using, and which Android version does it run? Samsung Galaxy S7 (Android 8.0.0), OnePlus 6 (Android 8.1.0)

Does the same happen on other devices or an emulator? I’ve only tested the two devices.

Can you reproduce the issue in the sample project included with the library? If not, can you provide your own sample project or sample code that produces this error?

// Initializer
IntentIntegrator qrScannerIntent = new IntentIntegrator(this);
qrScannerIntent.setBeepEnabled(false);
qrScannerIntent.setPrompt("");
qrScannerIntent.setRequestCode(REQUEST_QRCODE_SCAN); // 55
qrScannerIntent.initiateScan();

// This doesn't work as described by your documentation
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
    if (requestCode == REQUEST_QRCODE_SCAN) {
        // resultCode is always -1, as such intentResult is always null too
        IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    }
}

// Solution is to do this instead;
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
    // QR code scan?
    if (requestCode == REQUEST_QRCODE_SCAN) {
        if (!data.hasExtra(Intents.Scan.RESULT)) {
            return;
        }

        String qrCodeResult = data.getStringExtra(Intents.Scan.RESULT);
        if (qrCodeResult.length() == 0) {
            return;
        }

        // Works!! qrCodeResult contains the data from the QR code, even if resultCode is -1!
    }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rkistnercommented, Sep 7, 2019

If you change the requestCode, you have to use the parseActivityResult(resultCode, data) method (the version without the requestCode parameter).

0reactions
xrpdevscommented, Feb 12, 2021

If you change the requestCode, you have to use the parseActivityResult(resultCode, data) method (the version without the requestCode parameter).

Thanks for this, I wasted hours this evening due to this… Onwards and upwards!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple onActivityResult for 1 Activity using Zxing barcode
The code below is work well but when i use any "scan", the buttons always returns the result to the first textview which...
Read more >
Re: ZXing returning null - Google Groups
Yes, but I am asking where the message is coming from. The request/result code tell you what the state of the result is,...
Read more >
Problem with the onActivityResult | B4X Programming Forum
The reason is probably simple: de intent is returning the result to the ba Activity, not to the ABBarcode activity.
Read more >
IntentIntegrator (ZXing 3.3.2 API)
A utility class which helps ease integration with Barcode Scanner via Intent s. This is a simple way to invoke barcode scanning and...
Read more >
Android QR Code Scanner – Quick Guide - Ronny Yabar
1.- Add ZXing to your project. In particular, we need two Zxing classes, IntentIntegrator and IntentResult. Add them easily to your project.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found