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
parent
c4b1fffb22
commit
1220a87f8a
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue