Android: PlatformServices:Do not expect Intents in non-Activity usecase

In non-Activity contexts, do not register the QPlatformServices class
as an intent listener, as only Qt applications based on Qt Activities
will receive new Intents. Calling getIntent on a non-Activity context
will also cause an error, as getIntent is a method of Activity, not
Context.

Skip both when constructing QPlatformServices for applications without
an Activity context.

Task-number: QTBUG-118874
Change-Id: Ide64bd6a90d8db0a7654968ff42cdaa5da1d3b51
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
bb10
Petri Virkkunen 2024-02-15 11:57:33 +02:00
parent b43341f678
commit ec3c96d72d
1 changed files with 12 additions and 9 deletions

View File

@ -24,15 +24,18 @@ 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_CLASS(UriType, "android/net/Uri")