1# @ohos.wantAgent (WantAgent) (System API) 2 3The **WantAgent** module provides APIs for creating and comparing **WantAgent** objects, and obtaining the user ID and bundle name of a **WantAgent** object. 4 5> **NOTE** 6> 7> The APIs of this module are supported since API version 7 and deprecated since API version 9. You are advised to use [@ohos.app.ability.wantAgent](js-apis-app-ability-wantAgent.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.wantAgent (WantAgent)](js-apis-wantAgent.md). 10 11## Modules to Import 12 13```ts 14import WantAgent from '@ohos.wantAgent'; 15``` 16 17## WantAgent.getWant 18 19getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void 20 21Obtains the Want in a **WantAgent** object. This API uses an asynchronous callback to return the result. 22 23**System capability**: SystemCapability.Ability.AbilityRuntime.Core 24 25**System API**: This is a system API and cannot be called by third-party applications. 26 27**Parameters** 28 29| Name | Type | Mandatory| Description | 30| -------- | -------------------------- | ---- | ----------------------- | 31| agent | [WantAgent](js-apis-wantAgent-sys.md) | Yes | **WantAgent** object. | 32| callback | AsyncCallback\<Want\> | Yes | Callback used to return the Want.| 33 34**Example** 35 36```ts 37import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 38import Want from '@ohos.app.ability.Want'; 39import { BusinessError } from '@ohos.base'; 40 41// WantAgent object 42let wantAgent: _WantAgent; 43 44// getWantAgent callback 45function getWantAgentCallback(err: BusinessError, data: _WantAgent) { 46 console.info('==========================>getWantAgentCallback=======================>'); 47 if (err.code == 0) { 48 wantAgent = data; 49 } else { 50 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 51 return; 52 } 53 54 // getWant callback 55 let getWantCallback = (err: BusinessError, data: Want) => { 56 console.info('==========================>getWantCallback=======================>'); 57 } 58 WantAgent.getWant(wantAgent, getWantCallback); 59} 60 61WantAgent.getWantAgent({ 62 wants: [ 63 { 64 deviceId: 'deviceId', 65 bundleName: 'com.neu.setResultOnAbilityResultTest1', 66 abilityName: 'com.example.test.EntryAbility', 67 action: 'action1', 68 entities: ['entity1'], 69 type: 'MIMETYPE', 70 uri: 'key={true,true,false}', 71 parameters: 72 { 73 mykey0: 2222, 74 mykey1: [1, 2, 3], 75 mykey2: '[1, 2, 3]', 76 mykey3: 'ssssssssssssssssssssssssss', 77 mykey4: [false, true, false], 78 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 79 mykey6: true, 80 } 81 } 82 ], 83 operationType: WantAgent.OperationType.START_ABILITIES, 84 requestCode: 0, 85 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 86}, getWantAgentCallback); 87``` 88 89## WantAgent.getWant 90 91getWant(agent: WantAgent): Promise\<Want\> 92 93Obtains the Want in a **WantAgent** object. This API uses a promise to return the result. 94 95**System capability**: SystemCapability.Ability.AbilityRuntime.Core 96 97**System API**: This is a system API and cannot be called by third-party applications. 98 99**Parameters** 100 101| Name| Type | Mandatory| Description | 102| ---- | ------------- | ---- | ------------- | 103| agent | [WantAgent](js-apis-wantAgent-sys.md) | Yes | **WantAgent** object.| 104 105**Return value** 106 107| Type | Description | 108| ----------------------------------------------------------- | ------------------------------------------------------------ | 109| Promise\<Want\> | Promise used to return the Want.| 110 111**Example** 112 113```ts 114import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 115import { BusinessError } from '@ohos.base'; 116 117// WantAgent object 118let wantAgent: _WantAgent; 119 120WantAgent.getWantAgent({ 121 wants: [ 122 { 123 deviceId: 'deviceId', 124 bundleName: 'com.neu.setResultOnAbilityResultTest1', 125 abilityName: 'com.example.test.EntryAbility', 126 action: 'action1', 127 entities: ['entity1'], 128 type: 'MIMETYPE', 129 uri: 'key={true,true,false}', 130 parameters: 131 { 132 mykey0: 2222, 133 mykey1: [1, 2, 3], 134 mykey2: '[1, 2, 3]', 135 mykey3: 'ssssssssssssssssssssssssss', 136 mykey4: [false, true, false], 137 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 138 mykey6: true, 139 } 140 } 141 ], 142 operationType: WantAgent.OperationType.START_ABILITIES, 143 requestCode: 0, 144 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 145}).then((data) => { 146 console.info('==========================>getWantAgentCallback=======================>'); 147 wantAgent = data; 148 if (wantAgent) { 149 WantAgent.getWant(wantAgent).then((data) => { 150 console.info('==========================>getWantCallback=======================>'); 151 }); 152 } 153}); 154``` 155