diff options
Diffstat (limited to 'src/plugins/platforms/android/qandroidplatformservices.cpp')
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformservices.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/plugins/platforms/android/qandroidplatformservices.cpp b/src/plugins/platforms/android/qandroidplatformservices.cpp index 5964236420..39287aa905 100644 --- a/src/plugins/platforms/android/qandroidplatformservices.cpp +++ b/src/plugins/platforms/android/qandroidplatformservices.cpp @@ -24,19 +24,22 @@ QAndroidPlatformServices::QAndroidPlatformServices() QtAndroidPrivate::registerNewIntentListener(this); - QMetaObject::invokeMethod( - this, - [this] { - QJniObject context = QJniObject(QtAndroidPrivate::context()); - QJniObject intent = - context.callObjectMethod("getIntent", "()Landroid/content/Intent;"); - handleNewIntent(nullptr, intent.object()); - }, - Qt::QueuedConnection); + // Qt applications without Activity contexts cannot retrieve intents from the Activity. + if (QNativeInterface::QAndroidApplication::isActivityContext()) { + QMetaObject::invokeMethod( + this, + [this] { + QJniObject context = QJniObject(QtAndroidPrivate::context()); + QJniObject intent = + context.callObjectMethod("getIntent", "()Landroid/content/Intent;"); + handleNewIntent(nullptr, intent.object()); + }, + Qt::QueuedConnection); + } } -Q_DECLARE_JNI_TYPE(UriType, "Landroid/net/Uri;") -Q_DECLARE_JNI_TYPE(FileType, "Ljava/io/File;") +Q_DECLARE_JNI_CLASS(UriType, "android/net/Uri") +Q_DECLARE_JNI_CLASS(FileType, "java/io/File") Q_DECLARE_JNI_CLASS(File, "java/io/File") Q_DECLARE_JNI_CLASS(FileProvider, "androidx/core/content/FileProvider"); @@ -78,11 +81,11 @@ bool QAndroidPlatformServices::openUrl(const QUrl &theUrl) const auto providerName = QJniObject::fromString(appId + ".qtprovider"_L1); const auto urlPath = QJniObject::fromString(url.path()); - const auto urlFile = QJniObject(QtJniTypes::className<QtJniTypes::File>(), + const auto urlFile = QJniObject(QtJniTypes::Traits<QtJniTypes::File>::className(), urlPath.object<jstring>()); const auto fileProviderUri = QJniObject::callStaticMethod<QtJniTypes::UriType>( - QtJniTypes::className<QtJniTypes::FileProvider>(), "getUriForFile", + QtJniTypes::Traits<QtJniTypes::FileProvider>::className(), "getUriForFile", QAndroidApplication::context(), providerName.object<jstring>(), urlFile.object<QtJniTypes::FileType>()); |