• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# UIServiceHostProxy (System API)
2
3UIServiceHostProxy functions as a proxy to send data from the [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md) server to the client.
4
5
6> **NOTE**
7>
8>  - The initial APIs of this module are supported since API version 14. Newly added APIs will be marked with a superscript to indicate their earliest API version.
9>  - The APIs of this module can be used only in the stage model.
10>  - The APIs of this module must be used in the main thread, but not in sub-threads such as Worker and TaskPool.
11>  - The APIs provided by this module are system APIs.
12
13## Modules to Import
14
15```ts
16import { common } from '@kit.AbilityKit';
17```
18
19
20## UIServiceHostProxy.sendData
21
22sendData(data: Record\<string, Object>): void
23
24Sends data from the [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md) server to the client.
25
26**System capability**: SystemCapability.Ability.AbilityRuntime.Core
27
28**System API**: This is a system API.
29
30**Parameters**
31
32| Name| Type| Read Only| Optional| Description|
33| -------- | -------- | -------- | -------- | -------- |
34| data | Record\<string, Object> | Yes| No| Data to be sent to the [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md) client.|
35
36**Error codes**
37
38For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
39
40| ID| Error Message|
41| ------- | -------------------------------- |
42| 202 | Not System App. Interface caller is not a system app .                                                       |
43| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
44| 16000050 | Internal error. |
45
46**Example**
47
48```ts
49import { common, UIServiceExtensionAbility } from '@kit.AbilityKit';
50
51const TAG: string = '[UiServiceExtensionAbility] ';
52
53export default class MyUiServiceExtensionAbility extends UIServiceExtensionAbility {
54
55  // Process data sending.
56  onData(proxy: common.UIServiceHostProxy, data: Record<string, Object>) {
57    console.log(TAG + `onData ${JSON.stringify(data)}`);
58    // Define the data to be sent.
59    let formData: Record<string, string> = {
60      'proxyData': 'proxyData'
61    };
62    try {
63      // Send data to the UIServiceExtensionAbility server.
64      proxy.sendData(formData);
65    } catch (err) {
66      console.log(TAG + `sendData failed ${JSON.stringify(err.message)}`);
67    }
68  }
69}
70```
71