智能客服
你问我答,随时在线为你解决问题

























AgentHostProxy用于从AgentExtensionAbility服务端向客户端发送数据或安全认证请求。
- import { common } from '@kit.AbilityKit';
sendData(data: string): void
从AgentExtensionAbility服务端给客户端发送数据。
元服务API:从 API version 24开始,该接口支持在元服务中使用。
系统能力:SystemCapability.Ability.AgentRuntime.Core
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| data | string | 是 | 待发送到AgentExtensionAbility客户端的数据。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 35600002 | Failed to send the IPC message. |
示例:
- import { common, AgentExtensionAbility } from '@kit.AbilityKit';
- import { BusinessError } from '@kit.BasicServicesKit';
-
- const TAG: string = '[AgentExtensionAbility] ';
-
- export default class MyAgentExtensionAbility extends AgentExtensionAbility {
- // 数据发送处理
- onData(proxy: common.AgentHostProxy, data: string) {
- console.info(TAG + `onData ${data}`);
- try {
- // 发送数据到AgentExtensionAbility的客户端
- proxy.sendData('Hello Client');
- } catch (err) {
- let code = (err as BusinessError).code;
- let msg = (err as BusinessError).message;
- console.error(`${TAG} sendData failed, err code: ${code}, err msg: ${msg}.`);
- }
- }
- }
authorize(handshakeData: string): void
从AgentExtensionAbility服务端给客户端发送安全认证请求。
元服务API:从 API version 24开始,该接口支持在元服务中使用。
系统能力:SystemCapability.Ability.AgentRuntime.Core
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| handshakeData | string | 是 | 待发送到客户端的安全认证数据。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 35600002 | Failed to send the IPC message. |
示例:
- import { common, AgentExtensionAbility } from '@kit.AbilityKit';
- import { BusinessError } from '@kit.BasicServicesKit';
-
- const TAG: string = '[AgentExtensionAbility] ';
-
- export default class MyAgentExtensionAbility extends AgentExtensionAbility {
- // 安全认证处理
- onAuth(proxy: common.AgentHostProxy, handshakeData: string) {
- console.info(TAG + `onAuth ${handshakeData}`);
- try {
- // 发送认证数据到AgentExtensionAbility的客户端
- proxy.authorize('handshake_token');
- } catch (err) {
- let code = (err as BusinessError).code;
- let msg = (err as BusinessError).message;
- console.error(`${TAG} authorize failed, err code: ${code}, err msg: ${msg}.`);
- }
- }
- }
智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功