QAndroidBinder Class
封装了 Android Binder 类中最重要的方法。更多内容...
| 头文件: | #include <QtCore/private/qandroidextras_p.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS CorePrivate) target_link_libraries(mytarget PRIVATE Qt6::CorePrivate) |
| qmake: | QT += core-private |
| 自: | Qt 6.2 |
| 状态: | 技术预览 |
该类处于技术预览阶段,内容可能会有变动。
公共类型
| enum class | CallType { Normal, OneWay } |
公共函数
| 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 |
详细说明
QAndroidBinder 是一个便利类,封装了最重要的Android Binder方法。
成员类型文档
enum class QAndroidBinder::CallType
该枚举与QAndroidBinder::transact() 配合使用,用于描述执行 IPC 调用的模式。
| 常量 | 值 | 描述 |
|---|---|---|
QAndroidBinder::CallType::Normal | 0 | 正常 IPC,即调用方等待被调用方的结果 |
QAndroidBinder::CallType::OneWay | 1 | 单向 IPC,即调用方立即返回,不等待被调用方的结果 |
成员函数文档
[explicit] QAndroidBinder::QAndroidBinder()
创建一个可用于执行进程间通信(IPC)的新对象。
另请参阅 onTransact 和transact 。
QAndroidBinder::QAndroidBinder(const QJniObject &binder)
根据 Java 对象 `binder ` 创建一个新对象。
另请参阅 transact 。
QJniObject QAndroidBinder::handle() const
该返回值可用于调用本封装类未涵盖的其他 Java API
[virtual] bool QAndroidBinder::onTransact(int code, const QAndroidParcel &data, const QAndroidParcel &reply, QAndroidBinder::CallType flags)
默认实现是一个返回 false 的存根方法。用户应重写此方法,以从调用方获取事务数据。
code 是要执行的操作。data 是调用方发送的经过序列化的数据。
The reply is the marshaled data to be sent to the caller.
The flags are the additional operation flags.
警告:此 方法是在 Binder 线程中调用的,该线程与创建此对象的线程不同。
另请参阅 transact 。
bool QAndroidBinder::transact(int code, const QAndroidParcel &data, QAndroidParcel *reply = nullptr, QAndroidBinder::CallType flags = CallType::Normal) const
执行一次 IPC 调用
code 是待执行的操作。该时间段应在FIRST_CALL_TRANSACTION和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.
成功时返回 true
© 2026 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.