Important: Please read the Qt Code of Conduct -

Problem with intent communication calling Zxing scanner app

  • Hi there,

    I am looking for a working way to setup an Intent-communication on my mobile phone to use the scanning app of the ZXing Team. I really would like to use it from inside my Qt-app.
    Therfore I use the classes QAndroidJniObject and QtAndroid. As reciever I use the class QAndroidActivityResultReceiver.

    As one would expect, the call of the method startActivity brings up the scan-app. But then thing get weiry. The reveiver method recieves a resultCode = 0 without interaction from my side with the scaner-app. I did NOT push the return-button nor scan anything.
    If I call the startActivity twice, the first call returns the resultCode = 0. The second call waits for the scan, closes the scanner app and terminates with resultCode = 0.

    I would expect getting the scanned code. I have googled a lot but I could not come up with a really working solution.

    Any ideas or hints where to look for or what's going wrong?

    class OnActivityResult : public QAndroidActivityResultReceiver
    void handleActivityResult(int requestCode, int resultCode, const QAndroidJniObject & intent)
    qDebug() << "**** " << requestCode << " : " << resultCode;

        if (requestCode == 12345)
            if (resultCode != 0 && intent.isValid())
                QAndroidJniObject result = intent.getObjectField<jstring>("SCAN_RESULT");
                QAndroidJniObject format = intent.getObjectField<jstring>("SCAN_RESULT_FORMAT");
                qDebug() << result.toString() << " : " <&lt; format.toString();


    QAndroidJniObject intent("android/content/Intent");

    if (intent.isValid())
    QAndroidJniObject jPackage;
    QAndroidJniObject jClass;
    QAndroidJniObject jExtra;
    QAndroidJniObject jMode;

    jPackage = QAndroidJniObject::fromString("");
    jClass = QAndroidJniObject::fromString("");
    jExtra = QAndroidJniObject::fromString("SCAN_MODE");
    jMode = QandroidJniObject::fromString(""); // Scann all
    , "(Ljava/lang/String;)Landroid/content/Intent;"
    , jPackage.object&lt;jstring>());
    , "(Ljava/lang/String;)Landroid/content/Intent;"
    , jClass.object<jstring>());
    , "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;"
    , jExtra.object<jstring>()
    , jMode.object<jstring>());
    OnActivityResult* aarr = new OnActivityResult();
    QtAndroid::startActivity(intent, 12345, aarr);
    //QtAndroid::startActivity(intent, 12345, aarr);


  • This post is deleted!

Log in to reply