From 7bb2c3a09d3583b9681c21d80d591508b5e5fcd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 7 Feb 2023 00:32:36 +0100 Subject: [PATCH] Added Android "desktop" integration --- pkg/android/AndroidManifest.xml | 41 ++++++++++++++++++- .../src/org/gpxsee/gpxsee/Activity.java | 26 ++++++++++++ src/GUI/app.cpp | 20 +++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 pkg/android/src/org/gpxsee/gpxsee/Activity.java diff --git a/pkg/android/AndroidManifest.xml b/pkg/android/AndroidManifest.xml index 327a0954..4caa296e 100644 --- a/pkg/android/AndroidManifest.xml +++ b/pkg/android/AndroidManifest.xml @@ -4,11 +4,50 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pkg/android/src/org/gpxsee/gpxsee/Activity.java b/pkg/android/src/org/gpxsee/gpxsee/Activity.java new file mode 100644 index 00000000..98d51877 --- /dev/null +++ b/pkg/android/src/org/gpxsee/gpxsee/Activity.java @@ -0,0 +1,26 @@ +package org.gpxsee.gpxsee; + +import android.content.Intent; + +public class Activity extends org.qtproject.qt.android.bindings.QtActivity +{ + @Override + public void onNewIntent(Intent intent) + { + setIntent(intent); + } + + public String intentPath() + { + String path = ""; + + Intent intent = getIntent(); + if (intent != null) { + if (intent.getAction() == Intent.ACTION_VIEW) + path = intent.getDataString(); + setIntent(null); + } + + return path; + } +} diff --git a/src/GUI/app.cpp b/src/GUI/app.cpp index 91a8eaa1..a251abb0 100644 --- a/src/GUI/app.cpp +++ b/src/GUI/app.cpp @@ -6,6 +6,11 @@ #include #include #include +#ifdef Q_OS_ANDROID +#include +#include +#endif // Q_OS_ANDROID + #include "common/programpaths.h" #include "common/config.h" #include "common/downloader.h" @@ -102,6 +107,21 @@ void App::appStateChanged(Qt::ApplicationState state) { if (state == Qt::ApplicationSuspended) _gui->writeSettings(); + else if (state == Qt::ApplicationActive) { + QJniObject activity = QNativeInterface::QAndroidApplication::context(); + QString path(activity.callObjectMethod("intentPath").toString()); + if (!path.isEmpty()) { + if (!_gui->openFile(path, true)) { + MapAction *a; + if (!_gui->loadMap(path, a, true)) + _gui->openFile(path, false); + else { + if (a) + a->trigger(); + } + } + } + } } #endif // Q_OS_ANDROID