# @ohos.app.ability.Want (Want) Want is a carrier for information transfer between objects (application components). Want can be used as a parameter of **startAbility** to specify a startup target and information that needs to be carried during startup, for example, **bundleName** and **abilityName**, which respectively indicate the bundle name of the target ability and the ability name in the bundle. When UIAbility A needs to start UIAbility B and transfer some data to UIAbility B, it can use Want a carrier to transfer the data. > **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 ```ts import Want from '@ohos.app.ability.Want'; ``` ## Attributes **System capability**: SystemCapability.Ability.AbilityBase | Name | Type | Mandatory| Description | | ----------- | -------------------- | ---- | ------------------------------------------------------------ | | deviceId | string | No | ID of the device running the ability. If this field is unspecified, the local device is used. | | bundleName | string | No | Bundle name of the ability.| | moduleName | string | No| Name of the module to which the ability belongs.| | abilityName | string | No | Name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can match a specific ability. The value of **abilityName** must be unique in an application.| | [action](js-apis-app-ability-wantConstant.md#wantconstantaction) | string | No | Action to take, such as viewing and sharing application details. In implicit Want, you can define this field and use it together with **uri** or **parameters** to specify the operation to be performed on the data. For details about the definition and matching rules of implicit Want, see [Matching Rules of Explicit Want and Implicit Want](../../application-models/explicit-implicit-want-mappings.md). | | [entities](js-apis-app-ability-wantConstant.md#wantconstantentity) | Array\ | No| Additional category information (such as browser and video player) of the ability. It is a supplement to the **action** field for implicit Want. and is used to filter ability types.| | uri | string | No| Data carried. This field is used together with **type** to specify the data type. If **uri** is specified in a Want, the Want will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path**.| | type | string | No| MIME type, that is, the type of the file to open, for example, **text/xml** and **image/***. For details about the MIME type definition, see https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com.| | parameters | {[key: string]: any} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:
- **ohos.aafwk.callerPid**: PID of the caller.
- **ohos.aafwk.param.callerToken**: token of the caller.
- **ohos.aafwk.param.callerUid**: UID in [BundleInfo](js-apis-bundleManager-bundleInfo.md#bundleinfo-1), that is, the application UID in the bundle information. | | [flags](js-apis-ability-wantConstant.md#wantconstantflags) | number | No| How the **Want** object will be handled. By default, a number is passed in.
For example, **wantConstant.Flags.FLAG_ABILITY_CONTINUATION** specifies whether to start the ability in cross-device migration scenarios.| **Example** - Basic usage (called in a UIAbility object, where context in the example is the context object of the UIAbility). ```ts let want = { "deviceId": "", // An empty deviceId indicates the local device. "bundleName": "com.example.myapplication", "abilityName": "FuncAbility", "moduleName": "entry" // moduleName is optional. }; this.context.startAbility(want, (error) => { // Start an ability explicitly. The bundleName, abilityName, and moduleName parameters work together to uniquely identify an ability. console.log("error.code = " + error.code) }) ``` - Data is transferred through user-defined fields. The following data types are supported (called in a UIAbility object, where context in the example is the context object of the UIAbility): * String ```ts let want = { bundleName: "com.example.myapplication", abilityName: "FuncAbility", parameters: { keyForString: "str", }, } ``` * Number ```ts let want = { bundleName: "com.example.myapplication", abilityName: "FuncAbility", parameters: { keyForInt: 100, keyForDouble: 99.99, }, } ``` * Boolean ```ts let want = { bundleName: "com.example.myapplication", abilityName: "FuncAbility", parameters: { keyForBool: true, }, } ``` * Object ```ts let want = { bundleName: "com.example.myapplication", abilityName: "FuncAbility", parameters: { keyForObject: { keyForObjectString: "str", keyForObjectInt: -200, keyForObjectDouble: 35.5, keyForObjectBool: false, }, }, } ``` * Array ```ts let want = { bundleName: "com.example.myapplication", abilityName: "FuncAbility", parameters: { keyForArrayString: ["str1", "str2", "str3"], keyForArrayInt: [100, 200, 300, 400], keyForArrayDouble: [0.1, 0.2], keyForArrayObject: [{obj1: "aaa"}, {obj2: 100}], }, } ``` * File descriptor (FD) ```ts import fileio from '@ohos.fileio'; let fd; try { fd = fileio.openSync("/data/storage/el2/base/haps/pic.png"); } catch(e) { console.log("openSync fail:" + JSON.stringify(e)); } let want = { "deviceId": "", // An empty deviceId indicates the local device. "bundleName": "com.example.myapplication", "abilityName": "FuncAbility", "moduleName": "entry", // moduleName is optional. "parameters": { "keyFd":{"type":"FD", "value":fd} } }; this.context.startAbility(want, (error) => { // Start an ability explicitly. The bundleName, abilityName, and moduleName parameters work together to uniquely identify an ability. console.log("error.code = " + error.code) }) ``` - For more details and examples, see [Want](../../application-models/want-overview.md).