- Qt 6.8
- Qt Core
- C++ Classes
- QtCorePrivate
- QAndroidBinder
- Qt 6.8.1 Reference Documentation

# QAndroidBinder Class

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

Header: | `#include <QtCore/private/qandroidextras_p.h>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::CorePrivate)`
qmake: | `QT += core-private`
Since: | Qt 6.2
Status: | Preliminary

This class is under development and is subject to change.

- List of all members, including inherited members

## 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.

## 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.

Constant | Value | Description
--- | --- | ---
`QAndroidBinder::CallType::Normal` | `0` | normal IPC, meaning that the caller waits the result from the callee
`QAndroidBinder::CallType::OneWay` | `1` | one-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