Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved AndroidIntent and QAndroidJniObject

    Mobile and Embedded
    2
    4
    202
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • SeDi
      SeDi last edited by SeDi

      Hi,
      still trying to solve this Android problem, I am trying to add an "extra" to an Intent that is going to be raised via the ALARM_SERVICE.

      The problem is: to call the putExtra(...) method, I need a QAndroidIntent. The pendingIntent I have, is but a QAndroidJniObject.

      Following the docs,

      QAndroidIntent realIntent(pendingIntent);
      

      wraps(!) my pendingIntent, so I try to add the "extra" that way:

      realIntent.putExtra(QString("SCREEN"),QString("Camera"));
      

      Then I set the AlarmManager with pendingIntent:

      alarmManager.callMethod<void>("set",
                                                "(IJLandroid/app/PendingIntent;)V",
                                                QAndroidJniObject::getStaticField<jint>("android/app/AlarmManager", "RTC"),
                                                jlong(QDateTime::currentMSecsSinceEpoch() + 500), pendingIntent.object());
      

      But, apparently, the "extra" is NOT being set in the original pendingIntent (so it is obviously a different object), as this Q_ASSERT fails:

                  QAndroidIntent realIntent(pendingIntent);
                  realIntent.putExtra(QString("SCREEN"),QString("Camera"));
      
                  QAndroidIntent realIntent2(pendingIntent);
                  Q_ASSERT(realIntent2.extraVariant("SCREEN").toString()=="Camera");
      

      I've tried to call the method via ->callOptionMethod() and ->callStaticOptionMethod(), but I have trouble, probably my type specificatios are wrong. Trying out many combinations yielded the following error messages...

      
      W System.err: java.lang.ClassNotFoundException: Didn't find class "Intent" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /system/vendor/lib]]
      W System.err: java.lang.ClassNotFoundException: Didn't find class "Landroid.app.PendingIntent" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /system/vendor/lib]]
      W System.err: java.lang.ClassNotFoundException: Didn't find class "QAndroidIntent" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /system/vendor/lib]]
      W System.err: java.lang.NoSuchMethodError: no non-static method "Landroid/app/PendingIntent;.putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/app/PendingIntent;"
      W System.err: java.lang.NoSuchMethodError: no non-static method "Landroid/app/PendingIntent;.putExtra(Ljava/lang/String;Ljava/lang/String;)ILandroid/content/Intent;"
      W System.err: java.lang.NoSuchMethodError: no static method "Landroid/app/PendingIntent;.putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/app/PendingIntent;"
      W System.err: java.lang.NoSuchMethodError: no static method "Landroid/app/PendingIntent;.putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;"
      W System.err: java.lang.NoSuchMethodError: no static method "Landroid/content/Intent;.putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;"
      
      

      How can I "cast back" the proper AndroidIntent, equipped with an "extra", back to a QAndroidJniObject, suitable for the set(...) method?
      Alternatively: how can I add the "extra" to a QAndroidJniObject intent?

      Any help welcome.

      1 Reply Last reply Reply Quote 0
      • IntruderExcluder
        IntruderExcluder last edited by

        Maybe instead of passing pendingIntent to "set" method try to pass realIntent.handle().object()?

        1 Reply Last reply Reply Quote 1
        • SeDi
          SeDi last edited by SeDi

          Thank you, @IntruderExcluder!
          I can do that (and it gave me more insight!), but it doesn't solve the problem, I'm afraid.

          Interestingly,

          QAndroidIntent realIntent(pendingIntent);
          realIntent.putExtra(QString("SCREEN"), QString("Camera"));
          debugLog.write(QString("realIntent: "+realIntent.extraVariant("SCREEN").toString()+"\n").toLocal8Bit());
          

          results in

          realIntent: 
          

          It apparently didn't work to put the extra into the Intent in the first place - so my problem might be even more basic.

          Furthermore, this code on starting the app

          QAndroidJniObject intent = activity.callObjectMethod("getIntent", "()Landroid/content/Intent;");
          if (intent.isValid()) {
              debugLog.write("intent: " + intent.toString().toLocal8Bit()+"\n");
          }
          

          shows extras (in its string description) only when it's not a restart. The output for normal starts:

          intent: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=de.herrdiel.punktlandung/org.qtproject.qt5.android.bindings.QtActivity bnds=[859,1339][1137,1748] (has extras) }
          

          The output for restarts:

          intent: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=de.herrdiel.punktlandung cmp=de.herrdiel.punktlandung/org.qtproject.qt5.android.bindings.QtActivity }
          

          So, at least, I can detect, if it is a restart or not (different Strings), but I still can't submit more specific information - and I am not sure if all Android versions implement these Strings identically.

          The problem seems to be, how to properly put the Extra into the intent.

          1 Reply Last reply Reply Quote 0
          • SeDi
            SeDi last edited by

            @SeDi said in AndroidIntent and QAndroidJniObject:

            realIntent.putExtra(QString("SCREEN"), QString("Camera"));
            debugLog.write(QString("realIntent: "+realIntent.extraVariant("SCREEN").toString()+"\n").toLocal8Bit());
            ~
            results in
            realIntent:

            It should be "realIntent: Camera", shouldn't it?

            Can that possibly be a bug in Qt?
            Or is it just me misunderstanding a concept?

            1 Reply Last reply Reply Quote 0
            • First post
              Last post