Last active
May 24, 2021 17:24
-
-
Save strezh/5201d00023b2e95f4f61 to your computer and use it in GitHub Desktop.
Run Android Intent from Qt (#Android #application #Qt #Launcher)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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