如何在adroid设备上再次启动自己的qt应用程序

时间:2019-04-14 11:55:47

标签: android c++ qt

我想使用其他参数再次启动我自己的应用程序(用于看门狗服务)。

但是我无法启动任何应用程序。这是主要功能的代码:

    QAndroidJniObject activity = QtAndroid::androidActivity();

    QAndroidJniObject packageManager = activity.callObjectMethod(
        "getPackageManager",
        "()Landroid/content/pm/PackageManager;"
    );

    QAndroidJniObject param =
    QAndroidJniObject::fromString("org.qtproject.example.my_app_name");

    QAndroidJniObject intent = packageManager.callObjectMethod(
        "getLaunchIntentForPackage",
        "()Landroid/content/Intent;",
        param.object<jstring>()
    );

    activity.callMethod<void>(
        "startActivity",
        "(Landroid/content/Intent;)V",
        intent.object<jobject>()
    );

错误是:

E/AndroidRuntime(21014): FATAL EXCEPTION: QtThread
E/AndroidRuntime(21014): java.lang.NullPointerException
E/AndroidRuntime(21014):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
E/AndroidRuntime(21014):    at android.app.Activity.startActivityForResult(Activity.java:3587)
E/AndroidRuntime(21014):    at android.app.Activity.startActivityForResult(Activity.java:3548)
E/AndroidRuntime(21014):    at android.app.Activity.startActivity(Activity.java:3758)
E/AndroidRuntime(21014):    at android.app.Activity.startActivity(Activity.java:3726)
E/AndroidRuntime(21014):    at dalvik.system.NativeStart.run(Native Method)

0 个答案:

没有答案