API Documentation
Loading...
Searching...
No Matches
AndroidHelperFunctions.h
Go to the documentation of this file.
1#pragma once
2#ifdef ANDROID
3#include <QObject>
4 #ifdef ANDROID
5 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
6 #include <QtAndroidExtras>
7 #include <QAndroidJniObject>
8 #define JNIObject QAndroidJniObject
9 #else
10 #include <QtCore/private/qandroidextras_p.h>
11 #include <QJniObject>
12 #define QtAndroid QtAndroidPrivate
13 #define JNIObject QJniObject
14 #endif
15 class Android
16 {
17 public:
18 static void RunOnMainThread(const std::function<void()> &runnable)
19 {
20 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
21 QtAndroid::runOnAndroidThread(runnable);
22 #else
23 QCoreApplication::instance()->nativeInterface<QNativeInterface::QAndroidApplication>()->runOnAndroidMainThread([runnable]()
24 {
25 runnable();
26 return QVariant();
27 });
28 #endif
29 }
30 static JNIObject MainActivity()
31 {
32 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
33 return QtAndroid::androidActivity();
34 #else
35 return JNIObject(QCoreApplication::instance()->nativeInterface<QNativeInterface::QAndroidApplication>()->context());
36 #endif
37 }
38 static constexpr const char* QtNativePath()
39 {
40 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
41 return "org/qtproject/qt5/android/QtNative";
42 #else
43 return "org/qtproject/qt/android/bindings/QtActivity";
44 #endif
45 }
46 };
47 #endif
48#endif