-
-
Save strezh/5201d00023b2e95f4f61 to your computer and use it in GitHub Desktop.
void runApplication(const QString &packageName, const QString &className) | |
{ | |
qDebug() << "Start app: " <<packageName <<", "<<className; | |
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 jPackageName = QAndroidJniObject::fromString(packageName); | |
QAndroidJniObject jClassName = QAndroidJniObject::fromString(className); | |
if ( jPackageName.isValid() && jClassName.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;", | |
jPackageName.object<jstring>(),jClassName.object<jstring>()); | |
jint flag = QAndroidJniObject::getStaticField<jint>( | |
"android/content/Intent", | |
"FLAG_ACTIVITY_NEW_TASK"); | |
intent.callObjectMethod("setFlags", "(I)V",flag); | |
// Equivalent to Jave code: 'startActivity(intent);' | |
QAndroidJniEnvironment env; | |
activity.callObjectMethod( | |
"startActivity", | |
"(Landroid/content/Intent;)V", | |
intent.object<jobject>()); | |
if (env->ExceptionCheck()) { | |
qDebug() << "Intent not found!"; | |
env->ExceptionClear(); // TODO: stupid method! Remove this! | |
} | |
} else { | |
qDebug() << "Action is not valid"; | |
} | |
} else { | |
qDebug() << "Intent is not valid"; | |
} | |
} else { | |
qDebug() << "Activity is not valid"; | |
} | |
} |
Hi, I tried your code to start a new activity from my "Qt for android" application but it crashes.
I get the following error message:
art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: the return type of CallObjectMethodV does not match void android.app.Activity.startActivity(android.content.Intent)
when executing activity.callObjectMethod .
Can you help me?
Hi, could you please upload an example project or similar? How can I use this function?
Thanks a lot.
For those that are getting
JNI DETECTED ERROR IN APPLICATION: the return type of CallObjectMethodV does not match void android.app.Activity.startActivity(android.content.Intent)
You should use
activity.callMethod<void>("startActivity","(Landroid/content/Intent;)V", intent.object<jobject>());
Instead of
activity.callObjectMethod("startActivity","(Landroid/content/Intent;)V",intent.object<jobject>());
Starting from Android 5.x as filled in this QTBUG -> https://bugreports.qt.io/browse/QTBUG-48631
Hi, i am trying to Intent a Qt app from another Qt app (qt+android both) and always recieving "intent not found" :-(
What can i do?
Here a part of the manifest
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="Devolucion" android:screenOrientation="landscape" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Thank you strezh.
Can you help me, when I send url ("http://www.myweb.com") to "com.android.browser"