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