js-apis-ability-context.md 15.0 KB
Newer Older
W
wusongqing 已提交
1 2
# AbilityContext

W
wusongqing 已提交
3 4
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
W
wusongqing 已提交
5 6


W
wusongqing 已提交
7
Implements the ability context. This module is inherited from **Context**.
W
wusongqing 已提交
8 9


W
wusongqing 已提交
10 11 12 13 14 15 16
## Usage


Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**.


  
W
wusongqing 已提交
17
```js
W
wusongqing 已提交
18 19 20 21 22 23 24 25 26
import Ability from '@ohos.application.Ability'
class MainAbility extends Ability {
    onWindowStageCreate(windowStage) {
        let context = this.context;
    }
}
```


W
wusongqing 已提交
27
## Attributes
W
wusongqing 已提交
28

W
wusongqing 已提交
29
| Name| Type| Readable| Writable| Description| 
W
wusongqing 已提交
30
| -------- | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
31 32
| abilityInfo | AbilityInfo | Yes| No| Ability information.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core| 
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core| 
W
wusongqing 已提交
33 34


W
wusongqing 已提交
35
## AbilityContext.startAbility
W
wusongqing 已提交
36 37 38

startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void

W
wusongqing 已提交
39
Starts an ability. This API uses a callback to return the result.
W
wusongqing 已提交
40

W
wusongqing 已提交
41
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
42

W
wusongqing 已提交
43
**Parameters**
W
wusongqing 已提交
44

W
wusongqing 已提交
45
  | Name| Type| Mandatory| Description| 
W
wusongqing 已提交
46
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
47 48
  | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| 
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| 
W
wusongqing 已提交
49

W
wusongqing 已提交
50 51 52
**Example**

  ```js
W
wusongqing 已提交
53 54 55 56 57 58 59 60 61 62 63
  var want = {
  	"deviceId": "",
  	"bundleName": "com.extreme.test",
  	"abilityName": "com.extreme.test.MainAbility"
  };
  this.context.startAbility(want, (error) => {
      console.log("error.code = " + error.code)
  })
  ```


W
wusongqing 已提交
64
## AbilityContext.startAbility
W
wusongqing 已提交
65

W
wusongqing 已提交
66 67
startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void

W
wusongqing 已提交
68
Starts an ability. This API uses a callback to return the result.
W
wusongqing 已提交
69

W
wusongqing 已提交
70
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
71

W
wusongqing 已提交
72
**Parameters**
W
wusongqing 已提交
73

W
wusongqing 已提交
74
  | Name| Type| Mandatory| Description| 
W
wusongqing 已提交
75 76 77 78 79
  | -------- | -------- | -------- | -------- |
  | want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 
  | options | StartOptions | Yes| Parameters used for starting the ability.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| 

W
wusongqing 已提交
80
**Example**
W
wusongqing 已提交
81
    
W
wusongqing 已提交
82
  ```js
W
wusongqing 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96
  var want = {
  	"deviceId": "",
  	"bundleName": "com.extreme.test",
  	"abilityName": "com.extreme.test.MainAbility"
  };
  var options = {
  	windowMode: 0,
  };
  this.context.startAbility(want, options, (error) => {
      console.log("error.code = " + error.code)
  })
  ```


W
wusongqing 已提交
97
## AbilityContext.startAbility
W
wusongqing 已提交
98

W
wusongqing 已提交
99
startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
W
wusongqing 已提交
100

W
wusongqing 已提交
101
Starts an ability. This API uses a promise to return the result.
W
wusongqing 已提交
102

W
wusongqing 已提交
103
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
104

W
wusongqing 已提交
105
**Parameters**
W
wusongqing 已提交
106

W
wusongqing 已提交
107
  | Name| Type| Mandatory| Description| 
W
wusongqing 已提交
108
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
109
  | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| 
W
wusongqing 已提交
110 111 112
  | options | StartOptions | No| Parameters used for starting the ability.|

**Return value**
W
wusongqing 已提交
113

W
wusongqing 已提交
114
  | Type| Description| 
W
wusongqing 已提交
115
  | -------- | -------- |
W
wusongqing 已提交
116
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
117

W
wusongqing 已提交
118 119 120
**Example**

  ```js
W
wusongqing 已提交
121 122 123 124 125
  var want = {
  	"deviceId": "",
  	"bundleName": "com.extreme.test",
  	"abilityName": "com.extreme.test.MainAbility"
  };
W
wusongqing 已提交
126 127 128 129
  var options = {
  	windowMode: 0,
  };
  this.context.startAbility(want, options)
W
wusongqing 已提交
130 131 132 133 134 135 136 137
  .then((data) => {
      console.log('Operation successful.')
  }).catch((error) => {
      console.log('Operation failed.');
  })
  ```


W
wusongqing 已提交
138
## AbilityContext.startAbilityForResult
W
wusongqing 已提交
139 140 141

startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): void;

W
wusongqing 已提交
142
Starts an ability. This API uses a callback to return the execution result when the ability is terminated.
W
wusongqing 已提交
143

W
wusongqing 已提交
144
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
145

W
wusongqing 已提交
146
**Parameters**
W
wusongqing 已提交
147

W
wusongqing 已提交
148
  | Name| Type| Mandatory| Description|
W
wusongqing 已提交
149
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
150
  | want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
W
wusongqing 已提交
151
  | callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
152 153


W
wusongqing 已提交
154 155 156
**Example**

  ```js
W
wusongqing 已提交
157 158 159 160 161 162 163 164 165
  this.context.startAbilityForResult(
      {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"},
      (error, result) => {
          console.log("startAbilityForResult AsyncCallback is called, error.code = " + error.code)
          console.log("startAbilityForResult AsyncCallback is called, result.resultCode = " + result.resultCode)
       }
  );
  ```

W
wusongqing 已提交
166
## AbilityContext.startAbilityForResult
W
wusongqing 已提交
167 168 169

startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void;

W
wusongqing 已提交
170
Starts an ability. This API uses a callback to return the execution result when the ability is terminated.
W
wusongqing 已提交
171

W
wusongqing 已提交
172
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
173

W
wusongqing 已提交
174
**Parameters**
W
wusongqing 已提交
175 176 177 178 179 180 181 182

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
  | options | StartOptions | Yes| Parameters used for starting the ability.|
  | callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|


W
wusongqing 已提交
183 184 185
**Example**

  ```js
W
wusongqing 已提交
186 187 188 189 190 191 192 193 194 195 196 197
  var options = {
    windowMode: 0,
  };
  this.context.startAbilityForResult(
      {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, options,
      (error, result) => {
          console.log("startAbilityForResult AsyncCallback is called, error.code = " + error.code)
          console.log("startAbilityForResult AsyncCallback is called, result.resultCode = " + result.resultCode)
       }
  );
  ```

W
wusongqing 已提交
198

W
wusongqing 已提交
199
## AbilityContext.startAbilityForResult
W
wusongqing 已提交
200

W
wusongqing 已提交
201
startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityResult&gt;;
W
wusongqing 已提交
202

W
wusongqing 已提交
203
Starts an ability. This API uses a promise to return the execution result when the ability is terminated.
W
wusongqing 已提交
204

W
wusongqing 已提交
205
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
206

W
wusongqing 已提交
207
**Parameters**
W
wusongqing 已提交
208

W
wusongqing 已提交
209
  | Name| Type| Mandatory| Description| 
W
wusongqing 已提交
210
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
211
  | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
W
wusongqing 已提交
212
  | options | StartOptions | No| Parameters used for starting the ability.|
W
wusongqing 已提交
213

W
wusongqing 已提交
214

W
wusongqing 已提交
215 216
**Return value**

W
wusongqing 已提交
217
  | Type| Description|
W
wusongqing 已提交
218
  | -------- | -------- |
W
wusongqing 已提交
219
  | Promise&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Promise used to return the result.|
W
wusongqing 已提交
220

W
wusongqing 已提交
221 222 223
**Example**

  ```js
W
wusongqing 已提交
224 225 226 227
  var options = {
    windowMode: 0,
  };
  this.context.startAbilityForResult({bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, options).then((result) => {
W
wusongqing 已提交
228 229 230 231 232 233 234
      console.log("startAbilityForResult Promise.resolve is called, result.resultCode = " + result.resultCode)
  }, (error) => {
      console.log("startAbilityForResult Promise.Reject is called, error.code = " + error.code)
  })
  ```


W
wusongqing 已提交
235
## AbilityContext.terminateSelf
W
wusongqing 已提交
236 237 238

terminateSelf(callback: AsyncCallback&lt;void&gt;): void;

W
wusongqing 已提交
239
Terminates this ability. This API uses a callback to return the result.
W
wusongqing 已提交
240

W
wusongqing 已提交
241
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
242

W
wusongqing 已提交
243
**Parameters**
W
wusongqing 已提交
244

W
wusongqing 已提交
245
  | Name| Type| Mandatory| Description| 
W
wusongqing 已提交
246
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
247
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
248

W
wusongqing 已提交
249 250 251
**Example**

  ```js
W
wusongqing 已提交
252
  this.context.terminateSelf((err) => {
W
wusongqing 已提交
253 254
      console.log('terminateSelf result:' + JSON.stringfy(err));
  });
W
wusongqing 已提交
255 256 257
  ```


W
wusongqing 已提交
258
## AbilityContext.terminateSelf
W
wusongqing 已提交
259 260 261

terminateSelf(): Promise&lt;void&gt;;

W
wusongqing 已提交
262
Terminates this ability. This API uses a promise to return the result.
W
wusongqing 已提交
263

W
wusongqing 已提交
264
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
265

W
wusongqing 已提交
266
**Return value**
W
wusongqing 已提交
267

W
wusongqing 已提交
268
  | Type| Description| 
W
wusongqing 已提交
269
  | -------- | -------- |
W
wusongqing 已提交
270
  | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
271

W
wusongqing 已提交
272 273 274
**Example**

  ```js
W
wusongqing 已提交
275 276
  this.context.terminateSelf(want).then((data) => {
      console.log('success:' + JSON.stringfy(data));
W
wusongqing 已提交
277
  }).catch((error) => {
W
wusongqing 已提交
278 279 280 281 282
      console.log('failed:' + JSON.stringfy(error));
  });
  ```


W
wusongqing 已提交
283
## AbilityContext.terminateSelfWithResult
W
wusongqing 已提交
284 285 286

terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void;

W
wusongqing 已提交
287
Terminates this ability. This API uses a callback to return the information to the caller of **startAbilityForResult**.
W
wusongqing 已提交
288

W
wusongqing 已提交
289
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
290

W
wusongqing 已提交
291
**Parameters**
W
wusongqing 已提交
292

W
wusongqing 已提交
293
  | Name| Type| Mandatory| Description|
W
wusongqing 已提交
294
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
295
  | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
W
wusongqing 已提交
296
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
297

W
wusongqing 已提交
298 299 300
**Example**

  ```js
W
wusongqing 已提交
301 302 303 304 305 306 307 308 309 310 311
  this.context.terminateSelfWithResult(
     {
          want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
          resultCode: 100
      }, (error) => {
          console.log("terminateSelfWithResult is called = " + error.code)
      }
  );
  ```


W
wusongqing 已提交
312
## AbilityContext.terminateSelfWithResult
W
wusongqing 已提交
313 314 315

terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;

W
wusongqing 已提交
316
Terminates this ability. This API uses a promise to return information to the caller of **startAbilityForResult**.
W
wusongqing 已提交
317

W
wusongqing 已提交
318
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
319

W
wusongqing 已提交
320
**Parameters**
W
wusongqing 已提交
321

W
wusongqing 已提交
322
  | Name| Type| Mandatory| Description|
W
wusongqing 已提交
323
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
324
  | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
W
wusongqing 已提交
325

W
wusongqing 已提交
326 327
**Return value**

W
wusongqing 已提交
328
  | Type| Description| 
W
wusongqing 已提交
329
  | -------- | -------- |
W
wusongqing 已提交
330
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
331

W
wusongqing 已提交
332 333 334
**Example**

  ```js
W
wusongqing 已提交
335 336 337 338 339 340 341 342 343
  this.context.terminateSelfWithResult(
  {
      want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
      resultCode: 100
  }).then((result) => {
      console.log("terminateSelfWithResult")
  }
  )
  ```
W
wusongqing 已提交
344 345


W
wusongqing 已提交
346
## AbilityContext.startAbilityByCall
W
wusongqing 已提交
347 348 349 350 351

startAbilityByCall(want: Want): Promise&lt;Caller&gt;;

Obtains the caller interface of the specified ability, and if the specified ability is not started, starts the ability in the background.

W
wusongqing 已提交
352
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
353

W
wusongqing 已提交
354
**Parameters**
W
wusongqing 已提交
355

W
wusongqing 已提交
356
  | Name| Type| Mandatory| Description| 
W
wusongqing 已提交
357 358 359
  | -------- | -------- | -------- | -------- |
  | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.| 

W
wusongqing 已提交
360 361 362
**Return value**

  | Type| Description| 
W
wusongqing 已提交
363
  | -------- | -------- |
W
wusongqing 已提交
364
  | Promise&lt;Caller&gt; | Promise used to return the caller object to communicate with.| 
W
wusongqing 已提交
365

W
wusongqing 已提交
366
**Example**
W
wusongqing 已提交
367
    
W
wusongqing 已提交
368
  ```js
W
wusongqing 已提交
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
  import Ability from '@ohos.application.Ability';
  var caller;
  export default class MainAbility extends Ability {
      onWindowStageCreate(windowStage) {
          this.context.startAbilityByCall({
              bundleName: "com.example.myservice",
              abilityName: "com.example.myservice.MainAbility",
              deviceId: ""
          }).then((obj) => {
              caller = obj;
              console.log('Caller GetCaller Get ' + call);
          }).catch((e) => {
              console.log('Caller GetCaller error ' + e);
          });
      }
  }
  ```


W
wusongqing 已提交
388
## AbilityContext.requestPermissionsFromUser
W
wusongqing 已提交
389 390 391

requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void;

W
wusongqing 已提交
392
Requests permissions from the user by displaying a pop-up window. This API uses a callback to return the result.
W
wusongqing 已提交
393

W
wusongqing 已提交
394
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
395

W
wusongqing 已提交
396
**Parameters**
W
wusongqing 已提交
397

W
wusongqing 已提交
398
  | Name| Type| Mandatory| Description| 
W
wusongqing 已提交
399 400
  | -------- | -------- | -------- | -------- |
  | permissions | Array&lt;string&gt; | Yes| Permissions to request.| 
W
wusongqing 已提交
401
  | callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
402

W
wusongqing 已提交
403
**Example**
W
wusongqing 已提交
404 405 406 407 408 409 410 411
    
  ```
  this.context.requestPermissionsFromUser(permissions,(result) => {
      console.log('requestPermissionsFromUserresult:' + JSON.stringfy(result));
  });
  ```


W
wusongqing 已提交
412
## AbilityContext.requestPermissionsFromUser
W
wusongqing 已提交
413 414 415

requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;PermissionRequestResult&gt;;

W
wusongqing 已提交
416
Requests permissions from the user by displaying a pop-up window. This API uses a promise to return the result.
W
wusongqing 已提交
417

W
wusongqing 已提交
418
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
419

W
wusongqing 已提交
420
**Parameters**
W
wusongqing 已提交
421

W
wusongqing 已提交
422
  | Name| Type| Mandatory| Description| 
W
wusongqing 已提交
423
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
424 425 426
  | permissions | Array&lt;string&gt; | Yes| Permissions to request.|

**Return value**
W
wusongqing 已提交
427

W
wusongqing 已提交
428
  | Type| Description| 
W
wusongqing 已提交
429
  | -------- | -------- |
W
wusongqing 已提交
430
  | Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
431

W
wusongqing 已提交
432
**Example**
W
wusongqing 已提交
433 434 435 436 437 438 439 440 441 442
    
  ```
  this.context.requestPermissionsFromUser(permissions).then((data) => {
      console.log('success:' + JSON.stringfy(data));
  }).catch((error) => {
      console.log('failed:' + JSON.stringfy(error));
  });
  ```


W
wusongqing 已提交
443
## AbilityContext.setMissionLabel
W
wusongqing 已提交
444 445 446

setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void;

W
wusongqing 已提交
447
Sets the label of the ability displayed in the task. This API uses a callback to return the result.
W
wusongqing 已提交
448

W
wusongqing 已提交
449
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
450

W
wusongqing 已提交
451
**Parameters**
W
wusongqing 已提交
452

W
wusongqing 已提交
453
  | Name| Type| Mandatory| Description| 
W
wusongqing 已提交
454 455
  | -------- | -------- | -------- | -------- |
  | label | string | Yes| Label of the ability to set.| 
W
wusongqing 已提交
456
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
457

W
wusongqing 已提交
458
**Example**
W
wusongqing 已提交
459
    
W
wusongqing 已提交
460
  ```js
W
wusongqing 已提交
461 462 463 464 465 466
  this.context.setMissionLabel("test",(result) => {
      console.log('requestPermissionsFromUserresult:' + JSON.stringfy(result));
  });
  ```


W
wusongqing 已提交
467
## AbilityContext.setMissionLabel
W
wusongqing 已提交
468 469 470

setMissionLabel(label: string): Promise&lt;void&gt;

W
wusongqing 已提交
471
Sets the label of the ability displayed in the task. This API uses a promise to return the result.
W
wusongqing 已提交
472

W
wusongqing 已提交
473
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
474

W
wusongqing 已提交
475
**Parameters**
W
wusongqing 已提交
476

W
wusongqing 已提交
477
  | Name| Type| Mandatory| Description| 
W
wusongqing 已提交
478 479 480
  | -------- | -------- | -------- | -------- |
  | label | string | Yes| Label of the ability to set.| 

W
wusongqing 已提交
481 482 483
**Return value**

  | Type| Description| 
W
wusongqing 已提交
484
  | -------- | -------- |
W
wusongqing 已提交
485
  | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
486

W
wusongqing 已提交
487
**Example**
W
wusongqing 已提交
488
    
W
wusongqing 已提交
489
  ```js
W
wusongqing 已提交
490 491 492 493 494 495
  this.context.setMissionLabel("test").then((data) => {
      console.log('success:' + JSON.stringfy(data));
  }).catch((error) => {
      console.log('failed:' + JSON.stringfy(error));
  });
  ```