Commit 4afc5f07 authored by Volker Krause's avatar Volker Krause
Browse files

Adapt KAndroidExtras to the Qt6 Android API changes

parent 18eac3f3
Pipeline #185933 passed with stage
in 1 minute and 35 seconds
......@@ -7,7 +7,12 @@
#include <KAndroidExtras/Context>
#include <KAndroidExtras/ContentResolver>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QAndroidJniObject>
#else
#include <QJniObject>
using QAndroidJniObject = QJniObject;
#endif
#include <QtTest/qtest.h>
using namespace KAndroidExtras;
......
......@@ -29,7 +29,11 @@ target_compile_features(KAndroidExtras PUBLIC cxx_std_20) # for __VA_OPT__
target_link_libraries(KAndroidExtras PUBLIC Qt::Core)
if (ANDROID)
target_link_libraries(KAndroidExtras PUBLIC Qt::AndroidExtras)
if (QT_MAJOR_VERSION EQUAL "5")
target_link_libraries(KAndroidExtras PUBLIC Qt5::AndroidExtras)
else()
target_link_libraries(KAndroidExtras PRIVATE Qt::CorePrivate)
endif()
else()
target_include_directories(KAndroidExtras PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/fake)
if (QT_MAJOR_VERSION EQUAL "5")
......
......@@ -10,14 +10,27 @@
#include <KAndroidExtras/Intent>
#include <KAndroidExtras/JniSignature>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtAndroid>
#include <QAndroidJniEnvironment>
#else
#include <QCoreApplication>
#include <QJniEnvironment>
using QJniEnvironment = QAndroidJniEnvironment;
#include <private/qandroidextras_p.h>
#endif
using namespace KAndroidExtras;
Intent Activity::getIntent()
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto activity = QtAndroid::androidActivity();
#else
const QJniObject activity = QNativeInterface::QAndroidApplication::context();
#endif
if (!activity.isValid())
return {};
......@@ -28,7 +41,11 @@ Intent Activity::getIntent()
bool Activity::startActivity(const Intent &intent, int receiverRequestCode)
{
QAndroidJniEnvironment jniEnv;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QtAndroid::startActivity(intent, receiverRequestCode);
#else
QtAndroidPrivate::startActivity(intent, receiverRequestCode);
#endif
if (jniEnv->ExceptionCheck()) {
jniEnv->ExceptionClear();
return false;
......
......@@ -11,8 +11,12 @@
#include <KAndroidExtras/AndroidTypes>
#include <KAndroidExtras/JniSignature>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtAndroid>
#include <QAndroidJniObject>
#else
#include <QCoreApplication>
#endif
#include <QString>
#include <QUrl>
......@@ -21,7 +25,12 @@ using namespace KAndroidExtras;
QAndroidJniObject ContentResolver::get()
{
return QtAndroid::androidContext().callObjectMethod("getContentResolver", Jni::signature<android::content::ContentResolver()>());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto context = QtAndroid::androidContext();
#else
const QJniObject context = QNativeInterface::QAndroidApplication::context();
#endif
return context.callObjectMethod("getContentResolver", Jni::signature<android::content::ContentResolver()>());
}
QString ContentResolver::mimeType(const QUrl &url)
......
......@@ -9,7 +9,13 @@
#include "kandroidextras_export.h"
#include <qglobal.h>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
class QAndroidJniObject;
#else
class QJniObject;
using QAndroidJniObject = QJniObject;
#endif
class QString;
class QUrl;
......
......@@ -9,11 +9,20 @@
#include <KAndroidExtras/JavaTypes>
#include <KAndroidExtras/JniSignature>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtAndroid>
#else
#include <QCoreApplication>
#endif
using namespace KAndroidExtras;
QAndroidJniObject Context::getPackageName()
{
return QtAndroid::androidContext().callObjectMethod("getPackageName", Jni::signature<java::lang::String()>());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto context = QtAndroid::androidContext();
#else
const QJniObject context = QNativeInterface::QAndroidApplication::context();
#endif
return context.callObjectMethod("getPackageName", Jni::signature<java::lang::String()>());
}
......@@ -9,7 +9,13 @@
#include "kandroidextras_export.h"
#include <qglobal.h>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
class QAndroidJniObject;
#else
class QJniObject;
using QAndroidJniObject = QJniObject;
#endif
namespace KAndroidExtras {
......
......@@ -10,7 +10,6 @@
#include <KAndroidExtras/JniArray>
#include <KAndroidExtras/JniSignature>
#include <QAndroidJniEnvironment>
#include <QUrl>
using namespace KAndroidExtras;
......
......@@ -15,8 +15,6 @@
#include <KAndroidExtras/JavaTypes>
#include <KAndroidExtras/Uri>
#include <QAndroidJniObject>
class QUrl;
namespace KAndroidExtras {
......
......@@ -9,8 +9,6 @@
#include <KAndroidExtras/JniSignature>
#include <KAndroidExtras/JavaTypes>
#include <QAndroidJniObject>
using namespace KAndroidExtras;
QAndroidJniObject Uri::fromUrl(const QUrl &url)
......
......@@ -14,8 +14,6 @@
#include <QUrl>
class QAndroidJniObject;
namespace KAndroidExtras {
/** Conversion methods for android.net.Uri. */
......
/*
SPDX-FileCopyrightText: 2020-2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KANDROIDEXTRAS_MAKE_QTANDROIDEXTRAS_P_H
#define KANDROIDEXTRAS_MAKE_QTANDROIDEXTRAS_P_H
#include <QJniObject>
/** Mock object for QtAndroid namespace. */
namespace QtAndroidPrivate {
inline void startActivity(const QJniObject&, int) {}
}
#endif
......@@ -9,7 +9,6 @@
#include <KAndroidExtras/JavaTypes>
#include <KAndroidExtras/JniSignature>
#include <QAndroidJniObject>
#include <QLocale>
using namespace KAndroidExtras;
......
......@@ -9,7 +9,13 @@
#include "kandroidextras_export.h"
#include <qglobal.h>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
class QAndroidJniObject;
#else
class QJniObject;
using QAndroidJniObject = QJniObject;
#endif
class QLocale;
namespace KAndroidExtras {
......
......@@ -9,8 +9,6 @@
#include "jniobject.h"
#include "jnitypetraits.h"
#include <QAndroidJniObject>
namespace KAndroidExtras {
namespace Jni {
template <typename T> class Array;
......
......@@ -11,8 +11,12 @@
#include "jnireturnvalue.h"
#include "jnitypetraits.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QAndroidJniEnvironment>
#include <QAndroidJniObject>
#else
#include <QJniEnvironment>
using QAndroidJniEnvironment = QJniEnvironment;
#endif
namespace KAndroidExtras {
......
......@@ -13,8 +13,6 @@
#include "jnireturnvalue.h"
#include "jnitypetraits.h"
#include <QAndroidJniObject>
namespace KAndroidExtras {
///@cond internal
......
......@@ -13,8 +13,6 @@
#include "jnitypes.h"
#include "jnitypetraits.h"
#include <QAndroidJniObject>
#include <type_traits>
namespace KAndroidExtras {
......
......@@ -9,8 +9,6 @@
#include "jniobject.h"
#include "jnitypetraits.h"
#include <QAndroidJniObject>
namespace KAndroidExtras {
namespace Jni {
template <typename T> class Array;
......
......@@ -9,7 +9,13 @@
#include "jnitypes.h"
#include <qglobal.h>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QAndroidJniObject>
#else
#include <QJniObject>
using QAndroidJniObject = QJniObject;
#endif
#include <type_traits>
......
Supports Markdown
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