# @ohos.app.ability.wantAgent (WantAgent) The **WantAgent** module provides APIs for creating and comparing **WantAgent** objects, and obtaining the user ID and bundle name of a **WantAgent** object. You are advised to use this module, since it will replace the [@ohos.wantAgent](js-apis-wantAgent.md) module in the near future. > **NOTE** > > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import ```js import WantAgent from '@ohos.app.ability.wantAgent'; ``` ## WantAgent.getWantAgent getWantAgent(info: WantAgentInfo, callback: AsyncCallback\): void Obtains a **WantAgent** object. This API uses an asynchronous callback to return the result. If the creation fails, a null **WantAgent** object is returned. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------- | ---- | ----------------------- | | info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | Yes | Information about the **WantAgent** object to obtain. | | callback | AsyncCallback\ | Yes | Callback used to return the **WantAgent** object.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // getWantAgent callback function getWantAgentCallback(err, data) { console.info('==========================>getWantAgentCallback=======================>'); } // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.getWantAgent getWantAgent(info: WantAgentInfo): Promise\ Obtains a **WantAgent** object. This API uses a promise to return the result. If the creation fails, a null **WantAgent** object is returned. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name| Type | Mandatory| Description | | ---- | ------------- | ---- | ------------- | | info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | Yes | Information about the **WantAgent** object to obtain.| **Return value** | Type | Description | | ----------------------------------------------------------- | ------------------------------------------------------------ | | Promise\ | Promise used to return the **WantAgent** object.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo).then((data) => { console.info('==========================>getWantAgentCallback=======================>'); }); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.getBundleName getBundleName(agent: WantAgent, callback: AsyncCallback\): void Obtains the bundle name of a **WantAgent** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ----------------------- | ---- | --------------------------------- | | agent | WantAgent | Yes | Target **WantAgent** object. | | callback | AsyncCallback\ | Yes | Callback used to return the bundle name.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent; //getWantAgent callback function getWantAgentCallback(err, data) { console.info('==========================>getWantAgentCallback=======================>'); if (err.code == 0) { wantAgent = data; } else { console.info('----getWantAgent failed!----'); } } // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); // getBundleName callback function getBundleNameCallback(err, data) { console.info('==========================>getBundleNameCallback=======================>'); } WantAgent.getBundleName(wantAgent, getBundleNameCallback); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.getBundleName getBundleName(agent: WantAgent): Promise\ Obtains the bundle name of a **WantAgent** object. This API uses a promise to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | ----- | --------- | ---- | ------------- | | agent | WantAgent | Yes | Target **WantAgent** object.| **Return value** | Type | Description | | ----------------------------------------------------------- | ------------------------------------------------------------ | | Promise\ | Promise used to return the bundle name.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent; //WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo).then((data) => { console.info('==========================>getWantAgentCallback=======================>'); wantAgent = data; }); WantAgent.getBundleName(wantAgent).then((data) => { console.info('==========================>getBundleNameCallback=======================>'); }); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.getUid getUid(agent: WantAgent, callback: AsyncCallback\): void Obtains the user ID of a **WantAgent** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ----------------------- | ---- | ----------------------------------- | | agent | WantAgent | Yes | Target **WantAgent** object. | | callback | AsyncCallback\ | Yes | Callback used to return the user ID.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent; // getWantAgent callback function getWantAgentCallback(err, data) { console.info('==========================>getWantAgentCallback=======================>'); if (err.code == 0) { wantAgent = data; } else { console.info('----getWantAgent failed!----'); } } // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); // getUid callback function getUidCallback(err, data) { console.info('==========================>getUidCallback=======================>'); } WantAgent.getUid(wantAgent, getUidCallback); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.getUid getUid(agent: WantAgent): Promise\ Obtains the user ID of a **WantAgent** object. This API uses a promise to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | ----- | --------- | ---- | ------------- | | agent | WantAgent | Yes | Target **WantAgent** object.| **Return value** | Type | Description | | ----------------------------------------------------------- | ------------------------------------------------------------ | | Promise\ | Promise used to return the user ID.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent; // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo).then((data) => { console.info('==========================>getWantAgentCallback=======================>'); wantAgent = data; }); WantAgent.getUid(wantAgent).then((data) => { console.info('==========================>getUidCallback=======================>'); }); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.getWant getWant(agent: WantAgent, callback: AsyncCallback\): void Obtains the want in a **WantAgent** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API and cannot be called by third-party applications. **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | ------------------------------- | | agent | WantAgent | Yes | Target **WantAgent** object. | | callback | AsyncCallback\<[Want](js-apis-app-ability-want.md)\> | Yes | Callback used to return the want.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent; // getWantAgent callback function getWantAgentCallback(err, data) { console.info('==========================>getWantAgentCallback=======================>'); if (err.code == 0) { wantAgent = data; } else { console.info('----getWantAgent failed!----'); } } // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); // getWant callback function getWantCallback(err, data) { console.info('==========================>getWantCallback=======================>'); } WantAgent.getWant(wantAgent, getWantCallback); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.getWant getWant(agent: WantAgent): Promise\ Obtains the want in a **WantAgent** object. This API uses a promise to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API and cannot be called by third-party applications. **Parameters** | Name | Type | Mandatory| Description | | ----- | --------- | ---- | ------------- | | agent | WantAgent | Yes | Target **WantAgent** object.| **Return value** | Type | Description | | ----------------------------------------------------------- | ------------------------------------------------------------ | | Promise\ | Promise used to return the want.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent; // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo).then((data) => { console.info('==========================>getWantAgentCallback=======================>'); wantAgent = data; }); WantAgent.getWant(wantAgent).then((data) => { console.info('==========================>getWantCallback=======================>'); }); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.cancel cancel(agent: WantAgent, callback: AsyncCallback\): void Cancels a **WantAgent** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | --------------------------- | | agent | WantAgent | Yes | Target **WantAgent** object. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent; // getWantAgent callback function getWantAgentCallback(err, data) { console.info('==========================>getWantAgentCallback=======================>'); if (err.code == 0) { wantAgent = data; } else { console.info('----getWantAgent failed!----'); } } // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); // cancel callback function cancelCallback(err, data) { console.info('==========================>cancelCallback=======================>'); } WantAgent.cancel(wantAgent, cancelCallback); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.cancel cancel(agent: WantAgent): Promise\ Cancels a **WantAgent** object. This API uses a promise to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | ----- | --------- | ---- | ------------- | | agent | WantAgent | Yes | Target **WantAgent** object.| **Return value** | Type | Description | | --------------- | ------------------------------- | | Promise\ | Promise used to return the result.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent; // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo).then((data) => { console.info('==========================>getWantAgentCallback=======================>'); wantAgent = data; }); WantAgent.cancel(wantAgent).then((data) => { console.info('==========================>cancelCallback=======================>'); }); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.trigger trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback\): void Triggers a **WantAgent** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ----------------------------- | ---- | ------------------------------- | | agent | WantAgent | Yes | Target **WantAgent** object. | | triggerInfo | TriggerInfo | Yes | **TriggerInfo** object. | | callback | AsyncCallback\<[CompleteData](#completedata)\> | No | Callback used to return the result.| ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent; // getWantAgent callback function getWantAgentCallback(err, data) { console.info('==========================>getWantAgentCallback=======================>'); if (err.code == 0) { wantAgent = data; } else { console.info('----getWantAgent failed!----'); } } // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); // trigger callback function triggerCallback(data) { console.info('==========================>triggerCallback=======================>'); } let triggerInfo = { code:0 }; WantAgent.trigger(wantAgent, triggerInfo, triggerCallback); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.equal equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\): void Checks whether two **WantAgent** objects are equal to determine whether the same operation is from the same application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | ---------- | ------------------------ | ---- | --------------------------------------- | | agent | WantAgent | Yes | The first **WantAgent** object. | | otherAgent | WantAgent | Yes | The second **WantAgent** object. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent1; let wantAgent2; // getWantAgent callback function getWantAgentCallback(err, data) { console.info('==========================>getWantAgentCallback=======================>'); if (err.code == 0) { wantAgent1 = data; wantAgent2 = data; } else { console.info('----getWantAgent failed!----'); } } // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); // equal callback function equalCallback(err, data) { console.info('==========================>equalCallback=======================>'); } WantAgent.equal(wantAgent1, wantAgent2, equalCallback); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.equal equal(agent: WantAgent, otherAgent: WantAgent): Promise\ Checks whether two **WantAgent** objects are equal to determine whether the same operation is from the same application. This API uses a promise to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | ---------- | --------- | ---- | ------------- | | agent | WantAgent | Yes | The first **WantAgent** object.| | otherAgent | WantAgent | Yes | The second **WantAgent** object.| **Return value** | Type | Description | | ----------------------------------------------------------- | ------------------------------------------------------------ | | Promise\ | Promise used to return the result.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent1; let wantAgent2; // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo).then((data) => { console.info('==========================>getWantAgentCallback=======================>'); wantAgent1 = data; wantAgent2 = data; }); WantAgent.equal(wantAgent1, wantAgent2).then((data) => { console.info('==========================>equalCallback=======================>'); }); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.getOperationType getOperationType(agent: WantAgent, callback: AsyncCallback\): void; Obtains the operation type of a **WantAgent** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | ---------- | ------------------------ | ---- | --------------------------------------- | | agent | WantAgent | Yes | Target **WantAgent** object. | | callback | AsyncCallback\ | Yes | Callback used to return the operation type.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent; // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo).then((data) => { console.info('==========================>getWantAgentCallback=======================>'); wantAgent = data; }); WantAgent.getOperationType(wantAgent, (OperationType) => { console.log('----------- getOperationType ----------, OperationType: ' + OperationType); }) } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgent.getOperationType getOperationType(agent: WantAgent): Promise\; Obtains the operation type of a **WantAgent** object. This API uses a promise to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | ---------- | --------- | ---- | ------------- | | agent | WantAgent | Yes | Target **WantAgent** object.| **Return value** | Type | Description | | ----------------------------------------------------------- | ------------------------------------------------------------ | | Promise\ | Promise used to return the operation type.| **Example** ```js import WantAgent from '@ohos.app.ability.wantAgent'; // wantAgent object let wantAgent; // WantAgentInfo object let wantAgentInfo = { wants: [ { deviceId: 'deviceId', bundleName: 'com.neu.setResultOnAbilityResultTest1', abilityName: 'com.example.test.MainAbility', action: 'action1', entities: ['entity1'], type: 'MIMETYPE', uri: 'key={true,true,false}', parameters: { mykey0: 2222, mykey1: [1, 2, 3], mykey2: '[1, 2, 3]', mykey3: 'ssssssssssssssssssssssssss', mykey4: [false, true, false], mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], mykey6: true, } } ], operationType: WantAgent.OperationType.START_ABILITIES, requestCode: 0, wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; try { WantAgent.getWantAgent(wantAgentInfo).then((data) => { console.info('==========================>getWantAgentCallback=======================>'); wantAgent = data; }); WantAgent.getOperationType(wantAgent).then((OperationType) => { console.log('getOperationType success, OperationType: ' + OperationType); }).catch((err) => { console.log('getOperationType fail, err: ' + err); }) } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` ## WantAgentFlags **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Value | Description | | ------------------- | -------------- | ------------------------------------------------------------ | | ONE_TIME_FLAG | 0 | The **WantAgent** object can be used only once. | | NO_BUILD_FLAG | 1 | The **WantAgent** object does not exist and hence it is not created. In this case, **null** is returned. | | CANCEL_PRESENT_FLAG | 2 | The existing **WantAgent** object should be canceled before a new object is generated.| | UPDATE_PRESENT_FLAG | 3 | Extra information of the existing **WantAgent** object is replaced with that of the new object.| | CONSTANT_FLAG | 4 | The **WantAgent** object is immutable. | | REPLACE_ELEMENT | 5 | The **element** attribute of the current **Want** can be replaced by the **element** attribute of the **Want** in **WantAgent.trigger()**.| | REPLACE_ACTION | 6 | The **action** attribute of the current **Want** can be replaced by the **action** attribute of the **Want** in **WantAgent.trigger()**.| | REPLACE_URI | 7 | The **uri** attribute of the current **Want** can be replaced by the **uri** attribute of the **Want** in **WantAgent.trigger()**.| | REPLACE_ENTITIES | 8 | The **entities** attribute of the current **Want** can be replaced by the **entities** attribute of the **Want** in **WantAgent.trigger()**.| | REPLACE_BUNDLE | 9 | The **bundleName** attribute of the current **Want** can be replaced by the **bundleName** attribute of **Want** in **WantAgent.trigger()**.| ## OperationType **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Value | Description | | ----------------- | ------------- | ------------------------- | | UNKNOWN_TYPE | 0 | Unknown operation type. | | START_ABILITY | 1 | Starts an ability with a UI.| | START_ABILITIES | 2 | Starts multiple abilities with a UI.| | START_SERVICE | 3 | Starts an ability without a UI.| | SEND_COMMON_EVENT | 4 | Sends a common event. | ## CompleteData **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Type | Mandatory| Description | | -------------- | ------------------------------ | ---- | ---------------------- | | info | WantAgent | Yes | A triggered **WantAgent** object. | | want | Want | Yes | An existing triggered **want**. | | finalCode | number | Yes | Request code that triggers the **WantAgent** object.| | finalData | string | Yes | Final data collected by the common event. | | extraInfo | {[key: string]: any} | No | Extra information. |