Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Submit argument(s) to a program restart on Android
Forum Updated to NodeBB v4.3 + New Features

Submit argument(s) to a program restart on Android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 207 Views
  • 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.
  • SeDiS Offline
    SeDiS Offline
    SeDi
    wrote on last edited by SeDi
    #1

    Hi,
    I need to be able to restart my App. On the Android platform I do this as proposed here by Bogdan. It works flawlessly.

    Unfortunately I don't have the slightest idea, how (or even if) I can provide arguments to my pendingIntent. I have (naively) tried:

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

    But it didn't show up as an argument in my app. On Windows,

    QProcess::startDetached(programName, arguments);
    

    does that trick, but I don't know how to provide the information here.

    Any idea - including a tipp on where to read about this stuff - is highly appreciated.
    I have tried to understand the man pages of PendingIntent and AlarmManager, but I don't see what I am looking for.

    Here's what I do so far:

    int main(int argc, char *argv[])
    {
         ///... (shortened)
        QStringList arguments;
        if (currentExitCode == Controller::EXIT_CODE_REBOOT_TO_CAMERA) {
             arguments<<"Camera";
        }
        if (currentExitCode == Controller::EXIT_CODE_REBOOT || currentExitCode == Controller::EXIT_CODE_REBOOT_TO_CAMERA) {
            ///... (shortened)
            #ifdef Q_OS_ANDROID
                auto activity = QtAndroid::androidActivity();
                auto packageManager = activity.callObjectMethod("getPackageManager",
                                                                "()Landroid/content/pm/PackageManager;");
    
                auto activityIntent = packageManager.callObjectMethod("getLaunchIntentForPackage",
                                                                      "(Ljava/lang/String;)Landroid/content/Intent;",
                                                                      activity.callObjectMethod("getPackageName",
                                                                      "()Ljava/lang/String;").object());
    
                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"));
                auto alarmManager = activity.callObjectMethod("getSystemService",
                                                              "(Ljava/lang/String;)Ljava/lang/Object;",
                                                              QAndroidJniObject::getStaticObjectField("android/content/Context",
                                                                                                      "ALARM_SERVICE",
                                                                                                      "Ljava/lang/String;").object());
    
                alarmManager.callMethod<void>("set",
                                              "(IJLandroid/app/PendingIntent;)V",
                                              QAndroidJniObject::getStaticField<jint>("android/app/AlarmManager", "RTC"),
                                              jlong(QDateTime::currentMSecsSinceEpoch() + 500), pendingIntent.object());
    
            #endif
    
        }
        qApp->quit();
        app->deleteLater();
    
        return currentExitCode;
    }
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved