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
\title Android Services
\preliminary
\brief Provides information about Android Services support in Qt.
\previouspage android-openssl-support.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
Qt as well.
\omit //! Qt Android Extras not part of Qt 6.0
\section3 Start a Service On Demand
You can start the service in the following ways:
\list
\li Directly from C++ using \l {QtAndroidExtras}{QAndroidIntent} and
\l {QtAndroidExtras}{QAndroidJniObject}, by creating a service
\li Directly from C++ using \l {QAndroidIntent} and
\l {QJniObject}, by creating a service
\l {Android: Intent}{Intent} and calling the app's main activity method
\l {Android: startService()}{startService()}:
\code
QAndroidIntent serviceIntent(QtAndroid::androidActivity().object(),
"org/qtproject/example/qtandroidservice/QtAndroidService");
QAndroidJniObject result = QtAndroid::androidActivity().callObjectMethod(
auto activity = QJniObject(QNativeInterface::QAndroidApplication:context());
QAndroidIntent serviceIntent(activity.object(),
"org/qtproject/example/qtandroidservice/QtAndroidService");
QJniObject result = activity.callObjectMethod(
"startService",
"(Landroid/content/Intent;)Landroid/content/ComponentName;",
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:
\code
QAndroidJniObject::callStaticMethod<void>(
QJniObject::callStaticMethod<void>(
"org/qtproject/example/qtandroidservice/QtAndroidService",
"startQtAndroidService",
"(Landroid/content/Context;)V",
QtAndroid::androidActivity().object());
\endcode
\endlist
\endomit //! Qt Android Extras not part of Qt 6.0
\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
TARGET = service
CONFIG += dll
QT += core androidextras
QT += core core-private
SOURCES += \
service_main.cpp
@ -352,12 +352,13 @@ BroadcastReceiver.
This can work with services running in the same process as \c QtActivity and even
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
For more information, see
\l{Calling QML/C++ Functions from Java Code}.
\endomit //! Qt Android Extras not part of Qt 6.0
\omit //! Qt Android Extras not part of Qt 6.0
\section2 Using Android BroadcastReceiver
\l {Android: BroadcastReceiver}{Android BroadcastReceiver} enables exchanging
@ -424,17 +425,14 @@ an then register the broadcast receiver by calling the method
\c registerServiceBroadcastReceiver():
\code
QAndroidJniEnvironment env;
QJniEnvironment env;
jclass javaClass = env.findClass("org/qtproject/example/qtandroidservice/ActivityUtils");
QAndroidJniObject classObject(javaClass);
QJniObject classObject(javaClass);
classObject.callMethod<void>("registerServiceBroadcastReceiver",
"(Landroid/content/Context;)V",
QtAndroid::androidContext().object());
\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
@ -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
information, see \l{Use the same .so Lib File}.
\endomit //! Qt Remote Objects not part of Qt 6.0
\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}
and \l{Qt NFC}{NFC}-enabled devices.
\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.
\endomit //! Qt Android Extras not part of Qt 6.0
\li Develop secure applications using OpenSSL library.
\omit //! Not part of Qt 6.0
\li Create \l{Android Services}.
\endomit //! Not part of Qt 6.0
\li Create and deploy Application Package (APK) and Android App Bundle (AAB)
packages using Qt Creator.
\endlist

View File

@ -59,26 +59,6 @@
\li \l{Qt for Android - Building from Source}
\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
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}
)
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)
target_link_libraries(photosurface PUBLIC
Qt::Widgets

View File

@ -64,22 +64,6 @@
#include <QtCore/QMimeDatabase>
#include <QtCore/QStandardPaths>
#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()
{
@ -104,10 +88,12 @@ int main(int argc, char* argv[])
#else
QGuiApplication app(argc, argv);
#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;
#endif
}
QQuickWindow::setDefaultAlphaBuffer(true);
QCoreApplication::setApplicationName(QStringLiteral("Photosurface"));

View File

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