Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QtAndroidPrivate Namespace Reference

\preliminary \inmodule QtCorePrivate More...

Classes

class  ActivityResultListener
 
class  GenericMotionEventListener
 
class  KeyEventListener
 
class  NewIntentListener
 
class  OnBindListener
 
class  ResumePauseListener
 

Enumerations

enum class  BindFlag {
  None = 0x00000000 , AutoCreate = 0x00000001 , DebugUnbind = 0x00000002 , NotForeground = 0x00000004 ,
  AboveClient = 0x00000008 , AllowOomManagement = 0x00000010 , WaivePriority = 0x00000020 , Important = 0x00000040 ,
  AdjustWithActivity = 0x00000080 , ExternalService = -2147483648
}
 

Functions

Q_CORE_EXPORT QtJniTypes::Activity activity ()
 
Q_CORE_EXPORT QtJniTypes::Service service ()
 
Q_CORE_EXPORT QtJniTypes::Context context ()
 
Q_CORE_EXPORT JavaVM * javaVM ()
 
Q_CORE_EXPORT jint initJNI (JavaVM *vm, JNIEnv *env)
 
Q_CORE_EXPORT jclass findClass (const char *className, JNIEnv *env)
 
jobject classLoader ()
 
Q_CORE_EXPORT jint androidSdkVersion ()
 
bool registerPermissionNatives ()
 
bool registerNativeInterfaceNatives ()
 Posts the function runnable to the Android thread.
 
Q_CORE_EXPORT void handleActivityResult (jint requestCode, jint resultCode, jobject data)
 
Q_CORE_EXPORT void registerActivityResultListener (ActivityResultListener *listener)
 
Q_CORE_EXPORT void unregisterActivityResultListener (ActivityResultListener *listener)
 
Q_CORE_EXPORT void handleNewIntent (JNIEnv *env, jobject intent)
 
Q_CORE_EXPORT void registerNewIntentListener (NewIntentListener *listener)
 
Q_CORE_EXPORT void unregisterNewIntentListener (NewIntentListener *listener)
 
Q_CORE_EXPORT void handlePause ()
 
Q_CORE_EXPORT void handleResume ()
 
Q_CORE_EXPORT void registerResumePauseListener (ResumePauseListener *listener)
 
Q_CORE_EXPORT void unregisterResumePauseListener (ResumePauseListener *listener)
 
Q_CORE_EXPORT void registerGenericMotionEventListener (GenericMotionEventListener *listener)
 
Q_CORE_EXPORT void unregisterGenericMotionEventListener (GenericMotionEventListener *listener)
 
Q_CORE_EXPORT void registerKeyEventListener (KeyEventListener *listener)
 
Q_CORE_EXPORT void unregisterKeyEventListener (KeyEventListener *listener)
 
Q_CORE_EXPORT void waitForServiceSetup ()
 
Q_CORE_EXPORT int acuqireServiceSetup (int flags)
 
Q_CORE_EXPORT void setOnBindListener (OnBindListener *listener)
 
Q_CORE_EXPORT jobject callOnBindListener (jobject intent)
 
Q_CORE_EXPORT bool acquireAndroidDeadlockProtector ()
 
Q_CORE_EXPORT void releaseAndroidDeadlockProtector ()
 
Q_CORE_EXPORT void startIntentSender (const QJniObject &intentSender, int receiverRequestCode, QAndroidActivityResultReceiver *resultReceiver=nullptr)
 
Q_CORE_EXPORT void startActivity (const QJniObject &intent, int receiverRequestCode, QAndroidActivityResultReceiver *resultReceiver=nullptr)
 
Q_CORE_EXPORT void startActivity (const QAndroidIntent &intent, int receiverRequestCode, QAndroidActivityResultReceiver *resultReceiver=nullptr)
 
Q_CORE_EXPORT void startActivity (const QJniObject &intent, int receiverRequestCode, std::function< void(int, int, const QJniObject &data)> callbackFunc)
 
Q_CORE_EXPORT bool bindService (const QAndroidIntent &serviceIntent, const QAndroidServiceConnection &serviceConnection, BindFlags flags=BindFlag::None)
 

Detailed Description

\preliminary \inmodule QtCorePrivate

Since
6.2

The QtAndroidPrivate namespace provides miscellaneous functions to aid Android development. \inheaderfile QtCore/private/qandroidextras_p.h

qtcoreprivate-usage

Enumeration Type Documentation

◆ BindFlag

enum class QtAndroidPrivate::BindFlag
strong
Since
6.2

This enum is used with QtAndroidPrivate::bindService to describe the mode in which the binding is performed.

\value None No options. \value AutoCreate Automatically creates the service as long as the binding exist. See \l {https://developer.android.com/reference/android/content/Context.html#BIND_AUTO_CREATE} {BIND_AUTO_CREATE} documentation for more details. \value DebugUnbind Include debugging help for mismatched calls to unbind. See \l {https://developer.android.com/reference/android/content/Context.html#BIND_DEBUG_UNBIND} {BIND_DEBUG_UNBIND} documentation for more details. \value NotForeground Don't allow this binding to raise the target service's process to the foreground scheduling priority. See \l {https://developer.android.com/reference/android/content/Context.html#BIND_NOT_FOREGROUND} {BIND_NOT_FOREGROUND} documentation for more details. \value AboveClient Indicates that the client application binding to this service considers the service to be more important than the app itself. See \l {https://developer.android.com/reference/android/content/Context.html#BIND_ABOVE_CLIENT} {BIND_ABOVE_CLIENT} documentation for more details. \value AllowOomManagement Allow the process hosting the bound service to go through its normal memory management. See \l {https://developer.android.com/reference/android/content/Context.html#BIND_ALLOW_OOM_MANAGEMENT} {BIND_ALLOW_OOM_MANAGEMENT} documentation for more details. \value WaivePriority Don't impact the scheduling or memory management priority of the target service's hosting process. See \l {https://developer.android.com/reference/android/content/Context.html#BIND_WAIVE_PRIORITY} {BIND_WAIVE_PRIORITY} documentation for more details. \value Important This service is assigned a higher priority so that it is available to the client when needed. See \l {https://developer.android.com/reference/android/content/Context.html#BIND_IMPORTANT} {BIND_IMPORTANT} documentation for more details. \value AdjustWithActivity If binding from an activity, allow the target service's process importance to be raised based on whether the activity is visible to the user. See \l {https://developer.android.com/reference/android/content/Context.html#BIND_ADJUST_WITH_ACTIVITY} {BIND_ADJUST_WITH_ACTIVITY} documentation for more details. \value ExternalService The service being bound is an isolated, external service. See \l {https://developer.android.com/reference/android/content/Context.html#BIND_EXTERNAL_SERVICE} {BIND_EXTERNAL_SERVICE} documentation for more details.

Enumerator
None 
AutoCreate 
DebugUnbind 
NotForeground 
AboveClient 
AllowOomManagement 
WaivePriority 
Important 
AdjustWithActivity 
ExternalService 

Definition at line 208 of file qandroidextras_p.h.

Function Documentation

◆ acquireAndroidDeadlockProtector()

bool QtAndroidPrivate::acquireAndroidDeadlockProtector ( )

Definition at line 387 of file qjnihelpers.cpp.

References g_androidDeadlockProtector, and QBasicAtomicInteger< T >::testAndSetAcquire().

Referenced by AndroidDeadlockProtector::acquire(), and requestPermissionsInternal().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ activity()

QtJniTypes::Activity QtAndroidPrivate::activity ( )

Definition at line 294 of file qjnihelpers.cpp.

References g_jActivity.

Referenced by initJNI(), requestPermissionsInternal(), startActivity(), startActivity(), and startIntentSender().

+ Here is the caller graph for this function:

◆ acuqireServiceSetup()

int QtAndroidPrivate::acuqireServiceSetup ( int  flags)

Definition at line 363 of file qjnihelpers.cpp.

References g_serviceSetupLockers, and QBasicAtomicInteger< T >::ref().

+ Here is the call graph for this function:

◆ androidSdkVersion()

jint QtAndroidPrivate::androidSdkVersion ( )

Definition at line 326 of file qjnihelpers.cpp.

Referenced by nativeBluetoothPermission(), nativeLocationPermission(), QAndroidSystemLocale::query(), QtAndroidAccessibility::registerNatives(), registerPermissionNatives(), and requestPermissionsInternal().

+ Here is the caller graph for this function:

◆ bindService()

bool QtAndroidPrivate::bindService ( const QAndroidIntent serviceIntent,
const QAndroidServiceConnection serviceConnection,
BindFlags  flags = BindFlag::None 
)
Since
6.2

Binds the service given by serviceIntent, serviceConnection and flags. The serviceIntent object identifies the service to connect to. The serviceConnection is a listener that receives the information as the service is started and stopped.

Returns
true on success

See \l {https://developer.android.com/reference/android/content/Context.html#bindService%28android.content.Intent,%20android.content.ServiceConnection,%20int%29} {Android documentation} documentation for more details.

See also
QAndroidIntent, QAndroidServiceConnection, BindFlag

Definition at line 984 of file qandroidextras.cpp.

References context(), QAndroidServiceConnection::handle(), and QAndroidIntent::handle().

+ Here is the call graph for this function:

◆ callOnBindListener()

jobject QtAndroidPrivate::callOnBindListener ( jobject  intent)

Definition at line 377 of file qjnihelpers.cpp.

References g_onBindListener, g_onBindListenerMutex, lock, and QtAndroidPrivate::OnBindListener::onBind().

Referenced by onBind().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ classLoader()

jobject QtAndroidPrivate::classLoader ( )

Definition at line 321 of file qjnihelpers.cpp.

References g_jClassLoader.

Referenced by initJNI().

+ Here is the caller graph for this function:

◆ context()

QtJniTypes::Context QtAndroidPrivate::context ( )

Definition at line 305 of file qjnihelpers.cpp.

References g_jActivity, and g_jService.

Referenced by QAndroidPlatformServices::QAndroidPlatformServices(), and bindService().

+ Here is the caller graph for this function:

◆ findClass()

jclass QtAndroidPrivate::findClass ( const char *  className,
JNIEnv *  env 
)

Definition at line 508 of file qjniobject.cpp.

References className, QSet< T >::constEnd(), QSet< T >::constFind(), getCachedClass(), QSet< T >::insert(), it, QJniObjectPrivate::loadClass(), and QJniObjectPrivate::toBinaryEncClassName().

+ Here is the call graph for this function:

◆ handleActivityResult()

void QtAndroidPrivate::handleActivityResult ( jint  requestCode,
jint  resultCode,
jobject  data 
)

Definition at line 137 of file qjnihelpers.cpp.

References QList< T >::at(), i, mutex, and QList< T >::size().

Referenced by onActivityResult().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleNewIntent()

void QtAndroidPrivate::handleNewIntent ( JNIEnv *  env,
jobject  intent 
)

Definition at line 170 of file qjnihelpers.cpp.

References QList< T >::at(), i, mutex, and QList< T >::size().

Referenced by onNewIntent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handlePause()

void QtAndroidPrivate::handlePause ( )

Definition at line 203 of file qjnihelpers.cpp.

References QList< T >::at(), i, mutex, and QList< T >::size().

Referenced by QtAndroid::setAndroidPlatformIntegration(), and updateApplicationState().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleResume()

void QtAndroidPrivate::handleResume ( )

Definition at line 211 of file qjnihelpers.cpp.

References QList< T >::at(), i, mutex, and QList< T >::size().

Referenced by QtAndroid::setAndroidPlatformIntegration(), and updateApplicationState().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initJNI()

jint QtAndroidPrivate::initJNI ( JavaVM *  vm,
JNIEnv *  env 
)

Definition at line 219 of file qjnihelpers.cpp.

References activity(), classLoader(), dispatchGenericMotionEvent(), dispatchKeyEvent(), g_jActivity, g_javaVM, g_jClassLoader, g_jService, methods, registerNativeInterfaceNatives(), registerPermissionNatives(), service(), and updateNativeActivity().

Referenced by JNI_OnLoad().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ javaVM()

JavaVM * QtAndroidPrivate::javaVM ( )

Definition at line 316 of file qjnihelpers.cpp.

References g_javaVM.

Referenced by QJniEnvironmentPrivateTLS::~QJniEnvironmentPrivateTLS().

+ Here is the caller graph for this function:

◆ registerActivityResultListener()

void QtAndroidPrivate::registerActivityResultListener ( ActivityResultListener listener)

Definition at line 125 of file qjnihelpers.cpp.

References mutex.

Referenced by QAndroidActivityResultReceiver::QAndroidActivityResultReceiver(), and QtAndroidFileDialogHelper::QAndroidPlatformFileDialogHelper::show().

+ Here is the caller graph for this function:

◆ registerGenericMotionEventListener()

void QtAndroidPrivate::registerGenericMotionEventListener ( QtAndroidPrivate::GenericMotionEventListener listener)

Definition at line 334 of file qjnihelpers.cpp.

References mutex.

◆ registerKeyEventListener()

void QtAndroidPrivate::registerKeyEventListener ( QtAndroidPrivate::KeyEventListener listener)

Definition at line 346 of file qjnihelpers.cpp.

References mutex.

◆ registerNativeInterfaceNatives()

bool QtAndroidPrivate::registerNativeInterfaceNatives ( )

Posts the function runnable to the Android thread.

The function will be queued and executed on the Android UI thread. If the call is made on the Android UI thread runnable will be executed immediately. If the Android app is paused or the main Activity is null, runnable is added to the Android main thread's queue.

This call returns a QFuture<QVariant> which allows doing both synchronous and asynchronous calls, and can handle any return type. However, to get a result back from the QFuture::result(), QVariant::value() should be used.

If the runnable execution takes longer than the period of timeout, the blocking calls \l QFuture::waitForFinished() and \l QFuture::result() are ended once timeout has elapsed. However, if runnable has already started execution, it won't be cancelled.

The following example shows how to run an asynchronous call that expects a return type:

auto task = QNativeInterface::QAndroidApplication::runOnAndroidMainThread([=]() {
QJniObject surfaceView;
if (!surfaceView.isValid())
qDebug() << "SurfaceView object is not valid yet";
surfaceView = QJniObject("android/view/SurfaceView",
"(Landroid/content/Context;)V",
QNativeInterface::QAndroidApplication::context());
return QVariant::fromValue(surfaceView);
auto surfaceView = future.result().value<QJniObject>();
if (surfaceView.isValid())
qDebug() << "Retrieved SurfaceView object is valid";
});
\inmodule QtCore
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:531
#define qDebug
[1]
Definition qlogging.h:160
QFuture< void > future
[5]

The following example shows how to run a synchronous call with a void return type:

QNativeInterface::QAndroidApplication::runOnAndroidMainThread([]() {
QJniObject activity = QNativeInterface::QAndroidApplication::context();
// Hide system ui elements or go full screen
activity.callObjectMethod("getWindow", "()Landroid/view/Window;")
.callObjectMethod("getDecorView", "()Landroid/view/View;")
.callMethod<void>("setSystemUiVisibility", "(I)V", 0xffffffff);
Q_CORE_EXPORT QtJniTypes::Activity activity()
future waitForFinished()
Note
Becareful about the type of operations you do on the Android's main thread, as any long operation can block the app's UI rendering and input handling. If the function is expected to have long execution time, it's also good to use a \l QDeadlineTimer in your runnable to manage the execution and make sure it doesn't block the UI thread. Usually, any operation longer than 5 seconds might block the app's UI. For more information, see \l {Android: Keeping your app responsive}{Keeping your app responsive}.
Since
6.2

Definition at line 234 of file qandroidnativeinterface.cpp.

References methods, and qtNativeClassName.

Referenced by initJNI().

+ Here is the caller graph for this function:

◆ registerNewIntentListener()

void QtAndroidPrivate::registerNewIntentListener ( NewIntentListener listener)

Definition at line 158 of file qjnihelpers.cpp.

References mutex.

Referenced by QAndroidPlatformServices::QAndroidPlatformServices(), and QMainNfcNewIntentListener::QMainNfcNewIntentListener().

+ Here is the caller graph for this function:

◆ registerPermissionNatives()

bool QtAndroidPrivate::registerPermissionNatives ( )

Definition at line 1174 of file qandroidextras.cpp.

References androidSdkVersion(), methods, qtNativeClassName, and sendRequestPermissionsResult().

Referenced by initJNI().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerResumePauseListener()

void QtAndroidPrivate::registerResumePauseListener ( ResumePauseListener listener)

Definition at line 191 of file qjnihelpers.cpp.

References mutex.

Referenced by QMainNfcNewIntentListener::QMainNfcNewIntentListener().

+ Here is the caller graph for this function:

◆ releaseAndroidDeadlockProtector()

void QtAndroidPrivate::releaseAndroidDeadlockProtector ( )

Definition at line 392 of file qjnihelpers.cpp.

References g_androidDeadlockProtector, and QBasicAtomicInteger< T >::storeRelease().

Referenced by AndroidDeadlockProtector::~AndroidDeadlockProtector(), and sendRequestPermissionsResult().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ service()

QtJniTypes::Service QtAndroidPrivate::service ( )

Definition at line 300 of file qjnihelpers.cpp.

References g_jService.

Referenced by initJNI().

+ Here is the caller graph for this function:

◆ setOnBindListener()

void QtAndroidPrivate::setOnBindListener ( QtAndroidPrivate::OnBindListener listener)

Definition at line 369 of file qjnihelpers.cpp.

References QBasicAtomicInteger< T >::deref(), g_onBindListener, g_onBindListenerMutex, g_serviceSetupLockers, and lock.

+ Here is the call graph for this function:

◆ startActivity() [1/3]

void QtAndroidPrivate::startActivity ( const QAndroidIntent intent,
int  receiverRequestCode,
QAndroidActivityResultReceiver resultReceiver = nullptr 
)
Since
6.2

Starts the activity given by intent and provides the result asynchronously through the resultReceiver if this is non-null.

If resultReceiver is null, then the startActivity() method in the androidActivity() will be called. Otherwise startActivityForResult() will be called.

The receiverRequestCode is a request code unique to the resultReceiver, and will be returned along with the result, making it possible to use the same receiver for more than one intent.

Definition at line 902 of file qandroidextras.cpp.

References QAndroidIntent::handle(), and startActivity().

+ Here is the call graph for this function:

◆ startActivity() [2/3]

void QtAndroidPrivate::startActivity ( const QJniObject intent,
int  receiverRequestCode,
QAndroidActivityResultReceiver resultReceiver = nullptr 
)
Since
6.2

Starts the activity given by intent and provides the result asynchronously through the resultReceiver if this is non-null.

If resultReceiver is null, then the startActivity() method in the androidActivity() will be called. Otherwise startActivityForResult() will be called.

The receiverRequestCode is a request code unique to the resultReceiver, and will be returned along with the result, making it possible to use the same receiver for more than one intent.

Definition at line 869 of file qandroidextras.cpp.

References activity(), QAndroidActivityResultReceiverPrivate::get(), and QAndroidActivityResultReceiverPrivate::globalRequestCode().

Referenced by startActivity(), and startActivity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startActivity() [3/3]

void QtAndroidPrivate::startActivity ( const QJniObject intent,
int  receiverRequestCode,
std::function< void(int, int, const QJniObject &data)>  callbackFunc 
)
Since
6.2

Starts the activity given by intent, using the request code receiverRequestCode, and provides the result by calling callbackFunc.

Definition at line 915 of file qandroidextras.cpp.

References activity(), QAndroidActivityCallbackResultReceiver::instance(), QAndroidActivityCallbackResultReceiver::registerCallback(), and startActivity().

+ Here is the call graph for this function:

◆ startIntentSender()

void QtAndroidPrivate::startIntentSender ( const QJniObject intentSender,
int  receiverRequestCode,
QAndroidActivityResultReceiver resultReceiver = nullptr 
)
Since
6.2

Starts the activity given by intentSender and provides the result asynchronously through the resultReceiver if this is non-null.

If resultReceiver is null, then the startIntentSender() method in the androidActivity() will be called. Otherwise startIntentSenderForResult() will be called.

The receiverRequestCode is a request code unique to the resultReceiver, and will be returned along with the result, making it possible to use the same receiver for more than one intent.

Definition at line 939 of file qandroidextras.cpp.

References activity(), QAndroidActivityResultReceiverPrivate::get(), and QAndroidActivityResultReceiverPrivate::globalRequestCode().

+ Here is the call graph for this function:

◆ unregisterActivityResultListener()

void QtAndroidPrivate::unregisterActivityResultListener ( ActivityResultListener listener)

Definition at line 131 of file qjnihelpers.cpp.

References mutex.

Referenced by QAndroidActivityResultReceiver::~QAndroidActivityResultReceiver(), and QtAndroidFileDialogHelper::QAndroidPlatformFileDialogHelper::hide().

+ Here is the caller graph for this function:

◆ unregisterGenericMotionEventListener()

void QtAndroidPrivate::unregisterGenericMotionEventListener ( QtAndroidPrivate::GenericMotionEventListener listener)

Definition at line 340 of file qjnihelpers.cpp.

References mutex.

◆ unregisterKeyEventListener()

void QtAndroidPrivate::unregisterKeyEventListener ( QtAndroidPrivate::KeyEventListener listener)

Definition at line 352 of file qjnihelpers.cpp.

References mutex.

◆ unregisterNewIntentListener()

void QtAndroidPrivate::unregisterNewIntentListener ( NewIntentListener listener)

Definition at line 164 of file qjnihelpers.cpp.

References mutex.

Referenced by QMainNfcNewIntentListener::~QMainNfcNewIntentListener().

+ Here is the caller graph for this function:

◆ unregisterResumePauseListener()

void QtAndroidPrivate::unregisterResumePauseListener ( ResumePauseListener listener)

Definition at line 197 of file qjnihelpers.cpp.

References mutex.

Referenced by QMainNfcNewIntentListener::~QMainNfcNewIntentListener().

+ Here is the caller graph for this function:

◆ waitForServiceSetup()

void QtAndroidPrivate::waitForServiceSetup ( )

Definition at line 358 of file qjnihelpers.cpp.

Referenced by waitForServiceSetup().

+ Here is the caller graph for this function: