[Android-development] putExtra (QString, QString) doesn't seem to work for me
info at classintouch.de
info at classintouch.de
Tue Aug 3 11:28:29 CEST 2021
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/android-development/attachments/20210803/bfce6f59/attachment.html>
More information about the Android-development
mailing list