QAndroidBinder Class
封装 Android Binder 类最重要的方法。更多
头文件: | #include <QtCore/private/qandroidextras_p.h> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) 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)
从binder Java 对象创建新对象。
另请参阅 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
© 2025 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.