Android: Simplify the jni code in QAndroidPlatformServices

Remove the use of QtAndroid::AttachedJNIEnv and lazily cache
the openURL() methodID on first use.

Change-Id: I601d13bc7d644d7cb2f78655ad40c7d9566cf3cb
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
bb10
Christian Strømme 2014-04-23 16:22:04 +02:00 committed by Christian Stromme
parent c4b1fffb22
commit 1220a87f8a
2 changed files with 6 additions and 19 deletions

View File

@ -43,30 +43,21 @@
#include <QUrl>
#include <QDir>
#include <QDebug>
#include <QtCore/private/qjni_p.h>
QT_BEGIN_NAMESPACE
QAndroidPlatformServices::QAndroidPlatformServices()
{
QtAndroid::AttachedJNIEnv env;
if (!env.jniEnv)
return;
m_openURIMethodID = env.jniEnv->GetStaticMethodID(QtAndroid::applicationClass(),
"openURL",
"(Ljava/lang/String;)V");
}
bool QAndroidPlatformServices::openUrl(const QUrl &url)
{
QtAndroid::AttachedJNIEnv env;
if (!env.jniEnv)
return false;
jstring string = env.jniEnv->NewString(reinterpret_cast<const jchar *>(url.toString().constData()),
url.toString().length());
env.jniEnv->CallStaticVoidMethod(QtAndroid::applicationClass(), m_openURIMethodID, string);
env.jniEnv->DeleteLocalRef(string);
QJNIObjectPrivate urlString = QJNIObjectPrivate::fromString(url.toString());
QJNIObjectPrivate::callStaticMethod<void>(QtAndroid::applicationClass(),
"openURL",
"(Ljava/lang/String;)V",
urlString.object());
return true;
}

View File

@ -44,7 +44,6 @@
#include <qpa/qplatformservices.h>
#include "androidjnimain.h"
#include <jni.h>
QT_BEGIN_NAMESPACE
@ -55,9 +54,6 @@ public:
bool openUrl(const QUrl &url);
bool openDocument(const QUrl &url);
QByteArray desktopEnvironment() const;
private:
jmethodID m_openURIMethodID;
};
QT_END_NAMESPACE