[Android-development] putExtra (QString, QString) doesn't seem to work for me

Assam Boudjelthia assam.boudjelthia at qt.io
Mon Aug 16 13:08:45 CEST 2021


Hi Sebastian,

As the exception message state, PendingIntent doesn’t have putExtra/GetByteArray methods. You need to add this data into the Intent and not the PendingIntent. If you’re using the code from https://www.kdab.com/qt-on-android-how-to-restart-your-application/, I think you need to use putExtra with activityIntent before you create the PendingIntent that’s passed to the AlarmManager object. Then, once your app is restart, you can use getIntent() on your activity and retrieve the data set was set in the previous run.

Best regards,
Assam

> On Aug 3, 2021, at 12:28 PM, info at classintouch.de wrote:
> 
> Hi,
> 
> I've got a problem with putting an extra into a pending intent. My goal is to have a program restart with parameters/arguments.
> 
> @
> 
> auto pendingIntent = 
> 
>          QAndroidJniObject::callStaticObjectMethod("android/app/PendingIntent", "getActivity",
>             "(Landroid/content/Context;ILandroid/content/Intent;I)Landroid/app/PendingIntent;",
>             activity.object(), jint(0), activityIntent.object(),
>             QAndroidJniObject::getStaticField<jint>("android/content/Intent",
>             "FLAG_ACTIVITY_CLEAR_TOP"));
> 
> // according to the docs, the following constructor just wraps the original intent:
> 
> QAndroidIntent realIntent(pendingIntent);
> 
> // put extra in:realIntent.putExtra(QString("SCREEN"), QString("Camera"));
> 
> // read extra out:
> qDebug() << "realIntent: "<<realIntent.extraVariant("SCREEN").toString();@
> 
> ...results in just @realIntent: "" @,
> 
> whereas it should be @realIntent: "Camera"@
> 
> Instead, my output contains error messages that let me assume, that there might be an implementation bug in Qt:
> 
> @
> 
> W System.err: java.lang.NoSuchMethodError: no non-static method "Landroid/app/PendingIntent;.putExtra(Ljava/lang/String;[B)Landroid/content/Intent;"
> W System.err:     at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method)
> W System.err:     at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:620)
> W System.err:     at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
> W System.err:     at java.lang.Thread.run(Thread.java:764)
> W System.err: java.lang.NoSuchMethodError: no non-static method "Landroid/app/PendingIntent;.getByteArrayExtra(Ljava/lang/String;)[B"
> W System.err:     at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method)
> W System.err:     at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:620)
> W System.err:     at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
> W System.err:     at java.lang.Thread.run(Thread.java:764)
> 
> @
> 
> When I change the Intent's constructor to just 
> 
> @ QAndroidIntent realIntent;
> 
> @
> 
> The output is as expected now, but of course the restart doesn't work. 
> 
> 
> 
> I am on Qt 5.15.2, using clang on a Win10 machine. It doesn't seem to matter, which sdk levels are targeted for or minimum.
> 
> For context: (apart from this: successfully) I use this approach (by Bogdan) for restart: https://www.kdab.com/qt-on-android-how-to-restart-your-application/
> 
> I need the extra (or any other way) to pass some information over to the restarted app.
> 
> 
> 
> Shall I file this as a bug? Or do i misunderstand a concept? Is a "Pending Intent" different to an "Intent"? 
> 
> What else can I do? Any pointers, any workarounds are gratefully appreciated!
> 
> Best regards 
> 
> Sebastian
> 
> 
> 
> P.S.: I have tried to get help on this before, but on forum.qt.io nobody could help me solve this and from android-qt at googlegroups.com I didn't get a response at all. Sorry, if I violate any crossposting rules.
> 
> -- 
> 
> http://www.classintouch.de - Tablet-Software für Lehrer
> _______________________________________________
> Android-development mailing list
> Android-development at qt-project.org
> https://lists.qt-project.org/listinfo/android-development



More information about the Android-development mailing list