QAndroidBinder Class

Wraps the most important methods of Android Binder class. More...

Header: #include <QtCore/private/qandroidextras_p.h>
qmake: QT += core-private
Since: Qt 6.2
Status: Preliminary

This class is under development and is subject to change.

Public Types

enum class CallType { Normal, OneWay }

Public Functions

QAndroidBinder()
QAndroidBinder(const QJniObject &binder)
QJniObject handle() const
virtual bool onTransact(int code, const QAndroidParcel &data, const QAndroidParcel &reply, QAndroidBinder::CallType flags)
bool transact(int code, const QAndroidParcel &data, QAndroidParcel *reply = nullptr, QAndroidBinder::CallType flags = CallType::Normal) const

Detailed Description

The QAndroidBinder is a convenience class that wraps the most important Android Binder methods.

When building with CMake, use the following commands to use private Qt Core APIs:

find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::CorePrivate)

Member Type Documentation

enum class QAndroidBinder::CallType

This enum is used with QAndroidBinder::transact() to describe the mode in which the IPC call is performed.

ConstantValueDescription
QAndroidBinder::CallType::Normal0normal IPC, meaning that the caller waits the result from the callee
QAndroidBinder::CallType::OneWay1one-way IPC, meaning that the caller returns immediately, without waiting for a result from the callee

Member Function Documentation

[explicit] QAndroidBinder::QAndroidBinder()

Creates a new object which can be used to perform IPC.

See also onTransact and transact.

QAndroidBinder::QAndroidBinder(const QJniObject &binder)

Creates a new object from the binder Java object.

See also transact.

QJniObject QAndroidBinder::handle() const

The return value is useful to call other Java API which are not covered by this wrapper

[virtual] bool QAndroidBinder::onTransact(int code, const QAndroidParcel &data, const QAndroidParcel &reply, QAndroidBinder::CallType flags)

Default implementation is a stub that returns false. The user should override this method to get the transact data from the caller.

The code is the action to perform. The data is the marshaled data sent by the caller.
The reply is the marshaled data to be sent to the caller.
The flags are the additional operation flags.

Warning: This method is called from Binder's thread which is different from the thread that this object was created.

See also transact.

bool QAndroidBinder::transact(int code, const QAndroidParcel &data, QAndroidParcel *reply = nullptr, QAndroidBinder::CallType flags = CallType::Normal) const

Performs an IPC call

The code is the action to perform. Should be between FIRST_CALL_TRANSACTION and LAST_CALL_TRANSACTION.
The data is the marshaled data to send to the target.
The reply (if specified) is the marshaled data to be received from the target. May be nullptr if you are not interested in the return value.
The flags are the additional operation flags.

Returns true on success

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.