Skip to content Skip to sidebar Skip to footer

Startactivity On Qt, Nothing Displays

I coded like below. It seems to display the Android Setting menu, but nothing comes out. And I did not see any error or log about it. I don't know what happens after calling the s

Solution 1:

startActivity is a method of Activity class, not Intent. So it needs to be called on activity object, not on intent.

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

must be replace by:

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

Here is the working code to open Android settings menu:

QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");   //activity is validif ( activity.isValid() )
{
    // Equivalent to Jave code: 'Intent intent = new Intent();'
    QAndroidJniObject intent("android/content/Intent","()V");
    if ( intent.isValid() )
    {
        QAndroidJniObject param1 = QAndroidJniObject::fromString("com.android.settings");
        QAndroidJniObject param2 = QAndroidJniObject::fromString("com.android.settings.DevelopmentSettings");

        if ( param1.isValid() && param2.isValid() )
        {
            // Equivalent to Jave code: 'intent.setClassName("com.android.settings", "com.android.settings.DevelopmentSettings");'
            intent.callObjectMethod("setClassName","(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;",param1.object<jobject>(),param2.object<jobject>());

            // Equivalent to Jave code: 'startActivity(intent);'
            activity.callObjectMethod("startActivity","(Landroid/content/Intent;)V",intent.object<jobject>());
        }
    }
}

Post a Comment for "Startactivity On Qt, Nothing Displays"