Remove dependencies from QtAndroidExtras

Change-Id: Ic5d0f3c60db8c7078aa5f57075c8b9a627594925
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
This commit is contained in:
Assam Boudjelthia 2021-05-11 13:48:19 +03:00
parent cb5843c9c4
commit e1407d42de
6 changed files with 18 additions and 73 deletions

View File

@ -28,6 +28,7 @@
/*! /*!
\page android-services.html \page android-services.html
\title Android Services \title Android Services
\preliminary
\brief Provides information about Android Services support in Qt. \brief Provides information about Android Services support in Qt.
\previouspage android-openssl-support.html \previouspage android-openssl-support.html
\nextpage android-3rdparty-libs.html \nextpage android-3rdparty-libs.html
@ -91,22 +92,22 @@ public class QtAndroidService extends QtService
Android allows starting services on demand or at boot time. You can do both using Android allows starting services on demand or at boot time. You can do both using
Qt as well. Qt as well.
\omit //! Qt Android Extras not part of Qt 6.0
\section3 Start a Service On Demand \section3 Start a Service On Demand
You can start the service in the following ways: You can start the service in the following ways:
\list \list
\li Directly from C++ using \l {QtAndroidExtras}{QAndroidIntent} and \li Directly from C++ using \l {QAndroidIntent} and
\l {QtAndroidExtras}{QAndroidJniObject}, by creating a service \l {QJniObject}, by creating a service
\l {Android: Intent}{Intent} and calling the app's main activity method \l {Android: Intent}{Intent} and calling the app's main activity method
\l {Android: startService()}{startService()}: \l {Android: startService()}{startService()}:
\code \code
QAndroidIntent serviceIntent(QtAndroid::androidActivity().object(), auto activity = QJniObject(QNativeInterface::QAndroidApplication:context());
QAndroidIntent serviceIntent(activity.object(),
"org/qtproject/example/qtandroidservice/QtAndroidService"); "org/qtproject/example/qtandroidservice/QtAndroidService");
QAndroidJniObject result = QtAndroid::androidActivity().callObjectMethod( QJniObject result = activity.callObjectMethod(
"startService", "startService",
"(Landroid/content/Intent;)Landroid/content/ComponentName;", "(Landroid/content/Intent;)Landroid/content/ComponentName;",
serviceIntent.handle().object()); serviceIntent.handle().object());
@ -124,14 +125,13 @@ You can start the service in the following ways:
The you can call it from C++ using the following JNI call: The you can call it from C++ using the following JNI call:
\code \code
QAndroidJniObject::callStaticMethod<void>( QJniObject::callStaticMethod<void>(
"org/qtproject/example/qtandroidservice/QtAndroidService", "org/qtproject/example/qtandroidservice/QtAndroidService",
"startQtAndroidService", "startQtAndroidService",
"(Landroid/content/Context;)V", "(Landroid/content/Context;)V",
QtAndroid::androidActivity().object()); QtAndroid::androidActivity().object());
\endcode \endcode
\endlist \endlist
\endomit //! Qt Android Extras not part of Qt 6.0
\section3 Start a Service At Boot Time \section3 Start a Service At Boot Time
@ -312,7 +312,7 @@ provides a different executable for the service. A sample project \c .pro is:
TEMPLATE = lib TEMPLATE = lib
TARGET = service TARGET = service
CONFIG += dll CONFIG += dll
QT += core androidextras QT += core core-private
SOURCES += \ SOURCES += \
service_main.cpp service_main.cpp
@ -352,12 +352,13 @@ BroadcastReceiver.
This can work with services running in the same process as \c QtActivity and even This can work with services running in the same process as \c QtActivity and even
if \c Service is extended. if \c Service is extended.
//! TODO bring back once the jni example is merged to qtbase
\omit //! Qt Android Extras not part of Qt 6.0 \omit //! Qt Android Extras not part of Qt 6.0
For more information, see For more information, see
\l{Calling QML/C++ Functions from Java Code}. \l{Calling QML/C++ Functions from Java Code}.
\endomit //! Qt Android Extras not part of Qt 6.0 \endomit //! Qt Android Extras not part of Qt 6.0
\omit //! Qt Android Extras not part of Qt 6.0
\section2 Using Android BroadcastReceiver \section2 Using Android BroadcastReceiver
\l {Android: BroadcastReceiver}{Android BroadcastReceiver} enables exchanging \l {Android: BroadcastReceiver}{Android BroadcastReceiver} enables exchanging
@ -424,17 +425,14 @@ an then register the broadcast receiver by calling the method
\c registerServiceBroadcastReceiver(): \c registerServiceBroadcastReceiver():
\code \code
QAndroidJniEnvironment env; QJniEnvironment env;
jclass javaClass = env.findClass("org/qtproject/example/qtandroidservice/ActivityUtils"); jclass javaClass = env.findClass("org/qtproject/example/qtandroidservice/ActivityUtils");
QAndroidJniObject classObject(javaClass); QJniObject classObject(javaClass);
classObject.callMethod<void>("registerServiceBroadcastReceiver", classObject.callMethod<void>("registerServiceBroadcastReceiver",
"(Landroid/content/Context;)V", "(Landroid/content/Context;)V",
QtAndroid::androidContext().object()); QtAndroid::androidContext().object());
\endcode \endcode
\endomit //! Android Extras not part of Qt 6.0
\omit //! Qt Remote Objects not part of Qt 6.0
\section2 Using Qt Remote Objects \section2 Using Qt Remote Objects
@ -527,7 +525,6 @@ on the debug logcat.
\note The same method could be used when using the same \c .so lib file. For more \note The same method could be used when using the same \c .so lib file. For more
information, see \l{Use the same .so Lib File}. information, see \l{Use the same .so Lib File}.
\endomit //! Qt Remote Objects not part of Qt 6.0
\section2 Using QAndroidBinder \section2 Using QAndroidBinder

View File

@ -68,13 +68,9 @@ The following list summarizes what you can do with Qt for Android:
\li Connect and exchange data with \l{Qt Bluetooth}{Bluetooth} \li Connect and exchange data with \l{Qt Bluetooth}{Bluetooth}
and \l{Qt NFC}{NFC}-enabled devices. and \l{Qt NFC}{NFC}-enabled devices.
\endomit //! Qt Bluetooth and NFC not part of Qt 6.0 \endomit //! Qt Bluetooth and NFC not part of Qt 6.0
\omit //! Qt Android Extras not part of Qt 6.0
\li Integrate Java code into your application using Qt Android Extras. \li Integrate Java code into your application using Qt Android Extras.
\endomit //! Qt Android Extras not part of Qt 6.0
\li Develop secure applications using OpenSSL library. \li Develop secure applications using OpenSSL library.
\omit //! Not part of Qt 6.0
\li Create \l{Android Services}. \li Create \l{Android Services}.
\endomit //! Not part of Qt 6.0
\li Create and deploy Application Package (APK) and Android App Bundle (AAB) \li Create and deploy Application Package (APK) and Android App Bundle (AAB)
packages using Qt Creator. packages using Qt Creator.
\endlist \endlist

View File

@ -59,26 +59,6 @@
\li \l{Qt for Android - Building from Source} \li \l{Qt for Android - Building from Source}
\endlist \endlist
\omit //! Not part of Qt 6.0
\l {Qt Android Extras} is an Android specific module used to integrate Qt
API with Java API by enabling communication between Qt code (C++ and QML)
and Java code. The following examples demonstrate some of the features of
the module:
\list
\li \l{Qt Notifier} demonstrates how to call Java code from an
Android application.
\li \l{Qt JNI Messenger} demonstrates communication between Java code
and QML or C++ using JNI calls.
\li \l{Android Custom Activity} demonstrates working with custom Android activities.
\li \l{Qt JNI Music List} demonstrates how to exchange data from complex Java objects.
\li \l{Android Service with Qt Remote Objects} demonstrates how to run an Android service,
and how to communicate between the service and the app using Qt Remote Objects.
\endlist
For the full list examples, see \l {Qt Android Extras Examples}.
\endomit //! Not part of Qt 6.0
\section1 Qt Quick and QML Examples for Android \section1 Qt Quick and QML Examples for Android
The following Qt Quick and QML examples are useful when developing The following Qt Quick and QML examples are useful when developing

View File

@ -65,16 +65,6 @@ qt6_add_resources(photosurface "photosurface"
${photosurface_resource_files} ${photosurface_resource_files}
) )
if(ANDROID AND TARGET Qt::AndroidExtras)
target_compile_definitions(photosurface PUBLIC
REQUEST_PERMISSIONS_ON_ANDROID
)
target_link_libraries(photosurface PUBLIC
Qt::AndroidExtras
)
endif()
if(TARGET Qt::Widgets) if(TARGET Qt::Widgets)
target_link_libraries(photosurface PUBLIC target_link_libraries(photosurface PUBLIC
Qt::Widgets Qt::Widgets

View File

@ -64,22 +64,6 @@
#include <QtCore/QMimeDatabase> #include <QtCore/QMimeDatabase>
#include <QtCore/QStandardPaths> #include <QtCore/QStandardPaths>
#include <QtCore/QUrl> #include <QtCore/QUrl>
#ifdef REQUEST_PERMISSIONS_ON_ANDROID
#include <QtAndroid>
bool requestStoragePermission() {
using namespace QtAndroid;
QString permission = QStringLiteral("android.permission.WRITE_EXTERNAL_STORAGE");
const QHash<QString, PermissionResult> results = requestPermissionsSync(QStringList({permission}));
if (!results.contains(permission) || results[permission] == PermissionResult::Denied) {
qWarning() << "Couldn't get permission: " << permission;
return false;
}
return true;
}
#endif
static QStringList imageNameFilters() static QStringList imageNameFilters()
{ {
@ -104,10 +88,12 @@ int main(int argc, char* argv[])
#else #else
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
#endif #endif
#ifdef REQUEST_PERMISSIONS_ON_ANDROID
if (!requestStoragePermission()) auto permission = QPermission::WriteStorage;
if (QCoreApplication::requestPermission(permission).result() != QPermission::Authorized) {
qWarning() << "Couldn't get 'WriteStorage' permission!";
return -1; return -1;
#endif }
QQuickWindow::setDefaultAlphaBuffer(true); QQuickWindow::setDefaultAlphaBuffer(true);
QCoreApplication::setApplicationName(QStringLiteral("Photosurface")); QCoreApplication::setApplicationName(QStringLiteral("Photosurface"));

View File

@ -1,10 +1,6 @@
TEMPLATE = app TEMPLATE = app
QT += qml quick QT += qml quick
android: qtHaveModule(androidextras) {
QT += androidextras
DEFINES += REQUEST_PERMISSIONS_ON_ANDROID
}
qtHaveModule(widgets): QT += widgets qtHaveModule(widgets): QT += widgets
SOURCES += main.cpp SOURCES += main.cpp
RESOURCES += photosurface.qrc RESOURCES += photosurface.qrc