putExtra() to a PendingIntent
-
I am trying to use putExtra() on a PendingIntent. Far goal is to restart the app (that part works, thanks to this solution by BogDan Vatra) and hand over information to the new instance, which I want to achieve by putting an extra to the intent. I am not sure, if the basic idea of this approach to an "after-life communicating" is actually feasible, but I give my best to find out.
Any hint about what I am doing wrong would be highly appreciated. It's probably something very stupid/basic, because I am still a noob in Java/Android.
Qt5.15 on Win64, Targeting API 30, device: Galaxy Tab S4 with Android10.Here is what I've tried , the debug result is shown below:
// create the pendingIntent 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")); qDebug()<<"pendingIntent.toString(): "<<pendingIntent.toString(); // to test out more possibilities, I also wrap it into a "real" intent: QAndroidIntent intent(pendingIntent); qDebug()<<"intent.handle().toString(): "<<intent.handle().toString(); // create objects to store as extras QAndroidJniObject subject = QAndroidJniObject::fromString("url"); qDebug()<<"subject.toString(): "<<subject.toString(); QAndroidJniObject text = QAndroidJniObject::fromString("http://www.google.com"); qDebug()<<"text.toString(): "<<text.toString(); // straightforward qDebug()<<"putting EXTRA in, 1st try:"; intent.putExtra(subject.toString(), text.toString()); // other desperate attempts qDebug()<<"putting EXTRA in, 2nd try:"; intent.handle().callObjectMethod("putExtra", "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;", subject.object(), text.object()); qDebug()<<"putting EXTRA in, 3nd try:"; intent.handle().callObjectMethod("putExtra", "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;", subject.object(), jstring("http://www.google.com")); qDebug()<<"putting EXTRA in, 4th try:"; pendingIntent.callObjectMethod("putExtra", "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;", subject.object(), text.object()); qDebug()<<"putting EXTRA in, 5th try:"; pendingIntent.callObjectMethod("putExtra", "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;", subject.object(), jstring("http://www.google.com")); qDebug()<<"putting EXTRA in, 6th try:"; pendingIntent.callObjectMethod("putExtra", "(Ljava/lang/String;Landroid/os/Parcelable;)Landroid/content/Intent;", subject.object(), jstring("http://www.google.com")); qDebug()<<"putting EXTRA in, 7th try:"; pendingIntent.callObjectMethod("putExtra", "(Ljava/lang/String;Landroid/os/Parcelable;)Landroid/content/Intent;", subject.object(), text.object());
The result output seems hopeless:
D libRestart_armeabi-v7a.so: pendingIntent.toString(): "PendingIntent{12b7761: android.os.BinderProxy@3e79286}" D libRestart_armeabi-v7a.so: intent.handle().toString(): "PendingIntent{12b7761: android.os.BinderProxy@3e79286}" D libRestart_armeabi-v7a.so: subject.toString(): "url" D libRestart_armeabi-v7a.so: text.toString(): "http://www.google.com" D libRestart_armeabi-v7a.so: putting EXTRA in, 1st try: 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:919) D libRestart_armeabi-v7a.so: putting EXTRA in, 2nd try: W System.err: java.lang.NoSuchMethodError: no non-static method "Landroid/app/PendingIntent;.putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;" [...] //(output shortened, always the same lines as above) D libRestart_armeabi-v7a.so: putting EXTRA in, 3nd try: W System.err: java.lang.NoSuchMethodError: no non-static method "Landroid/app/PendingIntent;.putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;" [...] D libRestart_armeabi-v7a.so: putting EXTRA in, 4th try: W System.err: java.lang.NoSuchMethodError: no non-static method "Landroid/app/PendingIntent;.putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;" [...] D libRestart_armeabi-v7a.so: putting EXTRA in, 5th try: W System.err: java.lang.NoSuchMethodError: no non-static method "Landroid/app/PendingIntent;.putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;" [...] D libRestart_armeabi-v7a.so: putting EXTRA in, 6th try: W System.err: java.lang.NoSuchMethodError: no non-static method "Landroid/app/PendingIntent;.putExtra(Ljava/lang/String;Landroid/os/Parcelable;)Landroid/content/Intent;" [...] D libRestart_armeabi-v7a.so: putting EXTRA in, 7th try: W System.err: java.lang.NoSuchMethodError: no non-static method "Landroid/app/PendingIntent;.putExtra(Ljava/lang/String;Landroid/os/Parcelable;)Landroid/content/Intent;" [...]
Same happens on arm64-v8a build, btw.
-
For this specific issue I have solved the problem by just writing a file with the needed info as "messenger" and checking for its existence on startup. Seems hacky to me, but does the job. I'd still love to understand more about the way described above, especially when I want to send messenges cross-app.
So if anyone could enlighten me about where my mistake - or probably my conceptual misunderstanding lies, that'd still be awesome.