IntentIntegrator always returns result -1
See original GitHub issueFirst 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:
- Created 5 years ago
- Reactions:5
- Comments:8 (1 by maintainers)
Top GitHub Comments
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!