exclude custom android code if Qt 6 and greater

This commit is contained in:
Nikolaos Ftylitakis 2021-12-26 10:45:13 +02:00
parent 7d3b430b9e
commit 30fa997992
2 changed files with 44 additions and 23 deletions

View File

@ -15,12 +15,10 @@ CONFIG(debug, debug|release) {
}
HEADERS += \
application.h \
native.h
application.h
SOURCES += main.cpp \
application.cpp \
native.cpp
application.cpp
RESOURCES += qml.qrc
@ -33,28 +31,35 @@ include(../../src/QZXing-components.pri)
include(deployment.pri)
android {
QT += androidextras
lessThan(QT_VERSION, 6.2) {
HEADERS += \
native.h
DISTFILES += \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat
SOURCES += \
native.cpp
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
QT += androidextras
DISTFILES += \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
}
}
else:ios {
QMAKE_INFO_PLIST=Info.plist
}

View File

@ -1,10 +1,20 @@
#include "application.h"
#include <QDebug>
#if QT_VERSION < 0x060000
#include "native.h"
#endif
#if defined(Q_OS_ANDROID)
#if QT_VERSION < 0x060100
#include <QAndroidJniObject>
#include <QtAndroid>
#else
#include <QJniObject>
#endif
#endif // Q_OS_ANDROID
Application::Application()
@ -18,7 +28,9 @@ Application::Application()
connect(this, &Application::onPermissionsDenied,
this, &Application::initializeQML);
NativeHelpers::registerApplicationInstance(this);
#if QT_VERSION < 0x060000
NativeHelpers::registerApplicationInstance(this);
#endif
}
void Application::initializeQML()
@ -36,10 +48,14 @@ void Application::checkPermissions()
//intentionally called in the C++ thread since it is blocking and will continue after the check
qDebug() << "About to request permissions";
#if QT_VERSION < 0x060000
QAndroidJniObject::callStaticMethod<void>("org/ftylitak/qzxing/Utilities",
"requestQZXingPermissions",
"(Landroid/app/Activity;)V",
QtAndroid::androidActivity().object());
#else
emit onPermissionsGranted();
#endif
qDebug() << "Permissions granted";
#else
emit onPermissionsGranted();