本文介绍了startActivity Qt的,没有什么显示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I codeD像下面。
这似乎显示了Android设置菜单中,但没有出来。
而且我没有看到任何错误或登录了。我不知道打完电话后会发生什么 startActivity()

  QAndroidJniObject活性= QAndroidJniObject :: callStaticObjectMethod
                                     (组织/ qtproject / QT5 /安卓/ QtNative
                                      活动,
                                      ()Landroid /应用/活动;);如果(activity.isValid()){
    QAndroidJniObject P1 = QAndroidJniObject :: fromString(com.android.settings);
    QAndroidJniObject P2 = QAndroidJniObject :: fromString(com.android.settings.DevelopmentSettings);    QAndroidJniObject意图(机器人/内容/意图,()V);    如果(p1.isValid()及&放大器; p2.isValid()及&放大器; intent.isValid()){         qDebug()&所述;&下; 意图打造确定,startActivity         intent.callObjectMethod(setClassName
                                         (Ljava /朗/字符串; Ljava /朗/字符串;)Landroid /内容/意图;,
         p1.object< jobject>()
         p2.object&所述; jobject>());
         intent.callObjectMethod(startActivity
                     (Landroid /内容/意图;)V
                     intent.object&所述; jobject>());
    }
}


解决方案

startActivity 是活动类,而不是 。因此,它需要在活动对象被调用,而不是意图

  intent.callObjectMethod(startActivity,(Landroid /内容/意图;)V,intent.object< jobject>());

必须由替换:

  activity.callObjectMethod(startActivity,(Landroid /内容/意图;)V,intent.object< jobject>());

下面是工作code打开Android设置菜单:

  QAndroidJniObject活性= QAndroidJniObject :: callStaticObjectMethod(组织/ qtproject / QT5 /安卓/ QtNative,活动,()Landroid /应用/活动;); //活动是有效的
如果(activity.isValid())
{
    //相当于java的code:意向意图=新的Intent();'
    QAndroidJniObject意图(机器人/内容/意图,()V);
    如果(intent.isValid())
    {
        QAndroidJniObject参数1 = QAndroidJniObject :: fromString(com.android.settings);
        QAndroidJniObject param2的= QAndroidJniObject :: fromString(com.android.settings.DevelopmentSettings);        如果(param1.isValid()及&放大器; param2.isValid())
        {
            //相当于java的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>());            //相当于java的code:'startActivity(意向);'
            activity.callObjectMethod(\"startActivity\",\"(Landroid/content/Intent;)V\",intent.object<jobject>());
        }
    }
}

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 startActivity().

QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod
                                     ("org/qtproject/qt5/android/QtNative",
                                      "activity",
                                      "()Landroid/app/Activity;");

if(activity.isValid()){
    QAndroidJniObject p1 = QAndroidJniObject::fromString("com.android.settings");
    QAndroidJniObject p2 = QAndroidJniObject::fromString("com.android.settings.DevelopmentSettings");

    QAndroidJniObject intent("android/content/Intent", "()V");

    if(p1.isValid() && p2.isValid() && intent.isValid()){

         qDebug() << "intent create OK and startActivity";

         intent.callObjectMethod("setClassName",
                                         "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;",
         p1.object<jobject>(),
         p2.object<jobject>());
         intent.callObjectMethod("startActivity",
                     "(Landroid/content/Intent;)V",
                     intent.object<jobject>());
    }
}
解决方案

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 valid
if ( 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>());
        }
    }
}

这篇关于startActivity Qt的,没有什么显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 21:47