summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeena Miettinen <riitta-leena.miettinen@qt.io>2020-04-07 16:46:21 +0200
committerAssam Boudjelthia <assam.boudjelthia@qt.io>2020-04-16 16:53:43 +0300
commit313b7e45d129cf82482bd30eddccc2271abda37d (patch)
treeb1936be5df8862577f6c054fee20d47323b2dafa
parent4ba6e29bea36910cdc510d7b6c98c8b8ab393ef1 (diff)
downloadqtdoc-313b7e45d129cf82482bd30eddccc2271abda37d.tar.gz
Android: update out-dated docs
Many Qt for Android pages are out-dated or have wrong content, thus requiring a big update for many pages... Task-number: QTBUG-80390 Change-Id: I1c432d5cf9866d67e108882d3e41955385108e18 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
-rw-r--r--doc/src/external-resources.qdoc92
-rw-r--r--doc/src/platforms/android/android-building.qdoc29
-rw-r--r--doc/src/platforms/android/android-openssl-support.qdoc157
-rw-r--r--doc/src/platforms/android/android-platform-notes.qdoc4
-rw-r--r--doc/src/platforms/android/android-publishing-to-googleplay.qdoc2
-rw-r--r--doc/src/platforms/android/android-services.qdoc507
-rw-r--r--doc/src/platforms/android/android.qdoc198
-rw-r--r--doc/src/platforms/android/examples-android.qdoc61
-rw-r--r--doc/src/platforms/android/porting-to-android.qdoc82
-rw-r--r--doc/src/platforms/supported-platforms.qdocinc11
10 files changed, 906 insertions, 237 deletions
diff --git a/doc/src/external-resources.qdoc b/doc/src/external-resources.qdoc
index dad8eaf7..fcc8ef72 100644
--- a/doc/src/external-resources.qdoc
+++ b/doc/src/external-resources.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@@ -187,6 +187,74 @@
\title Android: App Manifest
*/
/*!
+ \externalpage http://developer.android.com/sdk/index.html
+ \title Android: The Android SDK Tools
+*/
+/*!
+ \externalpage http://developer.android.com/tools/sdk/ndk/index.html
+ \title Android: The Android NDK
+*/
+/*!
+ \externalpage https://developer.android.com/studio/index.html
+ \title Android: Android Studio
+*/
+/*!
+ \externalpage https://developer.android.com/studio/command-line/sdkmanager
+ \title Android: sdkmanager
+*/
+/*!
+ \externalpage https://developer.android.com/studio/run/emulator
+ \title Android: Android Emulator
+*/
+/*!
+ \externalpage http://developer.android.com/tools/help/adb.html
+ \title Android: adb
+*/
+/*!
+ \externalpage https://developer.android.com/reference/android/app/Service
+ \title Android: Service
+*/
+/*!
+ \externalpage https://developer.android.com/reference/android/content/Intent
+ \title Android: Intent
+*/
+/*!
+ \externalpage https://developer.android.com/reference/android/content/Context#startService(android.content.Intent)
+ \title Android: startService()
+*/
+/*!
+ \externalpage https://developer.android.com/reference/android/content/BroadcastReceiver
+ \title Android: BroadcastReceiver
+*/
+/*!
+ \externalpage https://developer.android.com/reference/android/content/Context#sendBroadcast(android.content.Intent)
+ \title Android: sendBroadcast()
+*/
+/*!
+ \externalpage https://developer.android.com/reference/android/os/Binder.html
+ \title Android: Binder
+*/
+/*!
+ \externalpage https://bugreports.qt.io/browse/QTBUG-81461
+ \title QTBUG-81461
+*/
+/*!
+ \externalpage http://strawberryperl.com
+ \title Perl
+*/
+/*!
+ \externalpage https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
+ \title Java SE Development Kit
+*/
+/*!
+ \externalpage http://openjdk.java.net
+ \title OpenJDK
+*/
+/*!
+ \externalpage http://www.gradle.org
+ \title Gradle
+*/
+/*!
\externalpage https://qtcloudservices.com/
\title Qt Cloud Services
*/
@@ -194,12 +262,18 @@
\externalpage http://doc.qt.io/qtcreator/creator-configuring.html
\title Configuring Qt Creator
*/
-
/*!
\externalpage http://doc.qt.io/qtcreator/creator-deploying-android.html#specifying-settings-for-packages
- \title Android APK
+ \title Qt Creator: Specifying Settings for Packages
+*/
+/*!
+ \externalpage http://doc.qt.io/qtcreator/creator-developing-android.html#specifying-android-device-settings
+ \title Qt Creator: Specifying Android Device Settings
+*/
+/*!
+ \externalpage http://doc.qt.io/qtcreator/creator-deploying-android.html#managing-android-skd-packages
+ \title Qt Creator: Managing Android SDK Packages
*/
-
/*!
\externalpage http://doc.qt.io/qtcreator/creator-build-example-application.html
\title Building and Running Example
@@ -219,6 +293,16 @@
*/
/*!
+ \externalpage https://github.com/KDAB/android_openssl
+ \title OpenSSL for Android
+*/
+
+/*!
+ \externalpage http://www.openssl.org/source
+ \title OpenSSL Source
+*/
+
+/*!
\externalpage https://codereview.qt-project.org/#/admin/projects/qt/qthttp
\title Qt HTTP
*/
diff --git a/doc/src/platforms/android/android-building.qdoc b/doc/src/platforms/android/android-building.qdoc
index 3180dbc2..1a002a46 100644
--- a/doc/src/platforms/android/android-building.qdoc
+++ b/doc/src/platforms/android/android-building.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@@ -64,19 +64,19 @@
\section2 Manual Installation
\list 1
- \li Download Android Studio from \l{https://developer.android.com/studio/index.html}.
+ \li Download \l {Android: Android Studio}{Android Studio}.
\li Open Android Studio and run the SDK Manager tool from
\uicontrol{Tools > Android > SDK Manager}. If this toolbar isn't visible, you can
enable it from the \uicontrol View menu: select \uicontrol Toolbar.
- \li Download the Android NDK from \l{https://developer.android.com/tools/sdk/ndk/index.html}.
+ \li Download \l{Android: The Android NDK}{Android NDK}.
\note As of Qt 5.12, Android NDK r18 is required and gcc toolchains are no longer
supported.
\li Ensure that the NDK supports the API level you're targeting. To verify, check your
\e{path_to_NDK/platforms} directory.
\note As of Qt 5.13, any API level >= 21 is sufficient.
\li Install a JDK with a version of 1.6 or newer from
- \l{https://www.oracle.com/technetwork/java/javase/downloads/index.html}. Alternatively, you
- can use OpenJDK.
+ \l{Java SE Development Kit}. Alternatively, you can
+ use \l {OpenJDK}.
\code
apt-get install openjdk-8-jdk
\endcode
@@ -149,22 +149,17 @@
\section2 Step 1: Setting up the Development Environment
\list 1
- \li Install the latest Perl from \l{http://strawberryperl.com}. Then, select a destination
+ \li Install the latest \l {Perl}, and then select a destination
folder, also known as \c{PERL_ROOT}.
\li Set up the MinGW toolchain by downloading a pre-built Qt package for MinGW, and then
- add it to your \c PATH, for example: \c{C:\dev\Qt\Tools\mingw730_64\bin}.
- \li Install the latest JDK from
- \l{https://www.oracle.com/technetwork/java/javase/downloads/index.html}. Then, add the
- \e{<JDK_ROOT>} to \c PATH.
+ add it to your \c PATH. For example: \c{C:\dev\Qt\Tools\mingw730_64\bin}.
+ \li Install JDK and add \e{<JDK_ROOT>} to \c PATH.
Alternatively, if you've installed Android Studio, you can use the JDK that's
included in your installation's \c jre folder.
- \li Install the Android NDK, r18b, from
- \l{https://developer.android.com/tools/sdk/ndk/index.html}. Extract it to
- \e{<ANDROID_NDK_PATH>}.
- \li Install the latest Android SDK (tools only) from
- \l{http://developer.android.com/sdk/index.html}. Run the Android SDK Manager and install
- the latest version of "SDK Platform", "Google APIs", and "build-tools" in
- \e{<ANDROID_SDK_PATH>}.
+ \li Install the Android NDK, r18b, and extract it to \e{<ANDROID_NDK_PATH>}.
+ \li Install the latest Android SDK (tools only). Run the Android SDK Manager
+ and install the latest version of "SDK Platform", "Google APIs", and
+ "build-tools" into \e{<ANDROID_SDK_PATH>}.
\li Open the \c cmd.exe window and verify that:
\list
\li \c{where gcc.exe} lists \e{<MINGW_ROOT>.exe} first before \e{<PERL_ROOT>.exe}.
diff --git a/doc/src/platforms/android/android-openssl-support.qdoc b/doc/src/platforms/android/android-openssl-support.qdoc
index 249c04f6..66c226bc 100644
--- a/doc/src/platforms/android/android-openssl-support.qdoc
+++ b/doc/src/platforms/android/android-openssl-support.qdoc
@@ -33,60 +33,135 @@
The Qt installation package comes with OpenSSL support but the OpenSSL libraries
are not part of the package due to legal restrictions in some countries. If your
application depends on OpenSSL, consider packaging the SSL libraries with your
-Application Package (APK) as the target device may or may not have them. You
-can use the \l{QSslSocket::supportsSsl()} static function to check for SSL
-support on the target.
+Application Package (APK) as the target device may or may not have them.
+
+You can use the \l {QSslSocket::supportsSsl()} static function to check for SSL
+support on the target device. First include the header:
+\code
+#include <QSslSocket>
+\endcode
+
+Then use the following line to check if SSL is supported:
+\code
+qDebug() << "Device supports OpenSSL: " << QSslSocket::supportsSsl();
+\endcode
+
+Check Qt Creator's \c {Application Output} section or the Android \c logcat for
+the result.
+
+\section1 Building OpenSSL for Android
+
+A convenient Github repository with prebuilt and a build script can be used
+without the need for manual step-by-step build. For more information, see
+\l {OpenSSL for Android}. If you download the repository, you can then skip
+to \l {Using OpenSSL Libraries with Qt for Android}.
+
+The following instructions guide you to build the OpenSSL libraries manually:
-The following instructions guide you to build and add the OpenSSL libraries to
-the APK:
\list 1
- \li Download the latest OpenSSL 1.1.x sources from \l{http://www.openssl.org/source}.
+ \li Download \l{OpenSSL Source}{OpenSSL} 1.1.x sources.
+
+ \li Extract the sources to a folder and navigate to that folder using
+ the CLI.
+ \note If your development platform is Windows, you need \c msys with
+ \c perl v5.14 or later to build OpenSSL.
- \li Extract the sources to a folder and navigate to that folder using
- the CLI.
- \note If your development platform is Windows, you need \c msys with
- \c perl v5.14 or later to build OpenSSL.
+ \li Add the Android LLVM toolchain (NDK r20b or r21) to your path:
- \li Add android llvm toolchain to your path:
- \badcode
- export PATH="<android_ndk_path>/toolchains/llvm/prebuilt/<host>/bin":$PATH
- \endcode
+ \badcode
+ export PATH="<android_ndk_path>/toolchains/llvm/prebuilt/<host>/bin":$PATH
+ \endcode
- \li Configure the OpenSSL sources to build for Android using
- the following command:
+ \li Configure the OpenSSL sources to build for Android using
+ the following command:
- \badcode
- ./Configure shared android-<arch> -D__ANDROID_API__=21
- \endcode
+ \badcode
+ ./Configure shared android-<arch> -D__ANDROID_API__=21
+ \endcode
- \note You must consider enabling/disabling the SSL features based on the
- legal restrictions in the region where your application is available.
- See the \l{OpenSSL Configure Options}{SSL configure options} for details about
- the configurable features.
+ Where <arch> can take a value of: \c arm, \c arm64, \c x86, \c x86_64.
- \li Run \c{make SHLIB_VERSION_NUMBER= SHLIB_EXT=_1_1.so build_libs} to
- build \c libcrypto and \c libssl shared libraries that are not versioned,
- but with a \e _1_1 suffix. If you want to use a different suffix, then you must
- set the \c ANDROID_OPENSSL_SUFFIX environment variable before you access the
- Qt Network API. Without a suffix, Android 5 (API 21) will load the system
- libraries \e libcrypto.so and \e libssl.so, which are OpenSSL 1.0, rather than
- your libraries.
+ \note You must consider enabling or disabling the SSL features based on
+ the legal restrictions in the region where your application is available.
+ For more information about the configurable features, see
+ \l{OpenSSL Configure Options}.
- \note Android does not load versioned libraries.
+ \li To build \c libcrypto and \c libssl shared libraries that are not versioned,
+ but with an \e _1_1 suffix, run:
- \li Open your Qt project using Qt Creator and update the "Build Android APK"
- settings to add \e libcrypto and \e libssl as additional libraries for
- your project.
+ \code
+ make -j$(nproc) SHLIB_VERSION_NUMBER= SHLIB_EXT=_1_1.so build_libs
+ \endcode
- \li Run your application to see it running on the device.
+ Without a suffix, Android 5 (API 21) will load the system libraries
+ \e {libcrypto.so} and \e {libssl.so}, which are OpenSSL 1.0, rather than
+ your libraries.
+
+ If you want to use a different suffix, you must change \c SHLIB_EXT in
+ the previous command, and set the \c ANDROID_OPENSSL_SUFFIX environment
+ variable before you access the Qt Network API.
+
+ \badcode
+ make -j$(nproc) SHLIB_VERSION_NUMBER= SHLIB_EXT=<custom_suffix>.so build_libs
+ \endcode
+
+ Then set the environment variable in your main.ccp file:
+
+ \code
+ qputenv("ANDROID_OPENSSL_SUFFIX", "<custom_suffix>");
+ \endcode
+
+ \note Android does not load versioned libraries.
\endlist
-\note here \l{https://github.com/KDAB/android_openssl} you can find a script which
-can be used to compile openssl for all android abis and also latest prebuilt libs.
+\section1 Using OpenSSL Libraries with Qt for Android
-Qt Creator builds your application and creates an application package (APK)
-with the OpenSSL libraries bundled in it. Once the APK is ready, it uses \c adb
-to deploy the APK on the target you chose and launch the application.
+Depending on the method you obtained the OpenSSL libraries, you can use one of
+the following step to include those libraries in your project:
-*/
+\list
+ \li Using the project files:
+
+ Using the convenience \l {OpenSSL for Android} repository,
+ you can directly add the include projects into your own project, by adding
+ the following to your \c {.pro} file:
+
+ \badcode
+ android: include(<path/to/android_openssl/openssl.pri)
+ \endcode
+
+ Or if using CMake, add the following to your \c {CMakeLists.txt}:
+
+ \badcode
+ if (ANDROID)
+ include(<path/to/android_openssl/CMakeLists.txt)
+ endif()
+ \endcode
+
+ Alternatively, you can either use the Qt for Android variable ANDROID_EXTRA_LIBS to add
+ extra libraries, mainly \c libcrypto and \c libssl. For QMake use:
+
+ \badcode
+ ANDROID_EXTRA_LIBS += \
+ <path_to_libs_dir>/libcrypto_1_1.so \
+ <path_to_libs_dir>/libssl_1_1.so
+ \endcode
+
+ For CMake:
+
+ \badcode
+ set(ANDROID_EXTRA_LIBS
+ <path_to_libs_dir>/ibcrypto_1_1.so
+ <path_to_libs_dir>/libssl_1_1.so
+ CACHE INTERNAL "")
+ \endcode
+
+ \note When targeting multiple architectures, include OpenSSL libraries
+ for all the targeted architectures.
+
+ \li Using Qt Creator, it is possible to add extra libraries. For more
+ information, see \l {Qt Creator: Adding Libraries to Projects}.
+\endlist
+
+*/
diff --git a/doc/src/platforms/android/android-platform-notes.qdoc b/doc/src/platforms/android/android-platform-notes.qdoc
index 32fab8e9..5314c411 100644
--- a/doc/src/platforms/android/android-platform-notes.qdoc
+++ b/doc/src/platforms/android/android-platform-notes.qdoc
@@ -34,8 +34,6 @@
and running them on the \l{Qt for Android}{Android} platform. Qt supports
Android versions 4.1 (API level 16) or later.
- \tableofcontents
-
\section1 Android Development in Qt Creator
The easiest way to develop with Qt for Android is to use
@@ -183,7 +181,7 @@
\row
\li ANDROID_NDK_HOST
\li Specifies the host for which the toolchain was built.
- For example, \c{linux-x86_64} for Linux, \c{windows{} for Windows, and
+ For example, \c{linux-x86_64} for Linux, \c{windows} for Windows, and
\c{darwin-x86_64} for macOS.
\note This variable is detected automatically. Normally, you don't have to change
it.
diff --git a/doc/src/platforms/android/android-publishing-to-googleplay.qdoc b/doc/src/platforms/android/android-publishing-to-googleplay.qdoc
index ff1bdf07..0535573d 100644
--- a/doc/src/platforms/android/android-publishing-to-googleplay.qdoc
+++ b/doc/src/platforms/android/android-publishing-to-googleplay.qdoc
@@ -74,7 +74,7 @@ on Google Play:
\li Set up a \uicontrol keystore to sign the \e .apk. You can create a new
keystore if you do not have one. For more details, see
- \l{Android APK}{QtCreator: Specifying Settings for Packages}.
+ \l{Qt Creator: Specifying Settings for Packages}{Specifying Settings for Packages in Qt Creator}.
\li Select \uicontrol{Open package location after build} and run your
application to build the \e .apk. Qt Creator builds the \e .apk and opens the
diff --git a/doc/src/platforms/android/android-services.qdoc b/doc/src/platforms/android/android-services.qdoc
index dbc008ba..65564c02 100644
--- a/doc/src/platforms/android/android-services.qdoc
+++ b/doc/src/platforms/android/android-services.qdoc
@@ -1,4 +1,4 @@
-/****************************************************************************
+/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
@@ -36,29 +36,500 @@ useful to perform long-term operations such as logging GPS, waiting for social
media notifications, and so on. A service will continue to run even if the
application that started it exits.
-To create a service, do the following steps:
-\list 1
- \li Uncomment the service part of your \c AndroidManifest.xml.
+\section1 Assemble the Service
- \li Make sure the \c service tag contains an \c android:process=":some_name"
- attribute. It is needed to force the \c service to run in a separate
- process than the \c activity.
+To get started, create an Android package directory as instructed in
+\l{Qt Creator: Deploying Applications to Android Devices}. This directory
+contains the \c AndroidManifest.xml file. Inside the package directory,
+create a \c src directory, where all your Java packages and classes
+will be created.
- \li If you're using the same application (.so file) for activity and also
- for service, you need to use \c android.app.arguments \c meta-data to
- pass some arguments to your \c main function in order to know which one
- is which.
+\section2 Create the Service Class
- \li To enable background running, uncomment \c android.app.background_running
- \c meta-data and set it to true (\c android:value="true" ).
+You can create a service by extending the class \c QtService or
+\l{Android: Service} to your Java class. Depending on whether you want to use
+Qt features in your service or call native C++ functions from Java, you need to
+extend either \c QtService or \c Service. Let's start with a simple service,
+as follows:
+\code
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+import org.qtproject.qt5.android.bindings.QtService;
+
+public class QtAndroidService extends QtService
+{
+ private static final String TAG = "QtAndroidService";
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ Log.i(TAG, "Creating Service");
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ Log.i(TAG, "Destroying Service");
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ int ret = super.onStartCommand(intent, flags, startId);
+
+ // Do some work
+
+ return ret;
+ }
+}
+\endcode
+
+\section2 Start the Service
+
+Android allows starting services on demand or at boot time. You can do both using
+Qt as well.
+
+\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
+ \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(
+ "startService",
+ "(Landroid/content/Intent;)Landroid/content/ComponentName;",
+ serviceIntent.handle().object());
+ \endcode
+
+ \li Start the service by calling a Java method. The easiest way is to create
+ a static method in your service class:
+
+ \code
+ public static void startQtAndroidService(Context context) {
+ context.startService(new Intent(context, QtAndroidService.class));
+ }
+ \endcode
+
+ The you can call it from C++ using the following JNI call:
+
+ \code
+ QAndroidJniObject::callStaticMethod<void>(
+ "org/qtproject/example/qtandroidservice/QtAndroidService",
+ "startQtAndroidService",
+ "(Landroid/content/Context;)V",
+ QtAndroid::androidActivity().object());
+ \endcode
\endlist
+\section3 Start a Service At Boot Time
+
+To run a service at boot time, you need a \l{Android: BroadcastReceiver}
+{BroadcastReceiver}.
+
+Create a custom Java class:
+
+\code
+public class QtBootServiceBroadcastReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Intent startServiceIntent = new Intent(context, QtBootServiceBroadcastReceiver.class);
+ context.startService(startServiceIntent);
+ }
+}
+\endcode
+
+Add the following \c uses-permission in the body of the \c <manifest> section in
+the \c AndroidManifest.xml file:
+
+\badcode
+<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+\endcode
+
+Also, add the \c receiver definition in the body of the \c <application> section:
+
+\badcode
+<receiver android:name=".QtBootServiceBroadcastReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ </intent-filter>
+</receiver>
+\endcode
+
+\note To run a service at boot time, it has to be defined as a separate process,
+see \l{Service in Separate Process}.
+
+\section2 Manage the Service in AndroidMnifest.xml
+
+For the service to be usable in an Android app, you must declare it in the
+\c AndroidManifest.xml file. Let's start with adding the service section:
+
+\list
+ \li When extending \c Service, just declare the service section as a normal Android
+ service. Add the following inside the \c <application> section:
+
+ \badcode
+ <service android:name=".QtAndroidService">
+ <!-- Background running -->
+ <meta-data android:name="android.app.background_running" android:value="true"/>
+ <!-- Background running -->
+ </service>
+ \endcode
+
+ This way the service will start in the same process as \c QtActivity,
+ which allows you to use native C++ calls from Java code. You can run it
+ in a separate process but that way you cannot use any native calls for
+ communication because the Qt libraries are not loaded for that process.
+ To run on separate process, add this to the service tag:
+
+ \badcode
+ android:process=":qt_service"
+ \endcode
+
+ \target Extending QtActivity AndroidManifest.xml
+ \li When extending \c QtService, you need to declare other items for loading
+ all the necessary libs required for Qt, mainly the same items as in
+ \c <activity> section for \c QtActivity. Add the following:
+
+ \badcode
+ <service android:process=":qt_service" android:name=".QtAndroidService">
+
+ <meta-data android:name="android.app.lib_name" android:value="service"/>
+ <meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
+ <meta-data android:name="android.app.repository" android:value="default"/>
+ <meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
+ <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
+
+ <!-- Deploy Qt libs as part of package -->
+ <meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
+
+ <!-- Run with local libs -->
+ <meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
+ <meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
+ <meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
+ <meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
+ <meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
+ <!-- Run with local libs -->
+
+ <!-- Background running -->
+ <meta-data android:name="android.app.background_running" android:value="true"/>
+ <!-- Background running -->
+ </service>
+ \endcode
+\endlist
+
+\note Make sure to define the following to run the service in the background:
+
+\badcode
+<meta-data android:name="android.app.background_running" android:value="true"/>
+\endcode
+
+There are a few variations on how to declare services. Some of them are already
+used in the previous manifest snippet. Depending on your use case, run the
+service either in the same process as QtActivity or in a separate process.
+
+\section3 Service in the Same Process as QtActivity
+
+To run a service in the same process as QtActivity, declare the service header
+as follows:
+
+\badcode
+<service android:name=".QtAndroidService">
+\endcode
+
+\section3 Service in Separate Process
+
+To run a service in a dedicated process, declare the service header as follows:
+
+\badcode
+<service android:process=":qt_service" android:name=".QtAndroidService">
+\endcode
+
Qt loads the \c .so file defined in \c android.app.lib_name \c meta-data,
-and calls the \c main function with all the arguments set in
-\c android.app.arguments \c meta-data.
+and calls the \c main() function with all the arguments set in
+\c android.app.arguments \c meta-data. When running in a separate process, you
+can start the service using either the same lib file as the main activity or
+a separate lib file.
-See \l{http://developer.android.com/guide/components/services.html}{Android Services}
-documentation for more information.
-*/
+\section4 Use the Same .so Lib File
+
+Using the same \c .so lib file as the main activity means the service
+will use the same entry point with an extra argument to distinguish
+it from the main activity. You can handle your application's
+execution in the \c main() function according the arguments provided.
+Add the following argument declaration to your service body:
+
+\badcode
+<!-- Application arguments -->
+<meta-data android:name="android.app.arguments" android:value="-service"/>
+<!-- Application arguments -->
+\endcode
+
+Then make sure the service \c android.app.lib_name is the same as
+the main activity, add the following:
+
+\badcode
+<meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
+\endcode
+
+When using the same \c .so lib file, your application's \c main() function
+is executed two times, one to start the main activity and the second time
+to start the service. Thus, you have to handle each execution according
+to the provided argument. One way to acheive that is as follows:
+
+\code
+if (argc <= 1) {
+ // code to handle main activity execution
+} else if (argc > 1 && strcmp(argv[1], "-service") == 0) {
+ qDebug() << "Service starting with from the same .so file";
+ QAndroidService app(argc, argv);
+ return app.exec();
+} else {
+ qWarning() << "Unrecognized command line argument";
+ return -1;
+}
+\endcode
+
+\section4 Use a Separate .so Lib File
+
+In this case, you need to have a sub-project with a \c lib template that
+provides a different executable for the service. A sample project \c .pro is:
+
+\badcode
+TEMPLATE = lib
+TARGET = service
+CONFIG += dll
+QT += core androidextras
+SOURCES += \
+ service_main.cpp
+
+HEADERS += servicemessenger.h
+\endcode
+
+In the \c service_main.cpp you could have the following:
+
+\code
+#include <QDebug>
+#include <QAndroidService>
+
+int main(int argc, char *argv[])
+{
+ qWarning() << "Service starting from a separate .so file";
+ QAndroidService app(argc, argv);
+
+ return app.exec();
+}
+\endcode
+
+Define the \c android.app.lib_name for the service in the \c AndroidManifest.xml:
+
+\badcode
+<meta-data android:name="android.app.lib_name" android:value="service"/>
+\endcode
+
+\section1 Communication with the Service
+
+Qt for Android offers a variety of inter-process communication (IPC) methods to
+communicate with Android Services. Depending on the structure of your project,
+you can use either native C++ calls from Java Service or Android
+BroadcastReceiver.
+
+\section2 Native C++ Calls from Java Service
+
+This can work with services running in the same process as \c QtActivity and even
+if \c Service is extended. For more information, see
+\l{Calling QML/C++ Functions from Java Code}.
+
+\section2 Using Android BroadcastReceiver
+
+\l {Android: BroadcastReceiver}{Android BroadcastReceiver} enables exchanging
+messages between the Android system, apps, activities and services. Similarly
+to other Android features, Qt can use broadcast receivers to exchange messages
+between \c QtActivity and your service. Let's start with logic to send a message
+from your service. Add the following in your service implementation, which calls
+\l{Android: sendBroadcast()}{sendBroadcast()}:
+
+\code
+@Override
+public int onStartCommand(Intent intent, int flags, int startId) {
+ int ret = super.onStartCommand(intent, flags, startId);
+
+ Intent sendToUiIntent = new Intent();
+ sendToUiIntent.setAction(ActivityUtils.BROADCAST_CUSTOM_ACTION);
+ sendToUiIntent.putExtra("message", "simple_string");
+
+ Log.i(TAG, "Service sending broadcast");
+ sendBroadcast(sendToUiIntent);
+
+ return ret;
+}
+\endcode
+
+Then, you need to create and register the broadcast receiver from
+the Qt's main activity. The easiest way is to create a custom class with a method
+and implement all that logic in Java. In the following example, the service sends
+a message \c "simple_string" to Qt by calling the native method \c sendToQt():
+
+\code
+public class ServiceBroadcastUtils {
+
+ private static native void sendToQt(String message);
+
+ private static final String TAG = "ActivityUtils";
+ public static final String BROADCAST_CUSTOM_ACTION = "org.qtproject.example.qtandroidservice.broadcast.custom";
+
+ public void registerServiceBroadcastReceiver(Context context) {
+ IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(BROADCAST_CUSTOM_ACTION);
+ context.registerReceiver(serviceMessageReceiver, intentFilter);
+ Log.i(TAG, "Registered broadcast receiver");
+ }
+
+ private BroadcastReceiver serviceMessageReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.i(TAG, "In OnReceive()");
+ if (BROADCAST_CUSTOM_ACTION.equals(intent.getAction())) {
+ String message = intent.getStringExtra("message");
+ sendToQt(data);
+ Log.i(TAG, "Service sent back message to C++: " + message);
+ }
+ }
+ };
+}
+\endcode
+
+For more information on working with native calls, see
+\l{Calling QML/C++ Functions from Java Code}.
+
+To make use of all that, start your service as shown in \l{Start the Service},
+an then register the broadcast receiver by calling the method
+\c registerServiceBroadcastReceiver():
+
+\code
+QAndroidJniEnvironment env;
+jclass javaClass = env.findClass("org/qtproject/example/qtandroidservice/ActivityUtils");
+QAndroidJniObject classObject(javaClass);
+
+classObject.callMethod<void>("registerServiceBroadcastReceiver",
+ "(Landroid/content/Context;)V",
+ QtAndroid::androidContext().object());
+\endcode
+
+For more information, see the examples \l{Android Service with BroadcastReceiver},
+and \l{Android Service with BroadcastReceiver - Same Lib File}.
+
+\section2 Using Qt Remote Objects
+
+\l{Getting Started with Qt Remote Objects}{Qt Remote Objects} offers an easy way
+to share APIs between Qt processes. The main concept is to server in the service
+process, and have a replica in the Qt application, then those two parts are able
+to exchange data between each other, using signals and slots.
+
+\section3 Prepare the replica
+Let's consider a service example with separate \c .so lib file. Define a
+\c .rep file which defines our communication class:
+
+\code
+class ServiceMessenger {
+ SLOT(void ping(const QString &message));
+ SIGNAL(pong(const QString &message));
+}
+\endcode
+
+The define the class in the service sub-project as \c servicemessenger.h:
+
+\code
+#include "rep_servicemessenger_source.h"
+
+class ServiceMessenger : public ServiceMessengerSource {
+public slots:
+ void ping(const QString &name) override {
+ emit pong("Hello " + name);
+ }
+};
+\endcode
+
+Then, add the \c .rep file to both the main application and service \c .pro files,
+in the main application:
+
+\badcode
+QT += remoteobjects
+REPC_REPLICA += servicemessenger.rep
+\endcode
+
+And in the service sub-project:
+
+\badcode
+QT += remoteobjects
+REPC_SOURCE += servicemessenger.rep
+\endcode
+
+\section3 Connect the source and replica
+
+Define the Qt Remote Objects source node in the service sub-project's \c main()
+function:
+
+\code
+#include "servicemessenger.h"
+
+#include <QDebug>
+#include <QAndroidService>
+
+int main(int argc, char *argv[])
+{
+ qWarning() << "QtAndroidService starting from separate .so";
+ QAndroidService app(argc, argv);
+
+ QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:replica")));
+ ServiceMessenger serviceMessenger;
+ srcNode.enableRemoting(&serviceMessenger);
+
+ return app.exec();
+}
+\endcode
+
+Then, in the application's \c main() function, connect to source node:
+
+\code
+QRemoteObjectNode repNode;
+repNode.connectToNode(QUrl(QStringLiteral("local:replica")));
+QSharedPointer<ServiceMessengerReplica> rep(repNode.acquire<ServiceMessengerReplica>());
+bool res = rep->waitForSource();
+Q_ASSERT(res);
+
+QObject::connect(rep.data(), &ServiceMessengerReplica::pong, [](const QString &message){
+ qDebug() << "Service sent: " << message;
+});
+rep->ping("Qt and Android are friends!");
+\endcode
+
+This example sends a message from the main application's process to the
+service. The service replies with the same message, which is printed
+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}.
+
+For more information, see the examples \l{Android Service with Qt Remote Objects},
+and \l{Android Service with Qt Remote Objects - Same Lib File}.
+
+\section2 Using QAndroidBinder
+
+While using \l{QtRemoteObjects}{Qt Remote Objects} for communication is a
+cross-platform solution, \l QAndroidBinder Class Reference} is Android specific.
+\l QAndroidBinder is a convenience class that implements the most important
+methods in \l{Android: Binder}.
+It allows sending \l{QByteArray} or \l{QVariant} objcets between processes.
+For more information on how to use it with an Android Service, see
+\l{Android Service with QAndroidBinder}{Android Service with QAndroidBinder Example}.
+
+*/
diff --git a/doc/src/platforms/android/android.qdoc b/doc/src/platforms/android/android.qdoc
index 050c98ef..513d7cb1 100644
--- a/doc/src/platforms/android/android.qdoc
+++ b/doc/src/platforms/android/android.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@@ -32,49 +32,54 @@
\ingroup supportedplatform
Qt for Android enables you to run Qt 5 applications on Android devices.
-All Qt modules (essential and add-on) are supported except Qt \WebEngine,
-Qt Serial Port, and the platform-specific ones (Qt Mac Extras,
-Qt Windows Extras, and Qt X11 Extras).
+All Qt modules (essentials and add-ons) are supported except the following:
+
+\list
+ \li Qt WebEngine
+ \li Qt Serial Port
+ \li Qt Virtual Keyboard
+ \li Platform-specific extras: Qt Mac Extras, Qt Windows Extras, and
+ Qt X11 Extras
+\endlist
The following configurations are supported:
\include supported-platforms.qdocinc android
-\br
The following list summarizes what you can do with Qt for Android:
\list
- \li Run \l{Qt Widgets}{Widget} and
- \l{QML Applications}{QML} applications on the device
- or emulator.
- \li Support for native \l{Android Style}{Android style} with
- Qt Quick Controls.
- \li Handle \l{Qt Multimedia}{Multimedia} content in your Qt Quick 2
- applications.
- \li Get \l{Qt Sensors}{sensor} readings and react to the changes.
- \li Retrieve current position data using satellite and network
- information.
- \li Connect and exchange data with \l{Qt Bluetooth}{Bluetooth}
- and \l{Qt NFC}{NFC}-enabled devices.
- \li Integrate Java code into your application using
- \l{Qt Android Extras}.
- \li Develop secure applications using OpenSSL library.
- \li Create \l{Android Services}
- \li Create and deploy Application Package using Qt Creator.
+ \li Run \l{Qt Widgets}{Widget-based} and \l{QML Applications}{QML}
+ applications on a device or an emulator.
+ \li Support for the \l{Material Style}{Material Style} with
+ Qt Quick Controls.
+ \li Handle \l{Qt Multimedia}{Multimedia} content in your
+ Qt Quick 2 applications.
+ \li Get \l{Qt Sensors}{sensor} readings.
+ \li Retrieve positioning data using satellite or network information.
+ \li Connect and exchange data with \l{Qt Bluetooth}{Bluetooth}
+ and \l{Qt NFC}{NFC}-enabled devices.
+ \li Integrate Java code into your application using \l{Qt Android Extras}.
+ \li Develop secure applications using OpenSSL library.
+ \li Create \l{Android Services}.
+ \li Create and deploy Application Package (APK) and Android App Bundle (AAB)
+ packages using Qt Creator.
\endlist
The following topics provide more details about how to use Qt for Android:
\list
\li \l{Getting Started with Qt for Android}{Getting Started}
- \li \l{Qt for Android - Building from Source}
\li \l{Porting to Android}{Porting a Qt Application}
- \li \l{Qt for Android Examples}{Examples}
+ \li \l{Qt for Android Examples}{Qt Examples on Android}
+ \li \l{Deploying an Application on Android}
+ \li \l{Qt Creator: Deploying Applications to Android Devices}
\li \l{Adding OpenSSL Support for Android}
\li \l{Android Services}{Creating Android Services}
- \li \l{Third-party Android Libraries}{Including third-party Android libraries in an application}
- \li \l{Qt Creator: Deploying Applications to Android Devices}{Deploying to the Device}
+ \li \l{Third-party Android Libraries}
+ {Including third-party Android libraries in an application}
\li \l{Publishing to Google Play}
\li \l{Platform and Compiler Notes - Android}{Platform Notes}
+ \li \l{Qt for Android - Building from Source}
\li \l{Android GNU C++ run-time licensing}
\endlist
*/
@@ -89,40 +94,69 @@ The following topics provide more details about how to use Qt for Android:
In order to use \l{Qt for Android}, you need the following:
\list
-\li \l{http://developer.android.com/sdk/index.html}{The Android SDK Tools}
- \note If your Qt version is earlier than v5.9, use the SDK tools package
- v25.2.5 or earlier.
-\li \l{http://developer.android.com/tools/sdk/ndk/index.html}{The Android NDK}
- \list
- \li Qt 5.11 and below
- \list
- \li NDK r10e
- \li GCC toolchain
- \endlist
- \li Qt 5.12.0 to 5.12.5
- and Qt 5.13.0 to 5.13.1
+ \li \l {Java SE Development Kit} (JDK) or \l{ OpenJDK} (on Linux)
+ version 6 up to 8. Versions higher than 8 might cause issues for
+ \l {android-sdk}{the Android SDK command-line tools}.
+
+ \li \l{Gradle} for building application packages (APK) and app bundles
+ (AAB) for Android devices. Gradle is delivered with Qt 5.9, and later.
+ Because Gradle scripts are not delivered with Android SDK tools since
+ version 26.0.0, they are delivered with Qt 5.9 and 5.6.3.
+
+ \note Using Ant to build APKs is no longer supported.
+
+ \target android-sdk
+ \li \l{Android: The Android SDK Tools}{The Android SDK Tools}
+ to install the following packages that are required to compile Qt
+ applications for Android:
+
\list
- \li NDK r19c
- \li \e android-clang
+ \li Platform tools
+ \li Build tools
+ \li At least one SDK platform
+ \li \l {android-ndk}{The Android NDK}, which contains toolchains
+ and debuggers for Android.
\endlist
- \li Qt 5.14+, Qt 5.13.2+
- and Qt 5.12.6+
+
+ \note Qt Creator 4.12 or later can set up the SDK Tools, NDK, and
+ essential packages automatically. For more information, see
+ \l {Qt Creator: Specifying Android Device Settings}.
+
+ \note If your Qt version is earlier than v5.9, use the SDK tools package
+ v25.2.5 or earlier.
+
+ \target android-ndk
+ \li \l{Android: The Android NDK}{The Android NDK}
+ can be installed using the \c sdkmanager tool. Alternatively, you can
+ download it and extract it manually to a path of your choosing.
+ Different Qt versions depend on different NDK versions, as listed below:
+
\list
- \li NDK r20b or r21
- \li \e android-clang
- \li \note Qt 5.14.0 and 5.14.1 with NDK r21 have a bug fixed at \l{https://bugreports.qt.io/browse/QTBUG-81461}{QTBUG-81461}.
+ \li Qt 5.14.0 or later, Qt 5.13.2 or later, and Qt 5.12.6 or later
+ \list
+ \li NDK r20b or r21
+ \li \e android-clang
+ \li \note Qt 5.14.0 and 5.14.1 with NDK r21 have a bug fixed at
+ \l {QTBUG-81461}.
+ \endlist
+ \li Qt 5.12.0 to 5.12.5 and Qt 5.13.0 to 5.13.1
+ \list
+ \li NDK r19c
+ \li \e android-clang
+ \endlist
+ \li Qt 5.11 and below
+ \list
+ \li NDK r10e
+ \li GCC toolchain
+ \endlist
\endlist
- \endlist
-
-\li \l{http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html}{Java SE Development Kit} (JDK) v6 or later. You can also use \l{http://openjdk.java.net}{OpenJDK} on Linux.
\endlist
-After installing these tools, update the Android SDK by installing the API
-and build tools packages required for development. You can install these packages
-either through Android Studio or using the command line tools package you installed
-earlier. For more details, refer to the
-\l{https://developer.android.com/studio/intro/update.html}{Android Studio}
-documentation.
+After installing the SDK tools, update the Android SDK, and then
+install the essential packages using \l {Android: Android Studio}
+{Android Studio}, the Qt Creator \l {Qt Creator: Managing Android SDK Packages}
+{SDK Manager UI}, or the \l {Android: sdkmanager}{sdkmanager} command
+line tool.
\note Make sure to unpack the Android SDK and NDK to a writeable location that Qt Creator
can access later. Otherwise, Qt Creator won't be able to use \c sdkmanager or find all
@@ -130,46 +164,40 @@ components even if they were installed manually.
\section2 Updating the Android SDK
-The command line tools provided by the Android SDK Tools package also enables updating
-the SDK, but without a GUI. For example, the following command on Ubuntu updates the SDK
-by installing the latest \c build-tools, \c platform-tools, \c emulator, and \c patcher
-packages:
+Use the \c sdkmanager command line tool to update the packages list and then
+install the essential packages:
\badcode
-./bin/sdkmanager --update
+cd <ANDROID_SDK_ROOT>/tools/bin/
+./sdkmanager --update
+./sdkmanager --install "platform-tools" "platforms;android-29" "build-tools;29.0.2" "ndk-bundle"
\endcode
-To install a specific package, use \c sdkmanager from
-\c{<ANDROID_SDK_ROOT>/tools/bin}. For example, the following command installs the
-\c android-10 platforms package on Ubuntu:
+To use the \l {Android: Android Emulator}{Android Emulator}, install it by
+entering:
\badcode
-./sdkmanager "platforms;android-10"
+./sdkmanager --install "emulator" "patcher;v4"
\endcode
-For more details, refer to the
-\l{https://developer.android.com/studio/command-line/sdkmanager.html}{sdkmanager}
-documentation.
-
-\section1 Configuring Your Development Host
+\section1 Host Specific Configuration
\section2 Windows
The default USB driver on Windows does not allow debugging using
Android Debug Bridge (ADB) tool. You must install the additional USB driver
-provided by the \e extras Android SDK package. Use the following command from
-the Windows command prompt to install the extras package:
+provided by the \e extras Android SDK package. To install it, run the following:
\badcode
-sdkmanager.bat "extras;google;usb_driver"
+sdkmanager.bat --install "extras;google;usb_driver"
\endcode
After the package installation is complete, install the driver from
\c{<ANDROID_SDK_ROOT>/extras/google/usb_driver}. Try running a few basic
-\l{http://developer.android.com/tools/help/adb.html}{adb} commands now
-and check whether your Android device responds to it.
+\l{Android: adb}{adb} commands now and check whether your Android device
+responds to them.
-\section2 64-bit Linux
+\section2 Linux 64-bit
If you're developing on a 64-bit Linux machine, you must install the
following dependencies in order to run 32-bit executables like \c adb, which
@@ -179,27 +207,23 @@ allows Qt Creator to find devices to deploy to:
sudo apt-get install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386
\endcode
-To run the emulator, the following dependencies are also necessary:
+\target emulator dependencies
+To run the Android emulator, the following dependencies are also necessary:
-\code
+\badcode
sudo apt-get install libsdl1.2debian:i386
\endcode
\section2 Qt Creator IDE
-The Qt Creator IDE that came with the Qt 5 installation on your development
-host, must be configured to enable developing applications for Android. Launch
-Qt Creator and select \uicontrol Tools > \uicontrol Options >
-\uicontrol Devices > \uicontrol Android to add the Android NDK and SDK paths.
-For more details, refer to \l{Qt Creator: Connecting Android Devices}{Qt Creator Manual}.
+The Qt Creator IDE can be used to develop Qt applications for Android. For more
+information, see \l{Qt Creator: Connecting Android Devices}.
\section1 Testing Your Setup
-Now you can test your development setup by running the examples that came
-with the Qt 5 installation. You can browse these examples in
-Qt Creator \uicontrol Welcome mode. Use the \c android filter in the search
-field to list all the examples tested on Android.
+Now you can test your development setup by running the examples shipped with the
+Qt installation. For more information, see \l {Qt for Android Examples}.
-To develop a simple application from scratch, see \l{Creating a Mobile Application}.
+To develop a simple application from scratch, see
+\l {Qt Creator: Creating a Mobile Application}.
*/
-
diff --git a/doc/src/platforms/android/examples-android.qdoc b/doc/src/platforms/android/examples-android.qdoc
index 4faa63a0..2b147909 100644
--- a/doc/src/platforms/android/examples-android.qdoc
+++ b/doc/src/platforms/android/examples-android.qdoc
@@ -30,40 +30,49 @@
\title Qt for Android Examples
\brief A list of selected Qt Examples for Android.
- This page lists Qt Examples known to work for \l{Qt for Android}{Android}.
- This page is not an exclusive list, meaning most
- \l{Qt Examples and Tutorials}{Qt Examples} are compatible with Android but
- are not listed here.
+ This page lists Qt examples that have been tested to run on
+ \l{Qt for Android}{Android}. However, most \l{Qt Examples and Tutorials}
+ {Qt Examples} can be run on Android even though they are not listed here.
\section1 Running the Examples
- To run the examples from \l{Qt Creator Manual}{Qt Creator}, open the \gui
- Welcome mode and select the example from \gui Examples. Entering the search
- term \gui Android filters these examples from the other \l{Qt Examples and
- Tutorials}{Qt Examples}. For more information, visit
- \l{Qt Creator: Building and Running an Example}{Building and Running an Example}.
+ To run examples from \l{Qt Creator Manual}{Qt Creator}, select \uicontrol
+ Welcome > \uicontrol Examples, and then select an installed Qt for Android
+ to filter the examples that have been tested to run on Android. For more
+ information, see \l{Qt Creator: Building and Running an Example}
+ {Building and Running an Example}.
\section1 Essentials
- These examples and tutorials give instructions on how to get started
- as well as information related to Qt for Android.
+ The following sections describe how to get started with developing
+ applications for Android:
\list
- \li \l{Getting Started with Qt for Android}{Getting Started}
- \li \l{Qt Creator: Creating a Mobile Application}{Creating a Mobile Application}
- \li \l{Qt Creator: Deploying Applications to Android Devices}{Deploying to the Device}
- \li \l{Porting to Android}{Porting a Qt Application}
- \li \l{Publishing to Google Play}
- \li \l{Adding OpenSSL Support for Android}
- \li \l{Building Qt 5 for Android}{Building from Sources}
- \li \l{Qt Notifier} - demonstrates how to call Java code from an Android application
+ \li \l{Getting Started with Qt for Android}
+ \li \l{Qt Creator: Creating a Mobile Application}
+ \li \l{Qt Creator: Deploying Applications to Android Devices}
+ \li \l{Publishing to Google Play}
+ \li \l{Porting to Android}
+ \li \l{Adding OpenSSL Support for Android}
+ \li \l{Qt for Android - Building from Source}
+ \endlist
+
+ \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 using 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 NJI calls.
\endlist
\section1 Qt Quick and QML Examples for Android
- These are a list of Qt Quick and QML examples for Android. For a full list
- of Qt Quick examples including beginner-level tutorials, visit
- \l{Qt Quick Examples and Tutorials}.
+ The following Qt Quick and QML examples are useful when developing
+ applications for Android. For a full list of Qt Quick examples
+ including beginner-level tutorials, see \l{Qt Quick Examples and Tutorials}.
\div {class="multi-column"}
\div {class="doc-column"}
@@ -123,5 +132,13 @@
\li \l{QML Camera Example}{Camera Example}
\endlist
\enddiv
+ \div {class="doc-column"}
+ \b{Location}
+ \list
+ \li \l{Map Viewer (QML)}{Map Viewer Example}
+ \li \l{Places Map (QML)}{Places Map Example}
+ \li \l{Plane Spotter (QML)}{Plane Spotter Example}
+ \endlist
+ \enddiv
\enddiv
*/
diff --git a/doc/src/platforms/android/porting-to-android.qdoc b/doc/src/platforms/android/porting-to-android.qdoc
index 27149b86..7bba94af 100644
--- a/doc/src/platforms/android/porting-to-android.qdoc
+++ b/doc/src/platforms/android/porting-to-android.qdoc
@@ -30,59 +30,65 @@
\title Porting to Android
\brief Provides instructions to port your existing Qt application to Android.
-In this section, we are going to port an existing Qt Application to
-\l{Qt for Android}{Android} and deploy it to the device.
-
Most Qt applications should be portable to Android with ease, unless they
depend on a specific hardware or software feature not supported by Android.
-If your application is not using any such feature, deployment is probably the
-only step that demands some changes to your application.
+If your application is not using any such feature, deployment is the only step
+that might demands some changes to your application.
\include porting-notes.qdocinc using resources
The other approach is to deploy the resources into the package's \c{assets}
directory. It is the best option if you want to achieve better
interoperability with the Android APIs. You can access all resources in the
-directory using the "assets:" prefix. Unlike qrc, this approach is not a
-cross-platform solution.
+directory using the "assets:" prefix. Unlike qrc, this approach is Android
+sepcific, not a cross-platform solution.
+
+To use the "assets:" approach, for example, add the following lines into the
+\c {.pro} file:
+
+\badcode
+android {
+ assets.files = images/happy.png
+ assets.path = /assets/images/
+ INSTALLS += assets
+}
+\endcode
+
+Then you can access that image asset from C++ as follows:
+
+\code
+QImage image("assets:/images/happy.png");
+\endcode
The following step-by-step instructions guide you to port an existing Qt Quick
application to Android using the qrc approach:
\list 1
- \li Open the existing project in Qt Creator and configure it
- with "Android for ARM" kit. For more information, see
- \l{Qt Creator: Configuring Projects}
- \li Identify all the resources used by your application and add them to one
- or more qrc files.
- Qt Creator updates your qmake project file with the "RESOURCES"
- variable listing the qrc files you added.
- \li To load or refer to the resources in the qrc file from your C++ code,
- use the "qrc:" scheme followed by the absolute URL. For example, to
- load the \c{main.qml} file from \c{resources.qrc}, you can use the
- following C++ code:
+ \li Open your project in Qt Creator and select an Android kit. For more
+ information, see \l{Qt Creator: Configuring Projects}{Configuring Projects in Qt Creator}.
+ \li Identify all the resources used by your application and add them to one
+ or more qrc files. Qt Creator updates your qmake project file with the
+ "RESOURCES" variable listing the qrc files you added.
+ \li To load or refer to the resources in the qrc file from your C++ code,
+ use the "qrc:" scheme followed by the absolute URL. For example, to
+ load the \c{main.qml} file from \c{resources.qrc}, you can use the
+ following C++ code:
- \code
- QQuickView viewer;
- viewer.setSource(QUrl("qrc:/qml/main.qml"));
- viewer.show();
- \endcode
+ \code
+ QQuickView viewer;
+ viewer.setSource(QUrl("qrc:/qml/main.qml"));
+ viewer.show();
+ \endcode
- \note QML documents can refer to the contents in qrc files using the
- relative path to the document. Such references do not require the
- "\c{qrc:}" or "\c{:/}" prefix.
- \li Save the changes to your project and run the application.
+ \note QML documents can refer to the contents in qrc files using the
+ relative path to the document. Such references do not require the
+ "\c{qrc:}" or "\c{:/}" prefix.
+ \li Deploy your application to a device or AVD. For more information, see
+ \l {Qt Creator: Deploying Applications to Android Devices}.
\endlist
-\note Qt Quick Controls in the application will use native
-\l{Android Style}{Android style} if the target device is running
-Android 3.0 (API 11) or later. The application should function normally on
-devices with Android versions earlier than v3.0, but without native style for
-controls.
-
-Qt Creator deploys your application on the Android device, if the
-device is detected by the PC. Otherwise, it tries to run the application on an
-AVD (Android Virtual Device). You will be prompted to create one if there are no
-AVDs found.
+\note Qt Quick Controls will use the \l{Material Style}{Material Style} if the
+target device is running Android 3.0 (API 11) or later. The application should
+function normally on devices with Android versions earlier than v3.0, but
+without native style for controls.
*/
-
diff --git a/doc/src/platforms/supported-platforms.qdocinc b/doc/src/platforms/supported-platforms.qdocinc
index d688dda1..ca9b3669 100644
--- a/doc/src/platforms/supported-platforms.qdocinc
+++ b/doc/src/platforms/supported-platforms.qdocinc
@@ -96,12 +96,11 @@
\section2 \l{Qt for Android}{Android}
//! [android]
\table 80%
- \header \li Platform Version \li Architecture \li Compiler \li Build Environment
- \row \li Android 5.0 or later (that is, API Level 21 and up)
- \li \c armv7a and \c x86, \c arm64-v8 and \c x86_64
- \li \b {Clang as provided by Google}, \b {MinGW 7.3}
- \li \b {RHEL 7.x (x86_64)}, \b{\macos 10.13}, \b {Windows 10 (x86_64)},
- \b Windows 7
+ \header \li Distribution \li Architecture \li Compiler \li Notes
+ \row \li Android 5.0 or later (API level 21 or higher)
+ \li \c armv7a, \c x86, \c arm64-v8, and \c x86_64
+ \li \b {Clang 9.0.8 (NDK r21) and Clang 8.0.7 (NDK r20b) as provided by Google}, \b {MinGW 7.3}
+ \li
\endtable
//! [android]