js-apis-app-ability-wantAgent.md 59.1 KB
Newer Older
Z
zengyawen 已提交
1
# @ohos.app.ability.wantAgent (WantAgent模块)
D
donglin 已提交
2

Z
zhuhan 已提交
3
app.ability.WantAgent模块提供了创建WantAgent实例、获取实例的用户ID、获取want信息、比较WantAgent实例和获取bundle名称等能力。该模块将会取代[@ohos.wantAgent](js-apis-wantAgent.md)模块,建议优先使用本模块。
D
donglin 已提交
4 5 6 7 8 9 10

> **说明:**
> 
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。  

## 导入模块

Z
zhuhan 已提交
11
```ts
D
donglin 已提交
12 13 14 15 16 17 18
import WantAgent from '@ohos.app.ability.wantAgent';
```

## WantAgent.getWantAgent

getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void

F
fangJinliang1 已提交
19
创建WantAgent(callback形式)。 创建失败返回的WantAgent为空值。
D
donglin 已提交
20 21 22 23 24

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
25 26
| 参数名     | 类型                       | 必填 | 说明                    |
| -------- | -------------------------- | ---- | ----------------------- |
Z
zhuhan 已提交
27
| info     | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md)              | 是   | WantAgent信息。           |
D
fix  
donglin 已提交
28
| callback | AsyncCallback\<WantAgent\> | 是   | 创建WantAgent的回调方法。 |
D
donglin 已提交
29

Z
zhuhan 已提交
30
**错误码:**
Z
zhuhan 已提交
31
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
57 58
**示例:**

Z
zhuhan 已提交
59 60
```ts
//wantAgent对象
Z
zhuhan 已提交
61
let wantAgent;
D
donglin 已提交
62
//WantAgentInfo对象
Z
zhuhan 已提交
63
let wantAgentInfo = {
D
donglin 已提交
64 65
    wants: [
        {
Z
zhuhan 已提交
66
            deviceId: 'deviceId',
67 68
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
69 70 71 72
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
73 74 75 76
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
77 78
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
79
                mykey4: [false, true, false],
Z
zhuhan 已提交
80
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
81 82 83 84 85 86 87
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
88
};
D
donglin 已提交
89

Z
zhuhan 已提交
90 91
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
92
    if (err === undefined) {
Z
zhuhan 已提交
93 94
        wantAgent = data;
    } else {
M
mingxihua 已提交
95
        console.error('getWantAgent failed, error: ${JSON.stringify(err)}');
Z
zhuhan 已提交
96 97
    }
}
Z
zhuhan 已提交
98
try {
Z
zhuhan 已提交
99
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
100
} catch(err) {
M
mingxihua 已提交
101
    console.error('getWantAgent failed, error: ${JSON.stringify(err)}');
D
donglin 已提交
102 103 104 105 106 107 108 109 110
}
```



## WantAgent.getWantAgent

getWantAgent(info: WantAgentInfo): Promise\<WantAgent\>

F
fangJinliang1 已提交
111
创建WantAgent(Promise形式)。 创建失败返回的WantAgent为空值。
D
donglin 已提交
112 113 114 115 116

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
117 118
| 参数名 | 类型          | 必填 | 说明          |
| ---- | ------------- | ---- | ------------- |
M
m00512953 已提交
119
| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | 是   | WantAgent信息。 |
D
donglin 已提交
120 121 122 123 124 125 126

**返回值:**

| 类型                                                        | 说明                                                         |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<WantAgent\> | 以Promise形式返回WantAgent。 |

Z
zhuhan 已提交
127
**错误码:**
Z
zhuhan 已提交
128
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
154 155
**示例:**

Z
zhuhan 已提交
156
```ts
D
donglin 已提交
157
//WantAgentInfo对象
Z
zhuhan 已提交
158
let wantAgentInfo = {
D
donglin 已提交
159 160
    wants: [
        {
Z
zhuhan 已提交
161
            deviceId: 'deviceId',
162 163
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
164 165 166 167
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
168 169 170 171
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
172 173
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
174
                mykey4: [false, true, false],
Z
zhuhan 已提交
175
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
176 177 178 179 180 181 182
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
183
};
D
donglin 已提交
184 185 186

try {
    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
Z
zhuhan 已提交
187 188
    wantAgent = data;
}).catch((err) => {
M
mingxihua 已提交
189
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
190 191
});
} catch (err) {
M
mingxihua 已提交
192
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
}
```



## WantAgent.getBundleName

getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void

获取WantAgent实例的包名(callback形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
208 209 210 211
| 参数名     | 类型                    | 必填 | 说明                              |
| -------- | ----------------------- | ---- | --------------------------------- |
| agent    | WantAgent               | 是   | WantAgent对象。                     |
| callback | AsyncCallback\<string\> | 是   | 获取WantAgent实例的包名的回调方法。 |
D
donglin 已提交
212

Z
zhuhan 已提交
213
**错误码:**
Z
zhuhan 已提交
214
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
240 241
**示例:**

Z
zhuhan 已提交
242
```ts
D
donglin 已提交
243
//wantAgent对象
Z
zhuhan 已提交
244
let wantAgent;
D
donglin 已提交
245
//WantAgentInfo对象
Z
zhuhan 已提交
246
let wantAgentInfo = {
D
donglin 已提交
247 248
    wants: [
        {
Z
zhuhan 已提交
249
            deviceId: 'deviceId',
250 251
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
252 253 254 255
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
256 257 258 259
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
260 261
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
262
                mykey4: [false, true, false],
Z
zhuhan 已提交
263
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
264 265 266 267 268 269 270
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
271
};
D
donglin 已提交
272

Z
zhuhan 已提交
273 274
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
275
    if (err === undefined) {
Z
zhuhan 已提交
276 277
        wantAgent = data;
    } else {
M
mingxihua 已提交
278
        console.info('getWantAgent failed ${JSON.stringify(wantAgent)}');
Z
zhuhan 已提交
279
    }
D
donglin 已提交
280 281
    //getBundleName回调
    function getBundleNameCallback(err, data) {
Z
zhuhan 已提交
282
        if(err) {
M
mingxihua 已提交
283
            console.info('getBundleName failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
284
        } else {
M
mingxihua 已提交
285
            console.info('getBundleName ok! ${JSON.stringify(data)}');
Z
zhuhan 已提交
286 287 288 289 290
        }
    }
    try {
        WantAgent.getBundleName(wantAgent, getBundleNameCallback);
    } catch(err) {
M
mingxihua 已提交
291
        console.info('getBundleName failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
292
    }
Z
zhuhan 已提交
293
}
Z
zhuhan 已提交
294
try {
Z
zhuhan 已提交
295
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
296
} catch(err) {
M
mingxihua 已提交
297
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
}
```



## WantAgent.getBundleName

getBundleName(agent: WantAgent): Promise\<string\>

获取WantAgent实例的包名(Promise形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
313 314 315
| 参数名  | 类型      | 必填 | 说明          |
| ----- | --------- | ---- | ------------- |
| agent | WantAgent | 是   | WantAgent对象。 |
D
donglin 已提交
316 317 318 319 320 321 322

**返回值:**

| 类型                                                        | 说明                                                         |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<string\> | 以Promise形式返回获取WantAgent实例的包名。 |

Z
zhuhan 已提交
323
**错误码:**
Z
zhuhan 已提交
324
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
350 351
**示例:**

Z
zhuhan 已提交
352 353
```ts
 //wantAgent对象
Z
zhuhan 已提交
354
let wantAgent;
D
donglin 已提交
355
//WantAgentInfo对象
Z
zhuhan 已提交
356
let wantAgentInfo = {
D
donglin 已提交
357 358
    wants: [
        {
Z
zhuhan 已提交
359
            deviceId: 'deviceId',
360 361
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
362 363 364 365
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
366 367 368 369
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
370 371
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
372
                mykey4: [false, true, false],
Z
zhuhan 已提交
373
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
374 375 376 377 378 379 380
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
381
};
D
donglin 已提交
382

Z
zhuhan 已提交
383 384
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
385
    if (err === undefined) {
D
donglin 已提交
386
        wantAgent = data;
Z
zhuhan 已提交
387
    } else {
M
mingxihua 已提交
388
        console.info('getWantAgent failed! ${JSON.stringify(wantAgent)}');
Z
zhuhan 已提交
389 390 391
    }
    try {
        WantAgent.getBundleName(wantAgent).then((data)=>{
M
mingxihua 已提交
392
            console.info('getBundleName ok! ${JSON.stringify(data)}');
Z
zhuhan 已提交
393
        }).catch((err)=>{
M
mingxihua 已提交
394
            console.info('getBundleName failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
M
mingxihua 已提交
395
        });
Z
zhuhan 已提交
396
    } catch(err){
M
mingxihua 已提交
397
        console.info('getBundleName failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
398 399
    }
}
Z
zhuhan 已提交
400
try {
Z
zhuhan 已提交
401
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
402
} catch(err) {
M
mingxihua 已提交
403
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
}
```



## WantAgent.getUid

getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void

获取WantAgent实例的用户ID(callback形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
419 420 421 422
| 参数名     | 类型                    | 必填 | 说明                                |
| -------- | ----------------------- | ---- | ----------------------------------- |
| agent    | WantAgent               | 是   | WantAgent对象。                       |
| callback | AsyncCallback\<number\> | 是   | 获取WantAgent实例的用户ID的回调方法。 |
D
donglin 已提交
423

Z
zhuhan 已提交
424
**错误码:**
Z
zhuhan 已提交
425
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
451 452
**示例:**

Z
zhuhan 已提交
453
```ts
D
donglin 已提交
454 455
import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象
Z
zhuhan 已提交
456
let wantAgent;
D
donglin 已提交
457
//WantAgentInfo对象
Z
zhuhan 已提交
458
let wantAgentInfo = {
D
donglin 已提交
459 460
    wants: [
        {
Z
zhuhan 已提交
461
            deviceId: 'deviceId',
462 463
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
464 465 466 467
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
468 469 470 471
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
472 473
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
474
                mykey4: [false, true, false],
Z
zhuhan 已提交
475
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
476 477 478 479 480 481 482
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
483
};
D
donglin 已提交
484

Z
zhuhan 已提交
485 486
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
487
    if (err === undefined) {
Z
zhuhan 已提交
488 489
        wantAgent = data;
    } else {
M
mingxihua 已提交
490
        console.info('getWantAgent failed ${JSON.stringify(err)}');
Z
zhuhan 已提交
491
    }
D
donglin 已提交
492 493
    //getUid回调
    function getUidCallback(err, data) {
Z
zhuhan 已提交
494
        if(err) {
M
mingxihua 已提交
495
            console.info('getUid failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
496
        } else {
M
mingxihua 已提交
497
            console.info('getUid ok! ${JSON.stringify(data)}');
Z
zhuhan 已提交
498 499 500 501 502
        }
    }
    try {
        WantAgent.getUid(wantAgent, getUidCallback);
    } catch(err) {
M
mingxihua 已提交
503
        console.info('getUid failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
504
    }
Z
zhuhan 已提交
505
}
Z
zhuhan 已提交
506
try {
Z
zhuhan 已提交
507
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
508
} catch(err) {
M
mingxihua 已提交
509
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
}
```



## WantAgent.getUid

getUid(agent: WantAgent): Promise\<number\>

获取WantAgent实例的用户ID(Promise形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
525 526 527
| 参数名  | 类型      | 必填 | 说明          |
| ----- | --------- | ---- | ------------- |
| agent | WantAgent | 是   | WantAgent对象。 |
D
donglin 已提交
528 529 530 531 532 533 534

**返回值:**

| 类型                                                        | 说明                                                         |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<number\> | 以Promise形式返回获取WantAgent实例的用户ID。 |

Z
zhuhan 已提交
535
**错误码:**
Z
zhuhan 已提交
536
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
562 563
**示例:**

Z
zhuhan 已提交
564
```ts
D
donglin 已提交
565
//wantAgent对象
Z
zhuhan 已提交
566
let wantAgent;
D
donglin 已提交
567
//WantAgentInfo对象
Z
zhuhan 已提交
568
let wantAgentInfo = {
D
donglin 已提交
569 570
    wants: [
        {
Z
zhuhan 已提交
571
            deviceId: 'deviceId',
572 573
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
574 575 576 577
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
578 579 580 581
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
582 583
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
584
                mykey4: [false, true, false],
Z
zhuhan 已提交
585
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
586 587 588 589 590 591 592
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
593
};
D
donglin 已提交
594

Z
zhuhan 已提交
595 596
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
597
    if (err === undefined) {
D
donglin 已提交
598
        wantAgent = data;
Z
zhuhan 已提交
599
    } else {
M
mingxihua 已提交
600
        console.info('getWantAgent failed! ${JSON.stringify(wantAgent)}');
Z
zhuhan 已提交
601 602 603
    }
    try {
        WantAgent.getUid(wantAgent).then((data)=>{
M
mingxihua 已提交
604
            console.info('getUid ok! ${JSON.stringify(data)}');
Z
zhuhan 已提交
605
        }).catch((err)=>{
M
mingxihua 已提交
606
            console.info('getUid failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
M
mingxihua 已提交
607
        });
Z
zhuhan 已提交
608
    } catch(err){
M
mingxihua 已提交
609
        console.info('getUid failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
610 611
    }
}
Z
zhuhan 已提交
612
try {
Z
zhuhan 已提交
613
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
614
} catch(err) {
M
mingxihua 已提交
615
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
}
```


## WantAgent.getWant

getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void

获取WantAgent对象的want(callback形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

D
fix  
donglin 已提交
632 633 634
| 参数名     | 类型                  | 必填 | 说明                            |
| -------- | --------------------- | ---- | ------------------------------- |
| agent    | WantAgent             | 是   | WantAgent对象。                   |
M
m00512953 已提交
635
| callback | AsyncCallback\<[Want](js-apis-app-ability-want.md)\> | 是   | 获取WantAgent对象want的回调方法。 |
D
donglin 已提交
636

Z
zhuhan 已提交
637
**错误码:**
Z
zhuhan 已提交
638
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
664 665
**示例:**

Z
zhuhan 已提交
666
```ts
D
donglin 已提交
667
//wantAgent对象
Z
zhuhan 已提交
668
let wantAgent;
D
donglin 已提交
669
//WantAgentInfo对象
Z
zhuhan 已提交
670
let wantAgentInfo = {
D
donglin 已提交
671 672
    wants: [
        {
Z
zhuhan 已提交
673
            deviceId: 'deviceId',
674 675
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
676 677 678 679
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
680 681 682 683
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
684 685
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
686
                mykey4: [false, true, false],
Z
zhuhan 已提交
687
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
688 689 690 691 692 693 694
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
695
};
D
donglin 已提交
696

Z
zhuhan 已提交
697 698
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
699
    if (err === undefined) {
Z
zhuhan 已提交
700 701
        wantAgent = data;
    } else {
M
mingxihua 已提交
702
        console.info('getWantAgent failed ${JSON.stringify(wantAgent)}');
Z
zhuhan 已提交
703
    }
M
mingxihua 已提交
704
    //getWant回调
D
donglin 已提交
705
    function getWantCallback(err, data) {
Z
zhuhan 已提交
706
        if(err) {
M
mingxihua 已提交
707
            console.info('getWant failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
708
        } else {
M
mingxihua 已提交
709
            console.info('getWant ok! ${JSON.stringify(data)}');
Z
zhuhan 已提交
710 711 712
        }
    }
    try {
M
mingxihua 已提交
713
        WantAgent.getWant(wantAgent, getWantCallback);
Z
zhuhan 已提交
714
    } catch(err) {
M
mingxihua 已提交
715
        console.info('getWant failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
716
    }
Z
zhuhan 已提交
717
}
Z
zhuhan 已提交
718
try {
Z
zhuhan 已提交
719
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
720
} catch(err) {
M
mingxihua 已提交
721
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
}
```



## WantAgent.getWant

getWant(agent: WantAgent): Promise\<Want\>

获取WantAgent对象的want(Promise形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

D
fix  
donglin 已提交
739 740 741
| 参数名  | 类型      | 必填 | 说明          |
| ----- | --------- | ---- | ------------- |
| agent | WantAgent | 是   | WantAgent对象。 |
D
donglin 已提交
742 743 744 745 746 747 748

**返回值:**

| 类型                                                        | 说明                                                         |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<Want\> | 以Promise形式返回获取WantAgent对象的want。 |

Z
zhuhan 已提交
749
**错误码:**
Z
zhuhan 已提交
750
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
776 777
**示例:**

Z
zhuhan 已提交
778
```ts
D
donglin 已提交
779
//wantAgent对象
Z
zhuhan 已提交
780
let wantAgent;
D
donglin 已提交
781
//WantAgentInfo对象
Z
zhuhan 已提交
782
let wantAgentInfo = {
D
donglin 已提交
783 784
    wants: [
        {
Z
zhuhan 已提交
785
            deviceId: 'deviceId',
786 787
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
788 789 790 791
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
792 793 794 795
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
796 797
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
798
                mykey4: [false, true, false],
Z
zhuhan 已提交
799
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
800 801 802 803 804 805 806
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
807
};
D
donglin 已提交
808

Z
zhuhan 已提交
809 810
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
811
    if (err === undefined) {
D
donglin 已提交
812
        wantAgent = data;
Z
zhuhan 已提交
813
    } else {
M
mingxihua 已提交
814
        console.info('getWantAgent failed! ${JSON.stringify(wantAgent)}');
Z
zhuhan 已提交
815 816 817
    }
    try {
        WantAgent.getUid(wantAgent).then((data)=>{
M
mingxihua 已提交
818
            console.info('getUid ok! ${JSON.stringify(data)}');
Z
zhuhan 已提交
819
        }).catch((err)=>{
M
mingxihua 已提交
820
            console.info('getUid failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
M
mingxihua 已提交
821
        });
Z
zhuhan 已提交
822
    } catch(err){
M
mingxihua 已提交
823
        console.info('getUid failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
824 825
    }
}
Z
zhuhan 已提交
826
try {
Z
zhuhan 已提交
827
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
828
} catch(err) {
M
mingxihua 已提交
829
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
}
```



## WantAgent.cancel

cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void

取消WantAgent实例(callback形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
845 846 847 848
| 参数名     | 类型                  | 必填 | 说明                        |
| -------- | --------------------- | ---- | --------------------------- |
| agent    | WantAgent             | 是   | WantAgent对象。               |
| callback | AsyncCallback\<void\> | 是   | 取消WantAgent实例的回调方法。 |
D
donglin 已提交
849

Z
zhuhan 已提交
850
**错误码:**
Z
zhuhan 已提交
851
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
877 878
**示例:**

Z
zhuhan 已提交
879
```ts
D
donglin 已提交
880
//wantAgent对象
Z
zhuhan 已提交
881
let wantAgent;
D
donglin 已提交
882
//WantAgentInfo对象
Z
zhuhan 已提交
883
let wantAgentInfo = {
D
donglin 已提交
884 885
    wants: [
        {
Z
zhuhan 已提交
886
            deviceId: 'deviceId',
887 888
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
889 890 891 892
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
893 894 895 896
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
897 898
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
899
                mykey4: [false, true, false],
Z
zhuhan 已提交
900
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
901 902 903 904 905 906 907
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
908
};
D
donglin 已提交
909

Z
zhuhan 已提交
910 911
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
912
    if (err === undefined) {
Z
zhuhan 已提交
913 914
        wantAgent = data;
    } else {
M
mingxihua 已提交
915
        console.info('getWantAgent failed ${JSON.stringify(wantAgent)}');
Z
zhuhan 已提交
916
    }
M
mingxihua 已提交
917
    //cancel回调
D
donglin 已提交
918
    function cancelCallback(err, data) {
Z
zhuhan 已提交
919
        if(err) {
M
mingxihua 已提交
920
            console.info('cancel failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
921 922 923
        } else {
            console.info('cancel ok!');
        }
D
donglin 已提交
924
    }
Z
zhuhan 已提交
925
    try {
M
mingxihua 已提交
926
        WantAgent.cancel(wantAgent, cancelCallback);
Z
zhuhan 已提交
927
    } catch(err) {
M
mingxihua 已提交
928
        console.info('cancel failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
929 930
    }
}
Z
zhuhan 已提交
931
try {
Z
zhuhan 已提交
932
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
933
} catch(err) {
M
mingxihua 已提交
934
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
}
```



## WantAgent.cancel

cancel(agent: WantAgent): Promise\<void\>

取消WantAgent实例(Promise形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
950 951 952
| 参数名  | 类型      | 必填 | 说明          |
| ----- | --------- | ---- | ------------- |
| agent | WantAgent | 是   | WantAgent对象。 |
D
donglin 已提交
953 954 955 956 957 958 959

**返回值:**

| 类型            | 说明                            |
| --------------- | ------------------------------- |
| Promise\<void\> | 以Promise形式获取异步返回结果。 |

Z
zhuhan 已提交
960
**错误码:**
Z
zhuhan 已提交
961
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
987 988
**示例:**

Z
zhuhan 已提交
989
```ts
D
donglin 已提交
990
//wantAgent对象
Z
zhuhan 已提交
991
let wantAgent;
D
donglin 已提交
992
//WantAgentInfo对象
Z
zhuhan 已提交
993
let wantAgentInfo = {
D
donglin 已提交
994 995
    wants: [
        {
Z
zhuhan 已提交
996
            deviceId: 'deviceId',
997 998
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
999 1000 1001 1002
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
1003 1004 1005 1006
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
1007 1008
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
1009
                mykey4: [false, true, false],
Z
zhuhan 已提交
1010
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
1011 1012 1013 1014 1015 1016 1017
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
1018
};
D
donglin 已提交
1019

Z
zhuhan 已提交
1020 1021
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
1022
    if (err === undefined) {
D
donglin 已提交
1023
        wantAgent = data;
Z
zhuhan 已提交
1024
    } else {
M
mingxihua 已提交
1025
        console.info('getWantAgent failed! ${JSON.stringify(wantAgent)}');
Z
zhuhan 已提交
1026 1027 1028 1029 1030
    }
    try {
        WantAgent.cancel(wantAgent).then((data)=>{
            console.info('cancel ok!');
        }).catch((err)=>{
M
mingxihua 已提交
1031
            console.info('cancel failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
M
mingxihua 已提交
1032
        });
Z
zhuhan 已提交
1033
    } catch(err){
M
mingxihua 已提交
1034
        console.info('cancel failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
1035 1036
    }
}
Z
zhuhan 已提交
1037
try {
Z
zhuhan 已提交
1038
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
1039
} catch(err) {
M
mingxihua 已提交
1040
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
1041 1042 1043 1044 1045
}
```

## WantAgent.trigger

1046
trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback\<CompleteData\>): void
D
donglin 已提交
1047 1048 1049 1050 1051 1052 1053

主动激发WantAgent实例(callback形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
1054 1055 1056
| 参数名        | 类型                          | 必填 | 说明                            |
| ----------- | ----------------------------- | ---- | ------------------------------- |
| agent       | WantAgent                     | 是   | WantAgent对象。                   |
Z
zhuhan 已提交
1057
| triggerInfo | [TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md)                   | 是   | TriggerInfo对象。                 |
M
m00512953 已提交
1058
| callback    | AsyncCallback\<[CompleteData](#completedata)\> | 否   | 主动激发WantAgent实例的回调方法。 |
D
donglin 已提交
1059

Z
zhuhan 已提交
1060
**错误码:**
Z
zhuhan 已提交
1061
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
1087 1088
**示例:**

Z
zhuhan 已提交
1089
```ts
D
donglin 已提交
1090
//wantAgent对象
Z
zhuhan 已提交
1091
let wantAgent;
Z
zhuhan 已提交
1092
// triggerInfo
Z
zhuhan 已提交
1093
let triggerInfo = {
M
mingxihua 已提交
1094 1095
    code: 0 //自定义义结果码
};
D
donglin 已提交
1096
//WantAgentInfo对象
Z
zhuhan 已提交
1097
let wantAgentInfo = {
D
donglin 已提交
1098 1099
    wants: [
        {
Z
zhuhan 已提交
1100
            deviceId: 'deviceId',
1101 1102
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
1103 1104 1105 1106
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
1107 1108 1109 1110
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
1111 1112
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
1113
                mykey4: [false, true, false],
Z
zhuhan 已提交
1114
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
1115 1116 1117 1118 1119 1120 1121
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
1122
};
D
donglin 已提交
1123

Z
zhuhan 已提交
1124 1125
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
1126
    if (err === undefined) {
Z
zhuhan 已提交
1127 1128
        wantAgent = data;
    } else {
M
mingxihua 已提交
1129
        console.info('getWantAgent failed ${JSON.stringify(wantAgent)}');
D
donglin 已提交
1130
    }
M
mingxihua 已提交
1131
    //trigger回调
Z
zhuhan 已提交
1132 1133
    function triggerCallback(err, data) {
        if(err) {
M
mingxihua 已提交
1134
            console.info('getUid failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
1135
        } else {
M
mingxihua 已提交
1136
            console.info('getUid ok! ${JSON.stringify(data)}');
Z
zhuhan 已提交
1137
        }
D
donglin 已提交
1138
    }
Z
zhuhan 已提交
1139 1140 1141
    try {
        WantAgent.trigger(wantAgent, triggerInfo, triggerCallback);
    } catch(err) {
M
mingxihua 已提交
1142
        console.info('getUid failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
1143 1144
    }
}
Z
zhuhan 已提交
1145
try {
Z
zhuhan 已提交
1146
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
1147
} catch(err) {
M
mingxihua 已提交
1148
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
1149 1150 1151 1152 1153 1154 1155 1156 1157
}
```



## WantAgent.equal

equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>): void

Z
zhuhan 已提交
1158
判断两个WantAgent实例是否相等(Callback形式),以此来判断是否是来自同一应用的相同操作。
D
donglin 已提交
1159 1160 1161 1162 1163

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
1164 1165 1166 1167 1168
| 参数名       | 类型                     | 必填 | 说明                                    |
| ---------- | ------------------------ | ---- | --------------------------------------- |
| agent      | WantAgent                | 是   | WantAgent对象。                           |
| otherAgent | WantAgent                | 是   | WantAgent对象。                           |
| callback   | AsyncCallback\<boolean\> | 是   | 判断两个WantAgent实例是否相等的回调方法。 |
D
donglin 已提交
1169

Z
zhuhan 已提交
1170
**错误码:**
Z
zhuhan 已提交
1171
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
1197 1198
**示例:**

Z
zhuhan 已提交
1199
```ts
D
donglin 已提交
1200
//wantAgent对象
Z
zhuhan 已提交
1201 1202
let wantAgent1;
let wantAgent2;
D
donglin 已提交
1203
//WantAgentInfo对象
Z
zhuhan 已提交
1204
let wantAgentInfo = {
D
donglin 已提交
1205 1206
    wants: [
        {
Z
zhuhan 已提交
1207
            deviceId: 'deviceId',
1208 1209
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
1210 1211 1212 1213
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
1214 1215 1216 1217
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
1218 1219
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
1220
                mykey4: [false, true, false],
Z
zhuhan 已提交
1221
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
1222 1223 1224 1225 1226 1227 1228
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
1229
};
D
donglin 已提交
1230

Z
zhuhan 已提交
1231 1232
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
1233
    if (err === undefined) {
Z
zhuhan 已提交
1234 1235 1236
        wantAgent1 = data;
        wantAgent2 = data;
    } else {
M
mingxihua 已提交
1237
        console.info('getWantAgent failed ${JSON.stringify(wantAgent)}');
Z
zhuhan 已提交
1238
    }
M
mingxihua 已提交
1239
    //equal回调
D
donglin 已提交
1240
    function equalCallback(err, data) {
Z
zhuhan 已提交
1241
        if(err) {
M
mingxihua 已提交
1242
            console.info('equal failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
1243
        } else {
M
mingxihua 已提交
1244
            console.info('equal ok! ${JSON.stringify(data)}');
Z
zhuhan 已提交
1245 1246 1247 1248 1249
        }
    }
    try {
        WantAgent.equal(wantAgent1,wantAgent2,equalCallback);
    } catch(err) {
M
mingxihua 已提交
1250
        console.info('equal failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
1251
    }
Z
zhuhan 已提交
1252
}
Z
zhuhan 已提交
1253
try {
Z
zhuhan 已提交
1254
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
1255
} catch(err) {
M
mingxihua 已提交
1256
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
1257 1258 1259 1260 1261 1262 1263 1264 1265
}
```



## WantAgent.equal

equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\>

Z
zhuhan 已提交
1266
判断两个WantAgent实例是否相等(Promise形式),以此来判断是否是来自同一应用的相同操作。
D
donglin 已提交
1267 1268 1269 1270 1271

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
1272 1273 1274 1275
| 参数名       | 类型      | 必填 | 说明          |
| ---------- | --------- | ---- | ------------- |
| agent      | WantAgent | 是   | WantAgent对象。 |
| otherAgent | WantAgent | 是   | WantAgent对象。 |
D
donglin 已提交
1276 1277 1278 1279 1280 1281 1282

**返回值:**

| 类型                                                        | 说明                                                         |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | 以Promise形式返回获取判断两个WantAgent实例是否相等的结果。 |

Z
zhuhan 已提交
1283
**错误码:**
Z
zhuhan 已提交
1284
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
1310 1311
**示例:**

Z
zhuhan 已提交
1312
```ts
D
donglin 已提交
1313
//wantAgent对象
Z
zhuhan 已提交
1314 1315
let wantAgent1;
let wantAgent2;
D
donglin 已提交
1316
//WantAgentInfo对象
Z
zhuhan 已提交
1317
let wantAgentInfo = {
D
donglin 已提交
1318 1319
    wants: [
        {
Z
zhuhan 已提交
1320
            deviceId: 'deviceId',
1321 1322
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
1323 1324 1325 1326
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
1327 1328 1329 1330
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
1331 1332
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
1333
                mykey4: [false, true, false],
Z
zhuhan 已提交
1334
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
1335 1336 1337 1338 1339 1340 1341
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
1342
};
D
donglin 已提交
1343

Z
zhuhan 已提交
1344 1345
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
1346
    if (err === undefined) {
D
donglin 已提交
1347 1348
        wantAgent1 = data;
        wantAgent2 = data;
Z
zhuhan 已提交
1349
    } else {
M
mingxihua 已提交
1350
        console.info('getWantAgent failed! ${JSON.stringify(wantAgent)}');
Z
zhuhan 已提交
1351 1352 1353
    }
    try {
        WantAgent.equal(wantAgent1,wantAgent2).then((data)=>{
M
mingxihua 已提交
1354
            console.info('equal ok! ${JSON.stringify(data)}');
Z
zhuhan 已提交
1355
        }).catch((err)=>{
M
mingxihua 已提交
1356
            console.info('equal failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
1357 1358
        })
    } catch(err){
M
mingxihua 已提交
1359
        console.info('equal failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
1360 1361
    }
}
Z
zhuhan 已提交
1362
try {
Z
zhuhan 已提交
1363
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
1364
} catch(err) {
M
mingxihua 已提交
1365
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378
}
```

## WantAgent.getOperationType

getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): void;

获取一个WantAgent的OperationType信息(callback形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
1379 1380 1381 1382
| 参数名       | 类型                     | 必填 | 说明                                    |
| ---------- | ------------------------ | ---- | --------------------------------------- |
| agent      | WantAgent                | 是   | WantAgent对象。                           |
| callback   | AsyncCallback\<number> | 是   | 获取一个WantAgent的OperationType信息的回调方法。 |
D
donglin 已提交
1383

Z
zhuhan 已提交
1384
**错误码:**
Z
zhuhan 已提交
1385
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
1411 1412
**示例:**

Z
zhuhan 已提交
1413
```ts
D
donglin 已提交
1414
//wantAgent对象
Z
zhuhan 已提交
1415
let wantAgent;
D
donglin 已提交
1416
//WantAgentInfo对象
Z
zhuhan 已提交
1417
let wantAgentInfo = {
D
donglin 已提交
1418 1419
    wants: [
        {
Z
zhuhan 已提交
1420
            deviceId: 'deviceId',
1421 1422
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
1423 1424 1425 1426
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
1427 1428 1429 1430
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
1431 1432
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
1433
                mykey4: [false, true, false],
Z
zhuhan 已提交
1434
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
1435 1436 1437 1438 1439 1440 1441
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
1442
};
D
donglin 已提交
1443

Z
zhuhan 已提交
1444 1445
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
1446
    if (err === undefined) {
D
donglin 已提交
1447
        wantAgent = data;
Z
zhuhan 已提交
1448
    } else {
M
mingxihua 已提交
1449
        console.info('getWantAgent failed ${JSON.stringify(wantAgent)}');
Z
zhuhan 已提交
1450
    }
M
mingxihua 已提交
1451
    //getOperationTypeCallback回调
Z
zhuhan 已提交
1452 1453
    function getOperationTypeCallback(err, data) {
        if(err) {
M
mingxihua 已提交
1454
            console.info('getOperationType failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
1455
        } else {
M
mingxihua 已提交
1456
            console.info('getOperationType ok! ${JSON.stringify(data)}');
Z
zhuhan 已提交
1457 1458 1459
        }
    }
    try {
M
mingxihua 已提交
1460
        WantAgent.getOperationTypeCallback(wantAgent, getOperationTypeCallback);
Z
zhuhan 已提交
1461
    } catch(err) {
M
mingxihua 已提交
1462
        console.info('getOperationTypeCallback failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
1463 1464
    }
}
Z
zhuhan 已提交
1465
try {
Z
zhuhan 已提交
1466
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
1467
} catch(err) {
M
mingxihua 已提交
1468
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
}
```

## WantAgent.getOperationType

getOperationType(agent: WantAgent): Promise\<number>;

获取一个WantAgent的OperationType信息(Promise形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

D
fix  
donglin 已提交
1482 1483 1484
| 参数名       | 类型      | 必填 | 说明          |
| ---------- | --------- | ---- | ------------- |
| agent      | WantAgent | 是   | WantAgent对象。 |
D
donglin 已提交
1485 1486 1487 1488 1489 1490 1491

**返回值:**

| 类型                                                        | 说明                                                         |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<number> | 以Promise形式返回获取operationType的结果。 |

Z
zhuhan 已提交
1492
**错误码:**
Z
zhuhan 已提交
1493
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
Z
zhuhan 已提交
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518
| 错误码ID    | 错误信息            |
|-----------|--------------------|
| 16000001   | Input error. The specified ability name does not exist. |
| 16000002   | Ability type error. The specified ability type is wrong.|
| 16000003   | Input error. The specified id does not exist.|
| 16000004   | Visibility verification failed.|
| 16000006   | Can not cross user operations.|
| 16000007   | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008   | Crowdtest App Expiration.|
| 16000009   | Can not start ability in wukong mode.|
| 16000010   | Can not operation with continue flag.|
| 16000011   | Context does not exist.|
| 16000050   | Internal Error.|
| 16000051   | Network error. The network is abnormal.|
| 16000052   | Free install not support. The applicaiotn dose not support free install.|
| 16000053   | Not top ability. The application is not top ability.|
| 16000054   | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055   | Free install timeout.|
| 16000056   | Can not free install other ability.|
| 16000057   | Not support cross device free install.|
| 16000101   | execute shell command failed.|
| 16000151   | Invalid wantagent object.|
| 16000152   | wantAgent object not found.|
| 16000153   | wangAgent object canceled.|

D
donglin 已提交
1519 1520
**示例:**

Z
zhuhan 已提交
1521
```ts
D
donglin 已提交
1522
//wantAgent对象
Z
zhuhan 已提交
1523
let wantAgent;
D
donglin 已提交
1524
//WantAgentInfo对象
Z
zhuhan 已提交
1525
let wantAgentInfo = {
D
donglin 已提交
1526 1527
    wants: [
        {
Z
zhuhan 已提交
1528
            deviceId: 'deviceId',
1529 1530
            bundleName: 'com.example.myapplication',
            abilityName: 'EntryAbility',
Z
zhuhan 已提交
1531 1532 1533 1534
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
D
donglin 已提交
1535 1536 1537 1538
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
Z
zhuhan 已提交
1539 1540
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
D
donglin 已提交
1541
                mykey4: [false, true, false],
Z
zhuhan 已提交
1542
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
D
donglin 已提交
1543 1544 1545 1546 1547 1548 1549
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
M
mingxihua 已提交
1550
};
D
donglin 已提交
1551

Z
zhuhan 已提交
1552 1553
//getWantAgent回调
function getWantAgentCallback(err, data) {
Z
zhuhan 已提交
1554
    if (err === undefined) {
D
donglin 已提交
1555
        wantAgent = data;
Z
zhuhan 已提交
1556
    } else {
M
mingxihua 已提交
1557
        console.info('getWantAgent failed! ${JSON.stringify(wantAgent)}');
Z
zhuhan 已提交
1558 1559 1560
    }
    try {
        WantAgent.getOperationType(wantAgent).then((data)=>{
M
mingxihua 已提交
1561
            console.info('getOperationType ok! ${JSON.stringify(data)}');
Z
zhuhan 已提交
1562
        }).catch((err)=>{
M
mingxihua 已提交
1563
            console.info('getOperationType failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
M
mingxihua 已提交
1564
        });
Z
zhuhan 已提交
1565
    } catch(err){
M
mingxihua 已提交
1566
        console.info('getOperationType failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
Z
zhuhan 已提交
1567 1568
    }
}
Z
zhuhan 已提交
1569
try {
Z
zhuhan 已提交
1570
    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
Z
zhuhan 已提交
1571
} catch(err) {
M
mingxihua 已提交
1572
    console.info('getWantAgent failed! ${JSON.stringify(err.code)} ${JSON.stringify(err.message)}');
D
donglin 已提交
1573 1574 1575 1576 1577 1578 1579 1580 1581
}
```

## WantAgentFlags

**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core

| 名称                | 值             | 说明                                                         |
| ------------------- | -------------- | ------------------------------------------------------------ |
D
merge  
donglin 已提交
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591
| ONE_TIME_FLAG       | 0 | WantAgent仅能使用一次。                                      |
| NO_BUILD_FLAG       | 1 | 如果描述WantAgent对象不存在,则不创建它,直接返回null。      |
| CANCEL_PRESENT_FLAG | 2 | 在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象。 |
| UPDATE_PRESENT_FLAG | 3 | 使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据。 |
| CONSTANT_FLAG       | 4 | WantAgent是不可变的。                                        |
| REPLACE_ELEMENT     | 5 | 当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代 |
| REPLACE_ACTION      | 6 | 当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代 |
| REPLACE_URI         | 7 | 当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代 |
| REPLACE_ENTITIES    | 8 | 当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代 |
| REPLACE_BUNDLE      | 9 | 当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代 |
D
donglin 已提交
1592 1593 1594 1595 1596 1597 1598 1599 1600



## OperationType

**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core

| 名称              | 值            | 说明                      |
| ----------------- | ------------- | ------------------------- |
D
merge  
donglin 已提交
1601 1602 1603 1604 1605
| UNKNOWN_TYPE      | 0 | 不识别的类型。            |
| START_ABILITY     | 1 | 开启一个有页面的Ability。 |
| START_ABILITIES   | 2 | 开启多个有页面的Ability。 |
| START_SERVICE     | 3 | 开启一个无页面的ability。 |
| SEND_COMMON_EVENT | 4 | 发送一个公共事件。        |
D
donglin 已提交
1606 1607 1608 1609 1610 1611 1612



## CompleteData 

**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core

1613 1614 1615 1616 1617
| 名称           | 类型                           | 必填 | 说明                    |
| -------------- | ------------------------------ | ---- | ---------------------- |
| info           | WantAgent                       | 是   | 触发的wantAgent。       |
| want           | Want                            | 是   | 存在的被触发的want。     |
| finalCode      | number                          | 是   | 触发wantAgent的请求代码。|
M
mingxihua 已提交
1618
| finalData      | string                          | 是   | 公共事件收集的最终数据。  |
1619
| extraInfo      | {[key: string]: any}            | 否   | 额外数据。               |
D
donglin 已提交
1620