QAndroidJniObject 使得从 Qt C++ 代码创建 JNI 对象成为可能。
例如:获取活动:
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
例如:创建一个新的 Intent:
QAndroidJniObject intent("android/content/Intent","()V");
然后,您可以逐步翻译从 C++ 执行您的 java 代码......
要回答您的具体问题,只需复制/粘贴此代码:
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>());
}
}
}
...然后投票!;-)