我正在尝试使用Intent交流两个Android(基于Qt)应用程序,但无法正常工作。
它们是两个应用程序,即桌面应用程序和返回应用程序,在这里您可以看到清单
<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="Desktop" android:screenOrientation="landscape" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<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="Return" android:screenOrientation="landscape" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
我正在尝试通过台式机应用程序使用此代码,试图调用return应用程序(均在Qt + Android中)
QString packageName="org.qtproject.qt5.android.bindings.QtActivity";
QString className="Return";
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.callMethod<void>(
"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";
}
我总是收到“找不到意图!”
预先感谢, 塞尔吉奥