summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android
diff options
context:
space:
mode:
authorMartin Koller <kollix@aon.at>2015-08-04 21:29:18 +0200
committerBogDan Vatra <bogdan@kdab.com>2015-10-26 11:35:15 +0000
commit2f7d3cf559e0bdf8643e213de3a36796f6a88bd3 (patch)
tree149e44fd7cb1856c2e35655687b7568842480789 /src/plugins/platforms/android
parentc20f92a0fa11c2cc7bad8f69a1e0a8f8b5893df3 (diff)
Android: auto-detect MIME type for local files to make openUrl work
[ChangeLog][QtCore][Android] Fixed the opening of a local file using QDesktopServices::openUrl(). For a local file to be viewed with QDesktopServices::openUrl(), Android needs to be given the MIME type otherwise it does not start an Intent to view the file. Task-number: QTBUG-45585 Change-Id: Ifcfce4bff35011f205cfadbdb2b37a1780dac87d Reviewed-by: BogDan Vatra <bogdan@kdab.com>
Diffstat (limited to 'src/plugins/platforms/android')
-rw-r--r--src/plugins/platforms/android/qandroidplatformservices.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/plugins/platforms/android/qandroidplatformservices.cpp b/src/plugins/platforms/android/qandroidplatformservices.cpp
index 2dba6c78e1..412e3e0466 100644
--- a/src/plugins/platforms/android/qandroidplatformservices.cpp
+++ b/src/plugins/platforms/android/qandroidplatformservices.cpp
@@ -33,8 +33,9 @@
#include "qandroidplatformservices.h"
#include <QUrl>
-#include <QDir>
+#include <QFile>
#include <QDebug>
+#include <QMimeDatabase>
#include <QtCore/private/qjni_p.h>
QT_BEGIN_NAMESPACE
@@ -43,13 +44,27 @@ QAndroidPlatformServices::QAndroidPlatformServices()
{
}
-bool QAndroidPlatformServices::openUrl(const QUrl &url)
+bool QAndroidPlatformServices::openUrl(const QUrl &theUrl)
{
+ QString mime;
+ QUrl url(theUrl);
+
+ // if the file is local, we need to pass the MIME type, otherwise Android
+ // does not start an Intent to view this file
+ if ((url.scheme().isEmpty() && QFile::exists(url.path())) || url.isLocalFile()) {
+ // a real URL including the scheme is needed, else the Intent can not be started
+ url.setScheme(QLatin1String("file"));
+
+ QMimeDatabase mimeDb;
+ mime = mimeDb.mimeTypeForUrl(url).name();
+ }
+
QJNIObjectPrivate urlString = QJNIObjectPrivate::fromString(url.toString());
+ QJNIObjectPrivate mimeString = QJNIObjectPrivate::fromString(mime);
return QJNIObjectPrivate::callStaticMethod<jboolean>(QtAndroid::applicationClass(),
"openURL",
- "(Ljava/lang/String;)Z",
- urlString.object());
+ "(Ljava/lang/String;Ljava/lang/String;)Z",
+ urlString.object(), mimeString.object());
}
bool QAndroidPlatformServices::openDocument(const QUrl &url)