Commit a9540cf3 authored by Volker Krause's avatar Volker Krause

Fix launching Okular by opening a document from the file browser

Summary:
There's two issues here:
- Activity::onCreate triggered before the C++ side was loaded, so the
  call to C++ failed (causing a crash). So delay that until we are ready.
- The static instance of URIHandler in the header caused it to duplicate
  into each translation unit, causing main.cpp to not see what android.cpp
  wrote into it.

Subscribers: okular-devel

Tags: #okular

Differential Revision: https://phabricator.kde.org/D18399
parent 1fd9c052
......@@ -40,9 +40,7 @@ public class OpenFileActivity extends QtActivity
FileClass.openUri(uri.toString());
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void handleViewIntent() {
final Intent bundleIntent = getIntent();
if (bundleIntent == null)
return;
......
......@@ -17,11 +17,13 @@
*************************************************************************************/
#include "android.h"
#include <QtAndroid>
#include <QAndroidJniObject>
#include <QAndroidJniEnvironment>
#include <QStringList>
#include <QDebug>
URIHandler URIHandler::handler;
static AndroidInstance* s_instance = nullptr;
void AndroidInstance::openFile(const QString &title, const QStringList &mimes)
......@@ -44,6 +46,11 @@ void AndroidInstance::openFile(const QString &title, const QStringList &mimes)
}
}
void AndroidInstance::handleViewIntent()
{
QtAndroid::androidActivity().callMethod<void>("handleViewIntent", "()V");
}
void Java_org_kde_something_FileClass_openUri(JNIEnv *env,
jobject /*obj*/,
jstring uri)
......@@ -54,7 +61,7 @@ void Java_org_kde_something_FileClass_openUri(JNIEnv *env,
if (s_instance)
s_instance->openUri(QUrl(uriString));
else
handler.openUri(uriString);
URIHandler::handler.openUri(uriString);
env->ReleaseStringUTFChars(uri, utf);
}
......@@ -30,16 +30,17 @@ public:
}
QString m_lastUrl;
static URIHandler handler;
};
static URIHandler handler;
class AndroidInstance : public QObject
{
Q_OBJECT
public:
Q_SCRIPTABLE void openFile(const QString &title, const QStringList &mimes);
static void handleViewIntent();
Q_SIGNALS:
void openUri(const QUrl &uri);
};
......
......@@ -49,8 +49,9 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
#ifdef __ANDROID__
AndroidInstance::handleViewIntent();
qmlRegisterSingletonType<QObject>("org.kde.okular.app", 2, 0, "AndroidInstance", [](QQmlEngine*, QJSEngine*) -> QObject* { return new AndroidInstance; });
const QString uri = handler.m_lastUrl;
const QString uri = URIHandler::handler.m_lastUrl;
#else
qmlRegisterSingletonType<QObject>("org.kde.okular.app", 2, 0, "AndroidInstance", [](QQmlEngine*, QJSEngine*) -> QObject* { return new QObject; });
const QString uri = parser.positionalArguments().count() == 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment