summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorLars Schmertmann <Lars.Schmertmann@governikus.de>2020-05-30 19:45:59 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-09-10 16:40:00 +0000
commit79bb0f1d52d12478a7aa495e4ac10e0083df2398 (patch)
treea756c43d38000725537eefefb7a7be5f4eed9b4e /src/gui
parent098883d0689de39ce79ebaa49f160d39b6adea73 (diff)
Android: Enable QDesktopService
QDesktopServices::openUrl(const QUrl &url) is already implemented on Android. But even if it is possible to set an URL handler, the mechanism to invoke it is missing. With this commit the URL handler will work on Android like it is already working on iOS. Task-number: QTBUG-84382 Change-Id: Ic560bd380f1cc59586861aa1a6a3ea064276a39e Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit f2b914afc6a5ba4aa2f8dcd13a979f04f07034c2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp26
-rw-r--r--src/gui/util/qdesktopservices.cpp51
2 files changed, 65 insertions, 12 deletions
diff --git a/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp b/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp
index 0809d62da9..f1aff54fea 100644
--- a/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp
+++ b/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp
@@ -144,7 +144,31 @@ QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
}
//! [8]
-*/ // comment wrapper 3
+//! [9]
+<intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+ <data android:scheme="https" android:host="your.domain.com" android:port="1337" android:path="/help"/>
+</intent-filter>
+//! [9]
+
+//! [10]
+<intent-filter android:autoVerify="true">
+//! [10]
+
+//! [11]
+[{
+ "relation": ["delegate_permission/common.handle_all_urls"],
+ "target": {
+ "namespace": "android_app",
+ "package_name": "com.example.app",
+ "sha256_cert_fingerprints":
+ ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"]
+ }
+}]
+//! [11]
+*/ // comment wrapper 3
} // src_gui_util_qdesktopservices
diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp
index 0550cb6f75..7a728cf692 100644
--- a/src/gui/util/qdesktopservices.cpp
+++ b/src/gui/util/qdesktopservices.cpp
@@ -182,7 +182,7 @@ void QOpenUrlHandlerRegistry::handlerDestroyed(QObject *handler)
\warning URLs passed to this function on iOS will not load unless their schemes are
listed in the \c LSApplicationQueriesSchemes key of the application's Info.plist file.
For more information, see the Apple Developer Documentation for
- \l{https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl}{canOpenURL(_:)}.
+ \l {iOS: canOpenURL:}{canOpenURL:}.
For example, the following lines enable URLs with the HTTPS scheme:
\snippet code/src_gui_util_qdesktopservices.cpp 3
@@ -244,14 +244,25 @@ bool QDesktopServices::openUrl(const QUrl &url)
\snippet code/src_gui_util_qdesktopservices.cpp 0
+ If setUrlHandler() is used to set a new handler for a scheme which already
+ has a handler, the existing handler is simply replaced with the new one.
+ Since QDesktopServices does not take ownership of handlers, no objects are
+ deleted when a handler is replaced.
+
+ Note that the handler will always be called from within the same thread that
+ calls QDesktopServices::openUrl().
+
+ \section1 iOS
+
To use this function for receiving data from other apps on iOS you also need to
add the custom scheme to the \c CFBundleURLSchemes list in your Info.plist file:
\snippet code/src_gui_util_qdesktopservices.cpp 4
For more information, see the Apple Developer Documentation for
- \l{https://developer.apple.com/documentation/uikit/core_app/allowing_apps_and_websites_to_link_to_your_content/communicating_with_other_apps_using_custom_urls?language=objc}{Communicating with Other Apps Using Custom URLs}.
- \warning It is not possible to claim support for some well known URL schemes, including http and https. This is only allowed for Universal Links.
+ \l {iOS: Defining a Custom URL Scheme for Your App}{Defining a Custom URL Scheme for Your App}.
+ \warning It is not possible to claim support for some well known URL schemes, including http and
+ https. This is only allowed for Universal Links.
To claim support for http and https the above entry in the Info.plist file
is not allowed. This is only possible when you add your domain to the
@@ -261,21 +272,39 @@ bool QDesktopServices::openUrl(const QUrl &url)
iOS will search for /.well-known/apple-app-site-association on your domain,
when the application is installed. If you want to listen to
- https://your.domain.com/help?topic=ABCDEF you need to provide the following
+ \c{https://your.domain.com/help?topic=ABCDEF} you need to provide the following
content there:
\snippet code/src_gui_util_qdesktopservices.cpp 8
For more information, see the Apple Developer Documentation for
- \l{https://developer.apple.com/documentation/safariservices/supporting_associated_domains_in_your_app}[Supporting Associated Domains}.
+ \l {iOS: Supporting Associated Domains}{Supporting Associated Domains}.
- If setUrlHandler() is used to set a new handler for a scheme which already
- has a handler, the existing handler is simply replaced with the new one.
- Since QDesktopServices does not take ownership of handlers, no objects are
- deleted when a handler is replaced.
+ \section1 Android
- Note that the handler will always be called from within the same thread that
- calls QDesktopServices::openUrl().
+ To use this function for receiving data from other apps on Android, you
+ need to add one or more intent filter to the \c activity in your app manifest:
+
+ \snippet code/src_gui_util_qdesktopservices.cpp 9
+
+ For more information, see the Android Developer Documentation for
+ \l {Android: Create Deep Links to App Content}{Create Deep Links to App Content}.
+
+ To immediately open the corresponding content in your Android app, without
+ requiring the user to select the app, you need to verify your link. To
+ enable the verification, add an additional parameter to your intent filter:
+
+ \snippet code/src_gui_util_qdesktopservices.cpp 10
+
+ Android will look for \c{https://your.domain.com/.well-known/assetlinks.json},
+ when the application is installed. If you want to listen to
+ \c{https://your.domain.com:1337/help}, you need to provide the following
+ content there:
+
+ \snippet code/src_gui_util_qdesktopservices.cpp 11
+
+ For more information, see the Android Developer Documentation for
+ \l {Android: Verify Android App Links}{Verify Android App Links}.
\sa openUrl(), unsetUrlHandler()
*/