提交 24315894 编写于 作者: G Gloria

Update docs against 15844+15899+15735

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 5cc343cf
......@@ -14,7 +14,7 @@ import wantConstant from '@ohos.ability.wantConstant';
## wantConstant.Action
Enumerates the action constants of the **Want** object. **action** specifies the operation to execute.
Enumerates the action constants of the **Want** object.
**System capability**: SystemCapability.Ability.AbilityBase
......@@ -46,18 +46,11 @@ Enumerates the action constants of the **Want** object. **action** specifies the
| ACTION_FILE_SELECT<sup>7+</sup> | ohos.action.fileSelect | Action of selecting a file. |
| PARAMS_STREAM<sup>7+</sup> | ability.params.stream | URI of the data stream associated with the target when the data is sent. The value must be an array of the string type. |
| ACTION_APP_ACCOUNT_OAUTH <sup>8+</sup> | ohos.account.appAccount.action.oauth | Action of providing the OAuth service. |
| ACTION_APP_ACCOUNT_AUTH <sup>9+</sup> | account.appAccount.action.auth | Action of providing the authentication service. |
| ACTION_MARKET_DOWNLOAD <sup>9+</sup> | ohos.want.action.marketDownload | Action of downloading an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| ACTION_MARKET_CROWDTEST <sup>9+</sup> | ohos.want.action.marketCrowdTest | Action of crowdtesting an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_SANDBOX<sup>9+</sup> |ohos.dlp.params.sandbox | Action of obtaining the sandbox flag.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_BUNDLE_NAME<sup>9+</sup> |ohos.dlp.params.bundleName |Action of obtaining the DLP bundle name.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_MODULE_NAME<sup>9+</sup> |ohos.dlp.params.moduleName |Action of obtaining the DLP module name.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_ABILITY_NAME<sup>9+</sup> |ohos.dlp.params.abilityName |Action of obtaining the DLP ability name.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_INDEX<sup>9+</sup> |ohos.dlp.params.index |Action of obtaining the DLP index.<br>**System API**: This is a system API and cannot be called by third-party applications. |
## wantConstant.Entity
Enumerates the entity constants of the **Want** object. **entity** specifies additional information of the target ability.
Enumerates the entity constants of the **Want** object.
**System capability**: SystemCapability.Ability.AbilityBase
......
......@@ -99,7 +99,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onContinue(wantParam) {
return AbilityConstant.OnConinueResult.AGREE;
return AbilityConstant.OnContinueResult.AGREE;
}
}
```
......@@ -132,7 +132,7 @@ let option = {
};
// Ensure that the context is obtained.
this.context.startAbility(want, option).then(()={
this.context.startAbility(want, option).then(()=>{
console.log('Succeed to start ability.');
}).catch((error)=>{
console.log('Failed to start ability with error: ' + JSON.stringify(error));
......
......@@ -275,7 +275,7 @@ export default class MyFirstAbility extends UIAbility {
// 2. Register the listener for the ability lifecycle changes through the applicationContext object.
try {
globalThis.lifecycleId = applicationContext.on('abilityLifecycle', abilityLifecycleCallback);
console.log('registerAbilityLifecycleCallback number: ' + JSON.stringify(lifecycleId));
console.log('registerAbilityLifecycleCallback lifecycleId: ${globalThis.lifecycleId}');
} catch (paramError) {
console.log('error: ' + paramError.code + ' ,' + paramError.message);
}
......@@ -285,7 +285,7 @@ export default class MyFirstAbility extends UIAbility {
MySecondAbility.ts
```ts
import UIAbility from 'ohos.app.ability.UIAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
export default class MySecondAbility extends UIAbility {
onDestroy() {
......
......@@ -59,12 +59,13 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
```ts
import abilityManager from '@ohos.app.ability.abilityManager';
import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
const config = {
language: 'Zh-Hans', // Simplified Chinese.
colorMode: COLOR_MODE_LIGHT, // Light theme.
direction: DIRECTION_VERTICAL, // Vertical direction.
screenDensity: SCREEN_DENSITY_SDPI, // The screen pixel density is 'sdpi'.
colorMode: ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT, // Light theme.
direction: ConfigurationConstant.Direction.DIRECTION_VERTICAL, // Vertical direction.
screenDensity: ConfigurationConstant.ScreenDensity.SCREEN_DENSITY_SDPI, // The screen pixel density is 'sdpi'.
displayId: 1, // The application is displayed on the display with ID 1.
hasPointerDevice: true, // A pointer device is connected.
};
......@@ -117,12 +118,13 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
```ts
import abilityManager from '@ohos.app.ability.abilityManager';
import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
const config = {
language: 'Zh-Hans', // Simplified Chinese.
colorMode: COLOR_MODE_LIGHT, // Light theme.
direction: DIRECTION_VERTICAL, // Vertical direction.
screenDensity: SCREEN_DENSITY_SDPI, // The screen pixel density is 'sdpi'.
colorMode: ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT, // Light theme.
direction: ConfigurationConstant.Direction.DIRECTION_VERTICAL, // Vertical direction.
screenDensity: ConfigurationConstant.ScreenDensity.SCREEN_DENSITY_SDPI, // The screen pixel density is 'sdpi'.
displayId: 1, // The application is displayed on the display with ID 1.
hasPointerDevice: true, // A pointer device is connected.
};
......
......@@ -459,7 +459,7 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
```ts
import appManager from '@ohos.app.ability.appManager';
let observeId = 0;
let observerId = 0;
// 1. Register an application state observer.
let applicationStateObserver = {
......@@ -540,7 +540,7 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
```ts
import appManager from '@ohos.app.ability.appManager';
let observeId = 0;
let observerId = 0;
// 1. Register an application state observer.
let applicationStateObserver = {
......
......@@ -72,9 +72,9 @@ import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate() {
appRecovery.enableAppRecovery(
appRecovery.RestartFlag::ALWAYS_RESTART,
appRecovery.SaveOccasionFlag::SAVE_WHEN_ERROR,
appRecovery.SaveModeFlag::SAVE_WITH_FILE
appRecovery.RestartFlag.ALWAYS_RESTART,
appRecovery.SaveOccasionFlag.SAVE_WHEN_ERROR,
appRecovery.SaveModeFlag.SAVE_WITH_FILE
);
}
}
......
......@@ -24,7 +24,6 @@ import common from '@ohos.app.ability.common';
| Context | [Context](js-apis-inner-application-context.md) | Level-2 module **Context**.|
| ExtensionContext | [ExtensionContext](js-apis-inner-application-extensionContext.md) | Level-2 module **ExtensionContext**.|
| FormExtensionContext | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | Level-2 module **FormExtensionContext**.|
| AreaMode | [AreaMode](#areamode) | Enumerated values of **AreaMode**.|
| EventHub | [EventHub](js-apis-inner-application-eventHub.md) | Level-2 module **EventHub**.|
| PermissionRequestResult | [PermissionRequestResult](js-apis-inner-application-permissionRequestResult.md) | Level-2 module **PermissionRequestResult**.|
| PacMap | [PacMap](js-apis-inner-ability-dataAbilityHelper.md#PacMap) | Level-2 module **PacMap**.|
......@@ -42,7 +41,6 @@ let baseContext: common.BaseContext;
let context: common.Context;
let extensionContext: common.ExtensionContext;
let formExtensionContext: common.FormExtensionContext;
let areaMode: common.AreaMode;
let eventHub: common.EventHub;
let permissionRequestResult: common.PermissionRequestResult;
let pacMap: common.PacMap;
......
# @ohos.app.ability.dataUriUtils (DataUriUtils)
The **DataUriUtils** module provides APIs to process URI objects. You can use the APIs to attach an ID to the end of a given URI and obtain, delete, or update the ID attached to the end of a given URI.
> **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 dataUriUtils from '@ohos.app.ability.dataUriUtils';
```
## dataUriUtils.getId
getId(uri: string): number
Obtains the ID attached to the end of a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| uri | string | Yes | Target URI object.|
**Return value**
| Type | Description |
| ------ | ------------------------ |
| number | ID obtained.|
**Example**
```ts
try {
let id = dataUriUtils.getId('com.example.dataUriUtils/1221');
console.info('get id: ${id}');
} catch(err) {
console.error('get id err ,check the uri ${err}');
}
```
## dataUriUtils.attachId
attachId(uri: string, id: number): string
Attaches an ID to the end of a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| uri | string | Yes | Target URI object.|
| id | number | Yes | ID to be attached. |
**Return value**
| Type | Description |
| ------ | --------------------- |
| string | URI object with the ID attached.|
**Example**
```ts
let id = 1122;
try {
let uri = dataUriUtils.attachId(
'com.example.dataUriUtils',
id,
);
console.info('attachId the uri is: ${uri}');
} catch (err) {
console.error('get id err ,check the uri ${err}');
}
```
## dataUriUtils.deleteId
deleteId(uri: string): string
Deletes the ID from the end of a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| uri | string | Yes | URI object from which the ID is to be deleted.|
**Return value**
| Type | Description |
| ------ | ------------------- |
| string | URI object with the ID deleted.|
**Example**
```ts
try {
let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221');
console.info('delete id with the uri is: ${uri}');
} catch(err) {
console.error('delete uri err, check the input uri ${err}');
}
```
## dataUriUtils.updateId
updateId(uri: string, id: number): string
Updates the ID in a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ------------------- |
| uri | string | Yes | Target URI object.|
| id | number | Yes | New ID. |
**Return value**
| Type | Description |
| ------ | --------------- |
| string | URI object with the new ID.|
**Example**
```ts
try {
let id = 1122;
let uri = dataUriUtils.updateId(
'com.example.dataUriUtils/1221',
id
);
} catch (err) {
console.error('delete uri err, check the input uri ${err}');
}
```
# @ohos.app.ability.dialogRequest (dialogRequest)
The **dialogRequest** module provides APIs related to modal dialog box processing, including obtaining the request information (used to bind a modal dialog box) and request callback (used to set the request result).
A modal dialog box is a system pop-up box that intercepts events (such as mouse, keyboard, and touchscreen events) triggered for the page displayed under it. The page can be operated only after the modal dialog box is destroyed.
> **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.
> - The APIs provided by this module are used in ServiceExtensionAbilities. For a ServiceExtensionAbility that implements modal dialog boxes, you can use the APIs to obtain the request information and request callback and return the request result.
## Modules to Import
```js
import dialogRequest from '@ohos.app.ability.dialogRequest';
```
## dialogRequest.getRequestInfo
getRequestInfo(want: Want): RequestInfo
Obtains the request information from Want.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| want | [Want](js-apis-application-want.md) | Yes | Want passed in the request for a modal dialog box.|
**Return value**
| Type | Description |
| ------ | ------------------------ |
| [RequestInfo](#requestinfo) | **RequestInfo** object obtained, which is used to bind a modal dialog box.|
**Example**
```ts
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest';
export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) {
console.info(TAG, `onCreate, want: ${want.abilityName}`);
}
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestInfo = dialogRequest.getRequestInfo(want);
} catch(err) {
console.error('getRequestInfo err= ${JSON.stringify(err)}');
}
}
onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`);
}
onDisconnect(want) {
console.info(TAG, `onDisconnect, want: ${want.abilityName}`);
}
onDestroy() {
console.info(TAG, `onDestroy`);
}
}
```
## dialogRequest.getRequestCallback
getRequestCallback(want: Want): RequestCallback
Obtains the request callback from Want.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| want | [Want](js-apis-application-want.md) | Yes | Want passed in the request for a modal dialog box.|
**Return value**
| Type | Description |
| ------ | ------------------------ |
| [RequestCallback](#requestcallback) | **RequestCallback** object obtained, which is used to set the return result.|
**Example**
```ts
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest';
export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) {
console.info(TAG, `onCreate, want: ${want.abilityName}`);
}
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestCallback = dialogRequest.getRequestCallback(want);
} catch(err) {
console.error('getRequestInfo err= ${JSON.stringify(err)}');
}
}
onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`);
}
onDisconnect(want) {
console.info(TAG, `onDisconnect, want: ${want.abilityName}`);
}
onDestroy() {
console.info(TAG, `onDestroy`);
}
}
```
## RequestInfo
Defines the request information, which is used as an input parameter for binding the modal dialog box.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
```ts
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest';
import window from '@ohos.window';
export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) {
console.info(TAG, `onCreate, want: ${want.abilityName}`);
}
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestInfo = dialogRequest.getRequestInfo(want);
window.bindDialogTarget(requestInfo, () => {
console.info('Dialog Window Need Destroy.');
}, (err) => {
if (err.code) {
console.error('Failed to bind dialog target. Cause: ${JSON.stringify(err)}');
return;
}
console.info('Succeeded in binding dialog target.');
});
} catch(err) {
console.error('getRequestInfo err= ${JSON.stringify(err)}');
}
}
onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`);
}
onDisconnect(want) {
console.info(TAG, `onDisconnect, want: ${want.abilityName}`);
}
onDestroy() {
console.info(TAG, `onDestroy`);
}
}
```
## ResultCode
Enumerates the result codes of the request for the modal dialog box.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name | Value | Description |
| ------------ | ------------------ | ---------------------- |
| RESULT_OK | 0 | The request succeeds. |
| RESULT_CANCEL | 1 | The request fails. |
## RequestResult
Defines the result of the request for the modal dialog box. Only the result code is included.
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| result | [ResultCode](#resultcode) | Yes| Yes| Result code of the request.|
## RequestCallback
Provides a callback for setting the modal dialog box request result.
### RequestCallback.setRequestResult
setRequestResult(result: RequestResult): void;
Sets the result of the request for the modal dialog box.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| result | [RequestResult](#requestresult) | Yes| Request result to set.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest';
export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) {
console.info(TAG, `onCreate, want: ${want.abilityName}`);
}
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestCallback = dialogRequest.getRequestCallback(want);
let myResult = {
result : dialogRequest.ResultCode.RESULT_CANCEL,
};
requestCallback.setRequestResult(myResult);
} catch(err) {
console.error('getRequestInfo err= ${JSON.stringify(err)}');
}
}
onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`);
}
onDisconnect(want) {
console.info(TAG, `onDisconnect, want: ${want.abilityName}`);
}
onDestroy() {
console.info(TAG, `onDestroy`);
}
}
```
......@@ -35,7 +35,7 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
Called when the system memory level changes.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
......@@ -47,11 +47,11 @@ Called when the system memory level changes.
```ts
import Ability from '@ohos.application.Ability';
import UIAbility from '@ohos.app.ability.UIAbility';
let callbackId;
export default class MyAbility extends Ability {
export default class MyAbility extends UIAbility {
onCreate() {
console.log('MyAbility onCreate');
globalThis.applicationContext = this.context.getApplicationContext();
......
......@@ -43,20 +43,63 @@ Registers a listener to observe the mission status.
**Example**
```ts
let listener = {
import missionManager from '@ohos.app.ability.missionManager';
import UIAbility from '@ohos.app.ability.UIAbility';
let listener = {
onMissionCreated: function (mission) {console.log('--------onMissionCreated-------');},
onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------');},
onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------');},
onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------');},
onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------');},
onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');}
};
console.log('registerMissionListener');
onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');},
onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');}
};
let listenerId = -1;
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('[Demo] EntryAbility onCreate');
globalThis.abilityWant = want;
globalThis.context = this.context;
}
onDestroy() {
try {
if (listenerId !== -1) {
missionManager.off('mission', listenerId).catch(function (err) {
console.log(err);
});
}
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
}
console.log('[Demo] EntryAbility onDestroy');
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log('[Demo] EntryAbility onWindowStageCreate');
try {
let listenerid = missionManager.on('mission', listener);
listenerId = missionManager.on('mission', listener);
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
console.error('error: ${paramError.code}, ${paramError.message}');
}
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause: ${JSON.stringify(err)}');
return;
}
console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}');
});
if (globalThis.flag) {
return;
}
}
};
```
......@@ -82,24 +125,63 @@ Deregisters a mission status listener.
**Example**
```ts
let listener = {
import missionManager from '@ohos.app.ability.missionManager';
import UIAbility from '@ohos.app.ability.UIAbility';
let listener = {
onMissionCreated: function (mission) {console.log('--------onMissionCreated-------');},
onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------');},
onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------');},
onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------');},
onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------');},
onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');}
};
console.log('registerMissionListener');
try {
let listenerid = missionManager.registerMissionListener(listener);
onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');},
onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');}
};
missionManager.unregisterMissionListener(listenerid, (error) => {
console.log('unregisterMissionListener');
let listenerId = -1;
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('[Demo] EntryAbility onCreate');
globalThis.abilityWant = want;
globalThis.context = this.context;
}
onDestroy() {
try {
if (listenerId !== -1) {
missionManager.off('mission', listenerId, (err) => {
console.log(err);
});
}
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
console.error('error: ${paramError.code}, ${paramError.message}');
}
console.log('[Demo] EntryAbility onDestroy');
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log('[Demo] EntryAbility onWindowStageCreate');
try {
listenerId = missionManager.on('mission', listener);
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
}
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause: ${JSON.stringify(err)}');
return;
}
console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}');
});
if (globalThis.flag) {
return;
}
}
};
```
......@@ -130,24 +212,63 @@ Deregisters a mission status listener. This API uses a promise to return the res
**Example**
```ts
let listener = {
import missionManager from '@ohos.app.ability.missionManager';
import UIAbility from '@ohos.app.ability.UIAbility';
let listener = {
onMissionCreated: function (mission) {console.log('--------onMissionCreated-------');},
onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------');},
onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------');},
onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------');},
onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------');},
onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');}
};
console.log('registerMissionListener');
try {
let listenerid = missionManager.registerMissionListener(listener);
onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');},
onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');}
};
missionManager.unregisterMissionListener(listenerid).catch(function (err) {
let listenerId = -1;
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('[Demo] EntryAbility onCreate');
globalThis.abilityWant = want;
globalThis.context = this.context;
}
onDestroy() {
try {
if (listenerId !== -1) {
missionManager.off('mission', listenerId).catch(function (err) {
console.log(err);
});
}
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
console.error('error: ${paramError.code}, ${paramError.message}');
}
console.log('[Demo] EntryAbility onDestroy');
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log('[Demo] EntryAbility onWindowStageCreate');
try {
listenerId = missionManager.on('mission', listener);
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
}
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause: ${JSON.stringify(err)}');
return;
}
console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}');
});
if (globalThis.flag) {
return;
}
}
};
```
......
......@@ -106,7 +106,7 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal
## ServiceExtensionAbility.onConnect
onConnect(want: Want): rpc.RemoteObject;
onConnect(want: Want): rpc.RemoteObject | Promise<rpc.RemoteObject>;
Called following **onCreate()** when a ServiceExtensionAbility is started by calling **connectAbility()**. A **RemoteObject** object is returned for communication between the server and client.
......@@ -148,7 +148,7 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal
## ServiceExtensionAbility.onDisconnect
onDisconnect(want: Want): void;
onDisconnect(want: Want): void | Promise<void>;
Called when this ServiceExtensionAbility is disconnected.
......
......@@ -125,7 +125,7 @@ Called when the **WindowStage** is restored during the migration of this ability
## Ability.onDestroy
onDestroy(): void;
onDestroy(): void | Promise&lt;void&gt;;
Called when this ability is destroyed to clear resources.
......@@ -182,7 +182,7 @@ Called when this ability is switched from the foreground to the background.
## Ability.onContinue
onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
onContinue(wantParam: { [key: string]: Object }): AbilityConstant.OnContinueResult;
Called to save data during the ability migration preparation process.
......@@ -204,7 +204,7 @@ Called to save data during the ability migration preparation process.
```ts
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
class MyUIAbility extends Ability {
onContinue(wantParams) {
console.log('onContinue');
wantParams['myData'] = 'my1234567';
......@@ -232,7 +232,7 @@ Called when a new Want is passed in and this ability is started again.
**Example**
```ts
class MyUIAbility extends UIAbility {
class MyUIAbility extends Ability {
onNewWant(want, launchParams) {
console.log('onNewWant, want:' + want.abilityName);
console.log('onNewWant, launchParams:' + JSON.stringify(launchParams));
......@@ -268,7 +268,7 @@ Dumps client information.
## Ability.onSaveState
onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: any}): AbilityConstant.OnSaveResult;
onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: Object}): AbilityConstant.OnSaveResult;
Called when the framework automatically saves the ability state in the case of an application fault. This API is used together with [appRecovery](js-apis-app-ability-appRecovery.md). If automatic state saving is enabled, **onSaveState** is called to save the state of this ability.
......@@ -292,7 +292,7 @@ Called when the framework automatically saves the ability state in the case of a
```ts
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
class MyUIAbility extends Ability {
onSaveState(reason, wantParam) {
console.log('onSaveState');
wantParam['myData'] = 'my1234567';
......@@ -309,7 +309,7 @@ Implements sending of sequenceable data to the target ability when the CallerAbi
## Caller.call
call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
call(method: string, data: rpc.Parcelable): Promise&lt;void&gt;;
Sends sequenceable data to the target ability.
......@@ -320,7 +320,7 @@ Sends sequenceable data to the target ability.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
| data | [rpc.Sequenceable](js-apis-rpc.md#sequenceabledeprecated) | Yes| Sequenceable data. You need to customize the data.|
| data | [rpc.Parcelable](js-apis-rpc.md#parcelabledeprecated) | Yes| Sequenceable data. You need to customize the data.|
**Return value**
......@@ -339,8 +339,7 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example**
```ts
import Ability from '@ohos.app.ability.UIAbility';
class MyMessageAble{ // ԶSequenceableݽṹ
class MyMessageAble{ // Custom sequenceable data structure.
name:''
str:''
num: 1
......@@ -372,7 +371,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
}).then((obj) => {
caller = obj;
let msg = new MyMessageAble('msg', 'world'); // See the definition of Sequenceable.
caller.call(method, msg)
.then(() => {
console.log('Caller call() called');
......@@ -392,7 +390,7 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
## Caller.callWithResult
callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessageParcel&gt;;
callWithResult(method: string, data: rpc.Parcelable): Promise&lt;rpc.MessageParcel&gt;;
Sends sequenceable data to the target ability and obtains the sequenceable data returned by the target ability.
......@@ -403,7 +401,7 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
| data | [rpc.Sequenceable](js-apis-rpc.md#sequenceabledeprecated) | Yes| Sequenceable data. You need to customize the data.|
| data | [rpc.Parcelable](js-apis-rpc.md#parcelabledeprecated) | Yes| Sequenceable data. You need to customize the data.|
**Return value**
......@@ -422,7 +420,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example**
```ts
import Ability from '@ohos.app.ability.UIAbility';
class MyMessageAble{
name:''
str:''
......@@ -494,7 +491,6 @@ Releases the caller interface of the target ability.
**Example**
```ts
import Ability from '@ohos.app.ability.UIAbility';
let caller;
export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
......@@ -520,7 +516,7 @@ Releases the caller interface of the target ability.
## Caller.onRelease
onRelease(callback: OnReleaseCallBack): void;
onRelease(callback: OnReleaseCallback): void;
Registers a callback that is invoked when the stub on the target ability is disconnected.
......@@ -530,12 +526,11 @@ Registers a callback that is invoked when the stub on the target ability is disc
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | [OnReleaseCallBack](#onreleasecallback) | Yes| Callback used to return the result.|
| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.|
**Example**
```ts
import Ability from '@ohos.application.Ability';
let caller;
export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
......@@ -574,7 +569,7 @@ Registers a callback that is invoked when the stub on the target ability is disc
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is fixed at **release**.|
| callback | [OnReleaseCallBack](#onreleasecallback) | Yes| Callback used to return the result.|
| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.|
**Error codes**
......@@ -587,7 +582,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example**
```ts
import Ability from '@ohos.app.ability.UIAbility';
let caller;
export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
......@@ -626,7 +620,7 @@ Deregisters a callback that is invoked when the stub on the target ability is di
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is fixed at **release**.|
| callback | [OnReleaseCallBack](#onreleasecallback) | Yes| Callback used to return the result.|
| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.|
**Error codes**
......@@ -639,7 +633,7 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
```ts
let caller;
export default class MainUIAbility extends UIAbility {
export default class MainUIAbility extends Ability {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: 'com.example.myservice',
......@@ -690,7 +684,7 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
```ts
let caller;
export default class MainUIAbility extends UIAbility {
export default class MainUIAbility extends Ability {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: 'com.example.myservice',
......@@ -746,7 +740,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example**
```ts
import Ability from '@ohos.app.ability.UIAbility';
class MyMessageAble{
name:''
str:''
......@@ -814,7 +807,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example**
```ts
import Ability from '@ohos.app.ability.UIAbility';
let method = 'call_Function';
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
......@@ -841,10 +833,10 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
## CalleeCallback
(indata: rpc.MessageParcel): rpc.Sequenceable;
(indata: rpc.MessageParcel): rpc.Parcelable;
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Readable| Writable| Type| Description|
| -------- | -------- | -------- | -------- | -------- |
| (indata: [rpc.MessageParcel](js-apis-rpc.md#sequenceabledeprecated)) | Yes| No| [rpc.Sequenceable](js-apis-rpc.md#sequenceabledeprecated) | Prototype of the listener function registered by the callee.|
| (indata: [rpc.MessageParcel](js-apis-rpc.md#sequenceabledeprecated)) | Yes| No| [rpc.Parcelable](js-apis-rpc.md#parcelabledeprecated) | Prototype of the listener function registered by the callee.|
......@@ -12,7 +12,7 @@ The **wantConstant** module provides the actions, entities, and flags used in **
import wantConstant from '@ohos.app.ability.wantConstant';
```
## wantConstant.Action
## wantConstant.Params
Enumerates the action constants of the **Want** object. **action** specifies the operation to execute.
......@@ -20,54 +20,12 @@ Enumerates the action constants of the **Want** object. **action** specifies the
| Name | Value | Description |
| ------------ | ------------------ | ---------------------- |
| ACTION_HOME | ohos.want.action.home | Action of returning to the home page. |
| ACTION_DIAL | ohos.want.action.dial | Action of launching the numeric keypad. |
| ACTION_SEARCH | ohos.want.action.search | Action of launching the search function. |
| ACTION_WIRELESS_SETTINGS | ohos.settings.wireless | Action of launching the UI that provides wireless network settings, for example, Wi-Fi options. |
| ACTION_MANAGE_APPLICATIONS_SETTINGS | ohos.settings.manage.applications | Action of launching the UI for managing installed applications. |
| ACTION_APPLICATION_DETAILS_SETTINGS | ohos.settings.application.details | Action of launching the UI that displays the details of an application. |
| ACTION_SET_ALARM | ohos.want.action.setAlarm | Action of launching the UI for setting the alarm clock. |
| ACTION_SHOW_ALARMS | ohos.want.action.showAlarms | Action of launching the UI that displays all alarms. |
| ACTION_SNOOZE_ALARM | ohos.want.action.snoozeAlarm | Action of launching the UI for snoozing an alarm. |
| ACTION_DISMISS_ALARM | ohos.want.action.dismissAlarm | Action of launching the UI for deleting an alarm. |
| ACTION_DISMISS_TIMER | ohos.want.action.dismissTimer | Action of launching the UI for dismissing a timer. |
| ACTION_SEND_SMS | ohos.want.action.sendSms | Action of launching the UI for sending an SMS message. |
| ACTION_CHOOSE | ohos.want.action.choose | Action of launching the UI for opening a contact or picture. |
| ACTION_IMAGE_CAPTURE | ohos.want.action.imageCapture | Action of launching the UI for photographing. |
| ACTION_VIDEO_CAPTURE | ohos.want.action.videoCapture | Action of launching the UI for shooting a video. |
| ACTION_SELECT | ohos.want.action.select | Action of launching the UI for application selection. |
| ACTION_SEND_DATA | ohos.want.action.sendData | Action of launching the UI for sending a single data record. |
| ACTION_SEND_MULTIPLE_DATA | ohos.want.action.sendMultipleData | Action of launching the UI for sending multiple data records. |
| ACTION_SCAN_MEDIA_FILE | ohos.want.action.scanMediaFile | Action of requesting a media scanner to scan a file and add the file to the media library. |
| ACTION_VIEW_DATA | ohos.want.action.viewData | Action of viewing data. |
| ACTION_EDIT_DATA | ohos.want.action.editData | Action of editing data. |
| INTENT_PARAMS_INTENT | ability.want.params.INTENT | Action of displaying selection options with an action selector. |
| INTENT_PARAMS_TITLE | ability.want.params.TITLE | Title of the character sequence dialog box used with the action selector. |
| ACTION_FILE_SELECT | ohos.action.fileSelect | Action of selecting a file. |
| PARAMS_STREAM | ability.params.stream | URI of the data stream associated with the target when the data is sent. |
| ACTION_APP_ACCOUNT_AUTH | account.appAccount.action.auth | Action of providing the authentication service. |
| ACTION_MARKET_DOWNLOAD | ohos.want.action.marketDownload | Action of downloading an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| ACTION_MARKET_CROWDTEST | ohos.want.action.marketCrowdTest | Action of crowdtesting an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_SANDBOX |ohos.dlp.params.sandbox | Action of obtaining the sandbox flag.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_BUNDLE_NAME |ohos.dlp.params.bundleName |Action of obtaining the DLP bundle name.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_MODULE_NAME |ohos.dlp.params.moduleName |Action of obtaining the DLP module name.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_ABILITY_NAME |ohos.dlp.params.abilityName |Action of obtaining the DLP ability name.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_INDEX |ohos.dlp.params.index |Action of obtaining the DLP index.<br>**System API**: This is a system API and cannot be called by third-party applications. |
## wantConstant.Entity
Enumerates the entity constants of the **Want** object. **entity** specifies additional information of the target ability.
**System capability**: SystemCapability.Ability.AbilityBase
| Name | Value | Description |
| ------------ | ------------------ | ---------------------- |
| ENTITY_DEFAULT | entity.system.default | Default entity. The default entity is used if no entity is specified. |
| ENTITY_HOME | entity.system.home | Home screen entity. |
| ENTITY_VOICE | entity.system.voice | Voice interaction entity. |
| ENTITY_BROWSABLE | entity.system.browsable | Browser type entity. |
| ENTITY_VIDEO | entity.system.video | Video type entity. |
| ABILITY_BACK_TO_OTHER_MISSION_STACK |ability.params.backToOtherMissionStack |Action of returning the ability to the mission stack. |
## wantConstant.Flags
......
......@@ -45,6 +45,8 @@ Called to notify the widget provider that a **Form** instance (widget) has been
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from'@ohos.app.form.formBindingData';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm(want) {
console.log('FormExtensionAbility onAddForm, want:' + want.abilityName);
......@@ -247,7 +249,7 @@ class MyFormExtensionAbility extends FormExtensionAbility {
## onShareForm
onShareForm?(formId: string): { [key: string]: any }
onShareForm?(formId: string): { [key: string]: Object }
Called by the widget provider to receive shared widget data.
......
......@@ -31,7 +31,6 @@ Describes widget information.
| isDefault | boolean | Yes | No | Whether the widget is the default one. |
| updateEnabled | boolean | Yes | No | Whether the widget is updatable. |
| formVisibleNotify | boolean | Yes | No | Whether to send a notification when the widget is visible. |
| relatedBundleName | string | Yes | No | Name of the associated bundle to which the widget belongs. |
| scheduledUpdateTime | string | Yes | No | Time when the widget was updated. |
| formConfigAbility | string | Yes | No | Configuration ability of the widget, that is, the ability corresponding to the option in the selection box displayed when the widget is long pressed. |
| updateDuration | number | Yes | No | Update period of the widget.|
......
......@@ -243,7 +243,8 @@ Obtains the application's widget information that meets a filter criterion on th
**Example**
```ts
import formInfo from '@ohos.application.formInfo';
import formInfo from '@ohos.app.form.formInfo';
const filter : formInfo.FormInfoFilter = {
// get info of forms belong to module entry.
moduleName : 'entry'
......@@ -291,7 +292,8 @@ Obtains the application's widget information on the device. This API uses a prom
**Example**
```ts
import formInfo from '@ohos.application.formInfo';
import formInfo from '@ohos.app.form.formInfo';
const filter : formInfo.FormInfoFilter = {
// get info of forms belong to module entry.
moduleName : 'entry'
......
......@@ -252,49 +252,6 @@ Registers an observer to listen for the state changes of all applications.
console.log('-------- observerCode: ---------', observerCode);
```
## appManager.registerApplicationStateObserver<sup>9+</sup>
registerApplicationStateObserver(observer: ApplicationStateObserver, bundleNameList: Array\<string>): number;
Registers an observer to listen for the state changes of a specified application.
**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
**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|
| -------- | -------- | -------- | -------- |
| observer | [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md) | Yes| Numeric code of the observer.|
| bundleNameList | Array<string> | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.|
**Example**
```ts
let applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
console.log('------------ onForegroundApplicationChanged -----------', appStateData);
},
onAbilityStateChanged(abilityStateData) {
console.log('------------ onAbilityStateChanged -----------', abilityStateData);
},
onProcessCreated(processData) {
console.log('------------ onProcessCreated -----------', processData);
},
onProcessDied(processData) {
console.log('------------ onProcessDied -----------', processData);
},
onProcessStateChanged(processData) {
console.log('------------ onProcessStateChanged -----------', processData);
}
};
let bundleNameList = ['bundleName1', 'bundleName2'];
const observerCode = app.registerApplicationStateObserver(applicationStateObserver, bundleNameList);
console.log('-------- observerCode: ---------', observerCode);
```
## appManager.unregisterApplicationStateObserver<sup>8+</sup>
unregisterApplicationStateObserver(observerId: number, callback: AsyncCallback\<void>): void;
......
......@@ -18,7 +18,7 @@ For details about the fields, see the **ohos.application.Configuration.d.ts** fi
**Example**
```ts
import Ability from '@ohos.application.Ability'
import Ability from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window'
export default class MainAbility extends Ability {
......@@ -34,11 +34,14 @@ export default class MainAbility extends Ability {
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`);
let language = config.language;
let colorMode = config.colorMode;
},
onMemoryLevel(level){
console.log('onMemoryLevel level: ${JSON.stringify(level)}');
}
};
let applicationContext = this.context.getApplicationContext();
applicationContext.registerEnvironmentCallback(envCallback);
applicationContext.on('environment',envCallback);
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
......
......@@ -1045,93 +1045,3 @@ formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
});
```
## shareForm<sup>9+</sup>
shareForm(formId: string, deviceId: string, callback: AsyncCallback&lt;void&gt;): void
Shares a specified widget with a remote device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.REQUIRE_FORM
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formId | string | Yes | Widget ID.|
| deviceId | string | Yes | Remote device ID.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the widget is shared, **error** is undefined; otherwise, **error** is an error object.|
**Example**
```ts
let formId = '12400633174999288';
let deviceId = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2';
formHost.shareForm(formId, deviceId, (error, data) => {
if (error.code) {
console.log('formHost shareForm, error:' + JSON.stringify(error));
}
});
```
## shareForm<sup>9+</sup>
shareForm(formId: string, deviceId: string): Promise&lt;void&gt;
Shares a specified widget with a remote device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.REQUIRE_FORM
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formId | string | Yes | Widget ID.|
| deviceId | string | Yes | Remote device ID.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```ts
let formId = '12400633174999288';
let deviceId = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2';
formHost.shareForm(formId, deviceId).then(() => {
console.log('formHost shareForm success');
}).catch((error) => {
console.log('formHost shareForm, error:' + JSON.stringify(error));
});
```
## notifyFormsPrivacyProtected<sup>9+</sup>
notifyFormsPrivacyProtected(formIds: Array\<string>, isProtected: boolean, callback: AsyncCallback\<void>): void
Notifies that the privacy protection status of the specified widgets changes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.REQUIRE_FORM
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formId | string | Yes | Widget ID.|
| deviceId | string | Yes | Remote device ID.|
```ts
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsPrivacyProtected(formIds, true).then(() => {
console.log('formHost shareForm success');
}).catch((error) => {
console.log('formHost shareForm, error:' + JSON.stringify(error));
});
```
# @ohos.application.formInfo (formInfo)
# @ohos.application.formInfo (FormInfo)
The **formInfo** module provides types and enums related to the widget information and state.
......@@ -49,7 +49,6 @@ Enumerates the widget types.
| Name | Value | Description |
| ----------- | ---- | ------------ |
| JS | 1 | JS widget. |
| eTS<sup>9+<sup> | 2 | eTS widget.|
## ColorMode
......@@ -94,48 +93,10 @@ Enumerates the widget parameters.
| Name | Value | Description |
| ----------- | ---- | ------------ |
| IDENTITY_KEY<sup>9+</sup> | "ohos.extra.param.key.form_identity" | Widget ID.<br>**System API**: This is a system API. |
| IDENTITY_KEY<sup>8+</sup> | "ohos.extra.param.key.form_identity" | Widget ID.<br>**System API**: This is a system API. |
| DIMENSION_KEY | "ohos.extra.param.key.form_dimension" | Widget dimension. |
| NAME_KEY | "ohos.extra.param.key.form_name" | Widget name. |
| MODULE_NAME_KEY | "ohos.extra.param.key.module_name" | Name of the module to which the widget belongs. |
| WIDTH_KEY | "ohos.extra.param.key.form_width" | Widget width. |
| HEIGHT_KEY | "ohos.extra.param.key.form_height" | Widget height. |
| TEMPORARY_KEY | "ohos.extra.param.key.form_temporary" | Temporary widget. |
| ABILITY_NAME_KEY<sup>9+</sup> | "ohos.extra.param.key.ability_name" | Ability name. |
| DEVICE_ID_KEY<sup>9+</sup> | "ohos.extra.param.key.device_id" | Device ID. |
| BUNDLE_NAME_KEY<sup>9+</sup> | "ohos.extra.param.key.bundle_name" | Key that specifies the target bundle name.|
## FormDimension<sup>9+</sup>
Enumerates the widget dimensions.
**System capability**: SystemCapability.Ability.Form
| Name | Value | Description |
| ----------- | ---- | ------------ |
| Dimension_1_2 <sup>9+</sup> | 1 | 1 x 2. |
| Dimension_2_2 <sup>9+</sup> | 2 | 2 x 2. |
| Dimension_2_4 <sup>9+</sup> | 3 | 2 x 4. |
| Dimension_4_4 <sup>9+</sup> | 4 | 4 x 4. |
| Dimension_2_1 <sup>9+</sup> | 5 | 2 x 1. |
## FormInfoFilter<sup>9+</sup>
Defines the widget information filter. Only the widget information that meets the filter is returned.
**System capability**: SystemCapability.Ability.Form
| Name | Description |
| ----------- | ------------ |
| moduleName<sup>9+</sup> | Optional. Only the information about the widget whose **moduleName** is the same as the provided value is returned.<br>If this parameter is not set, **moduleName** is not used for filtering.|
## VisibilityType<sup>9+</sup>
Enumerates the visibility types of the widget.
**System capability**: SystemCapability.Ability.Form
| Name | Value | Description |
| ----------- | ---- | ------------ |
| FORM_VISIBLE<sup>9+<sup> | 1 | The widget is visible.|
| FORM_INVISIBLE<sup>9+<sup> | 2 | The widget is invisible.|
......@@ -133,297 +133,3 @@ Updates a widget. This API uses a promise to return the result.
console.log('formProvider updateForm, error:' + JSON.stringify(error));
});
```
## getFormsInfo<sup>9+</sup>
getFormsInfo(callback: AsyncCallback&lt;Array&lt;formInfo.FormInfo&gt;&gt;): void
Obtains the application's widget information on the device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| callback | AsyncCallback&lt;Array&lt;[FormInfo](./js-apis-application-formInfo.md#forminfo-1)&gt;&gt; | Yes| Callback used to return the information obtained.|
**Example**
```ts
formProvider.getFormsInfo((error, data) => {
if (error.code) {
console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
} else {
console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
}
});
```
## getFormsInfo<sup>9+</sup>
getFormsInfo(filter: formInfo.FormInfoFilter, callback: AsyncCallback&lt;Array&lt;formInfo.FormInfo&gt;&gt;): void
Obtains the application's widget information that meets a filter criterion on the device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| filter | [formInfo.FormInfoFilter](./js-apis-application-formInfo.md#forminfofilter) | Yes| Filter criterion.|
| callback | AsyncCallback&lt;Array&lt;[FormInfo](./js-apis-application-formInfo.md#forminfo-1)&gt;&gt; | Yes| Callback used to return the information obtained.|
**Example**
```ts
import formInfo from '@ohos.application.formInfo';
const filter : formInfo.FormInfoFilter = {
// get info of forms belong to module entry.
moduleName : 'entry'
};
formProvider.getFormsInfo(filter, (error, data) => {
if (error.code) {
console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
} else {
console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
}
});
```
## getFormsInfo<sup>9+</sup>
getFormsInfo(filter?: formInfo.FormInfoFilter): Promise&lt;Array&lt;formInfo.FormInfo&gt;&gt;
Obtains the application's widget information on the device. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| filter | [formInfo.FormInfoFilter](./js-apis-application-formInfo.md) | No| Filter criterion.|
**Return value**
| Type | Description |
| :------------ | :---------------------------------- |
| Promise&lt;Array&lt;[FormInfo](./js-apis-application-formInfo.md#forminfo-1)&gt;&gt; | Promise used to return the information obtained.|
**Example**
```ts
import formInfo from '@ohos.application.formInfo';
const filter : formInfo.FormInfoFilter = {
// get info of forms belong to module entry.
moduleName : 'entry'
};
formProvider.getFormsInfo(filter).then((data) => {
console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
}).catch((error) => {
console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
});
```
## requestPublishForm<sup>9+</sup>
requestPublishForm(want: Want, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<string>): void
Requests to publish a widget carrying data to the widget host. This API uses an asynchronous callback to return the result. This API is usually called by the home screen.
**System capability**: SystemCapability.Ability.Form
**System API**: This is a system API.
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
| want | [Want](js-apis-application-want.md) | Yes | Request used for publishing. The following fields must be included:<br>Information about the target widget.<br>**abilityName**: ability of the target widget.<br>**parameters**:<br>"ohos.extra.param.key.form_dimension"<br>"ohos.extra.param.key.form_name"<br>"ohos.extra.param.key.module_name" |
| formBindingData.FormBindingData | [FormBindingData](js-apis-application-formBindingData.md#formbindingdata) | Yes | Data used for creating the widget.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the widget ID.|
**Example**
```ts
import formBindingData from '@ohos.application.formBindingData';
let want = {
abilityName: 'FormAbility',
parameters: {
'ohos.extra.param.key.form_dimension': 2,
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.module_name': 'entry'
}
};
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'});
formProvider.requestPublishForm(want, obj, (error, data) => {
if (error.code) {
console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
} else {
console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
}
});
```
## requestPublishForm<sup>9+</sup>
requestPublishForm(want: Want, callback: AsyncCallback&lt;string&gt;): void
Requests to publish a widget to the widget host. This API uses an asynchronous callback to return the result. This API is usually called by the home screen.
**System capability**: SystemCapability.Ability.Form
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-want.md) | Yes | Request used for publishing. The following fields must be included:<br>Information about the target widget.<br>**abilityName**: ability of the target widget.<br>**parameters**:<br>"ohos.extra.param.key.form_dimension"<br>"ohos.extra.param.key.form_name"<br>"ohos.extra.param.key.module_name" |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the widget ID.|
**Example**
```ts
let want = {
abilityName: 'FormAbility',
parameters: {
'ohos.extra.param.key.form_dimension': 2,
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.module_name': 'entry'
}
};
formProvider.requestPublishForm(want, (error, data) => {
if (error.code) {
console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
} else {
console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
}
});
```
## requestPublishForm<sup>9+</sup>
requestPublishForm(want: Want, formBindingData?: formBindingData.FormBindingData): Promise&lt;string&gt;
Requests to publish a widget to the widget host. This API uses a promise to return the result. This API is usually called by the home screen.
**System capability**: SystemCapability.Ability.Form
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-want.md) | Yes | Request used for publishing. The following fields must be included:<br>Information about the target widget.<br>**abilityName**: ability of the target widget.<br>**parameters**:<br>"ohos.extra.param.key.form_dimension"<br>"ohos.extra.param.key.form_name"<br>"ohos.extra.param.key.module_name" |
| formBindingData.FormBindingData | [FormBindingData](js-apis-application-formBindingData.md#formbindingdata) | Yes | Data used for creating the widget.|
**Return value**
| Type | Description |
| :------------ | :---------------------------------- |
| Promise&lt;string&gt; | Promise used to return the widget ID.|
**Example**
```ts
let want = {
abilityName: 'FormAbility',
parameters: {
'ohos.extra.param.key.form_dimension': 2,
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.module_name': 'entry'
}
};
formProvider.requestPublishForm(want).then((data) => {
console.log('formProvider requestPublishForm success, form ID is :' + JSON.stringify(data));
}).catch((error) => {
console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
});
```
## isRequestPublishFormSupported<sup>9+<sup>
isRequestPublishFormSupported(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a widget can be published to the widget host. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return whether the widget can be published to the widget host.|
**Example**
```ts
formProvider.isRequestPublishFormSupported((error, isSupported) => {
if (error.code) {
console.log('formProvider isRequestPublishFormSupported, error:' + JSON.stringify(error));
} else {
if (isSupported) {
let want = {
abilityName: 'FormAbility',
parameters: {
'ohos.extra.param.key.form_dimension': 2,
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.module_name': 'entry'
}
};
formProvider.requestPublishForm(want, (error, data) => {
if (error.code) {
console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
} else {
console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
}
});
}
}
});
```
## isRequestPublishFormSupported<sup>9+</sup>
isRequestPublishFormSupported(): Promise&lt;boolean&gt;
Checks whether a widget can be published to the widget host. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Ability.Form
**Return value**
| Type | Description |
| :------------ | :---------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return whether the widget can be published to the widget host.|
**Example**
```ts
formProvider.isRequestPublishFormSupported().then((isSupported) => {
if (isSupported) {
let want = {
abilityName: 'FormAbility',
parameters: {
'ohos.extra.param.key.form_dimension': 2,
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.module_name': 'entry'
}
};
formProvider.requestPublishForm(want).then((data) => {
console.log('formProvider requestPublishForm success, form ID is :' + JSON.stringify(data));
}).catch((error) => {
console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
});
}
}).catch((error) => {
console.log('formProvider isRequestPublishFormSupported, error:' + JSON.stringify(error));
});
```
\ No newline at end of file
......@@ -367,89 +367,6 @@ Obtains the snapshot of a given mission. This API uses a promise to return the r
});
```
## missionManager.getLowResolutionMissionSnapShot<sup>9+</sup>
getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback\<MissionSnapshot>): void;
Obtains the low-resolution snapshot of a given mission. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_MISSIONS
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)&gt; | Yes| Callback used to return the snapshot information obtained.|
**Example**
```ts
import missionManager from '@ohos.application.missionManager';
missionManager.getMissionInfos('', 10, (error, missions) => {
console.log('getMissionInfos is called, error.code = ' + error.code);
console.log('size = ' + missions.length);
console.log('missions = ' + JSON.stringify(missions));
let id = missions[0].missionId;
missionManager.getLowResolutionMissionSnapShot('', id, (error, snapshot) => {
console.log('getLowResolutionMissionSnapShot is called, error.code = ' + error.code);
console.log('bundleName = ' + snapshot.ability.bundleName);
});
});
```
## missionManager.getLowResolutionMissionSnapShot<sup>9+</sup>
getLowResolutionMissionSnapShot(deviceId: string, missionId: number): Promise\<MissionSnapshot>;
Obtains the low-resolution snapshot of a given mission. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_MISSIONS
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| missionId | number | Yes| Mission ID.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)&gt; | Promise used to return the snapshot information obtained.|
**Example**
```ts
import missionManager from '@ohos.application.missionManager';
let allMissions;
missionManager.getMissionInfos('',10).then(function(res){
allMissions=res;
}).catch(function(err){console.log(err);});
console.log('size = ' + allMissions.length);
console.log('missions = ' + JSON.stringify(allMissions));
let id = allMissions[0].missionId;
let snapshot = missionManager.getLowResolutionMissionSnapShot('', id).catch(function (err){
console.log(err);
});
```
## missionManager.lockMission
lockMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
......
......@@ -27,7 +27,6 @@ import Want from '@ohos.application.Want';
| action | string | No | Action to take, such as viewing and sharing application details. In implicit **Want**, you can define this attribute and use it together with **uri** or **parameters** to specify the operation to be performed on the data. |
| parameters | {[key: string]: any} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:<br>- **ohos.aafwk.callerPid**: PID of the caller.<br>- **ohos.aafwk.param.callerToken**: token of the caller.<br>- **ohos.aafwk.param.callerUid**: UID in [bundleInfo](js-apis-bundle-BundleInfo.md#bundleinfo-1), that is, the application UID in the bundle information.<br>- **component.startup.newRules**: whether to enable the new control rule.<br>- **moduleName**: module name of the caller. No matter what this field is set to, the correct module name will be sent to the peer.<br>- **ohos.dlp.params.sandbox**: available only for DLP files. |
| entities | Array\<string> | 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. |
| moduleName<sup>9+</sup> | string | No | Module to which the ability belongs.|
**Example**
......
......@@ -368,8 +368,8 @@ Continues a mission on a remote device. This API uses an asynchronous callback t
| Name | Type | Mandatory | Description |
| --------- | --------------------------------------- | ---- | ----- |
| parameter | [ContinueDeviceInfo](#continuedeviceinfo) | Yes | Parameters required for mission continuation.|
| options | [ContinueCallback](#continuecallback) | Yes | Callback invoked when the mission continuation is complete.|
| parameter | [ContinueDeviceInfo](#js-apis-inner-application-continueDeviceInfo.md) | Yes | Parameters required for mission continuation.|
| options | [ContinueCallback](#js-apis-inner-application-continueCallback.md) | Yes | Callback invoked when the mission continuation is complete.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Error codes**
......@@ -426,8 +426,8 @@ Continues a mission on a remote device. This API uses a promise to return the re
| Name | Type | Mandatory | Description |
| --------- | --------------------------------------- | ---- | ----- |
| parameter | [ContinueDeviceInfo](#continuedeviceinfo) | Yes | Parameters required for mission continuation.|
| options | [ContinueCallback](#continuecallback) | Yes | Callback invoked when the mission continuation is complete.|
| parameter | [ContinueDeviceInfo](#js-apis-inner-application-continueDeviceInfo.md) | Yes | Parameters required for mission continuation.|
| options | [ContinueCallback](#js-apis-inner-application-continueCallback.md) | Yes | Callback invoked when the mission continuation is complete.|
**Return value**
......@@ -514,30 +514,3 @@ Defines the parameters required for registering a listener.
| Name | Type | Readable | Writable | Description |
| -------- | ------ | ---- | ---- | ------- |
| deviceId | string | Yes | Yes | Device ID.|
## ContinueDeviceInfo
Defines the parameters required for mission continuation.
**Required permissions**: ohos.permission.MANAGE_MISSIONS
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
| Name | Type | Readable | Writable | Description |
| -------- | ------ | ---- | ---- | ------- |
| srcDeviceId | string | Yes | Yes | ID of the source device.|
| dstDeviceId | string | Yes | Yes | ID of the target device.|
| missionId | number | Yes | Yes | Mission ID.|
| wantParam | {[key: string]: any} | Yes | Yes | Extended parameters.|
## ContinueCallback
Defines the callback invoked when the mission continuation is complete.
**Required permissions**: ohos.permission.MANAGE_MISSIONS
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
| Name | Type | Readable | Writable | Description |
| --------------------- | -------- | ---- | ---- | ------------------ |
| onContinueDone | function | Yes | No | Callback used to notify the user that the mission continuation is complete and return the continuation result. |
......@@ -25,11 +25,9 @@ try {
DAHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri);
if (DAHelper == null) {
console.error('DAHelper is null');
return;
}
} catch (err) {
console.error('acquireDataAbilityHelper fail, error:' + JSON.stringify(err));
return;
}
let valueBucket = {
......
......@@ -38,7 +38,5 @@ let startAbilityParameter = {
featureAbility.startAbility(startAbilityParameter, (err, data)=>{
console.log('errCode : ' + JSON.stringify(err));
console.log('data : ' + JSON.stringify(data));
} catch(error) {
console.log('startAbility error: ' + JSON.stringify(error));
}
});
```
......@@ -10,9 +10,7 @@ The **AbilityDelegator** module provides APIs for managing **AbilityMonitor** in
An **AbilityDelegator** object is obtained by calling [getAbilityDelegator](js-apis-app-ability-abilityDelegatorRegistry.md#abilitydelegatorregistrygetabilitydelegator) in **AbilityDelegatorRegistry**.
```ts
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
```
## AbilityDelegator
......@@ -504,8 +502,8 @@ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility((err : any, data : any) => {
console.info('getCurrentTopAbility callback');
ability = data;
abilityDelegator.doAbilityForeground(ability, (err : any, data : any) => {
console.info('doAbilityForeground callback');
abilityDelegator.doAbilityForeground(ability, (err : any) => {
console.info("doAbilityForeground callback");
});
});
```
......@@ -542,8 +540,8 @@ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility((err : any, data : any) => {
console.info('getCurrentTopAbility callback');
ability = data;
abilityDelegator.doAbilityForeground(ability).then((data : any) => {
console.info('doAbilityForeground promise');
abilityDelegator.doAbilityForeground(ability).then(() => {
console.info("doAbilityForeground promise");
});
});
```
......@@ -575,8 +573,8 @@ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility((err : any, data : any) => {
console.info('getCurrentTopAbility callback');
ability = data;
abilityDelegator.doAbilityBackground(ability, (err : any, data : any) => {
console.info('doAbilityBackground callback');
abilityDelegator.doAbilityBackground(ability, (err : any) => {
console.info("doAbilityBackground callback");
});
});
```
......@@ -613,8 +611,8 @@ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility((err : any, data : any) => {
console.info('getCurrentTopAbility callback');
ability = data;
abilityDelegator.doAbilityBackground(ability).then((data : any) => {
console.info('doAbilityBackground promise');
abilityDelegator.doAbilityBackground(ability).then(() => {
console.info("doAbilityBackground promise");
});
});
```
......
......@@ -115,7 +115,7 @@ export default class EntryAbility extends UIAbility {
onDestroy() {
let applicationContext = this.context.getApplicationContext();
console.log('stage applicationContext: ' + applicationContext);
applicationContext.off(type: 'abilityLifecycle', lifecycleId, (error, data) => {
applicationContext.off('abilityLifecycle', lifecycleId, (error, data) => {
console.log('unregisterAbilityLifecycleCallback success, err: ' + JSON.stringify(error));
});
}
......@@ -148,7 +148,7 @@ export default class MyAbility extends Ability {
onDestroy() {
let applicationContext = this.context.getApplicationContext();
console.log('stage applicationContext: ' + applicationContext);
applicationContext.off(type: 'abilityLifecycle', lifecycleId);
applicationContext.off('abilityLifecycle', lifecycleId);
}
}
```
......@@ -185,7 +185,7 @@ export default class EntryAbility extends UIAbility {
onCreate() {
console.log('MyAbility onCreate')
globalThis.applicationContext = this.context.getApplicationContext();
let EnvironmentCallback = {
let environmentCallback = {
onConfigurationUpdated(config){
console.log('onConfigurationUpdated config:' + JSON.stringify(config));
},
......@@ -196,8 +196,8 @@ export default class EntryAbility extends UIAbility {
// 1. Obtain an applicationContext object.
let applicationContext = globalThis.applicationContext;
// 2. Use applicationContext to register a listener for the ability lifecycle in the application.
callbackId = applicationContext.on('environment', EnvironmentCallback);
console.log('registerEnvironmentCallback number: ' + JSON.stringify(callbackId));
callbackId = applicationContext.on('environment', environmentCallback);
console.log('registerEnvironmentCallback callbackId: ${callbackId}');
}
}
```
......
......@@ -19,12 +19,12 @@ Called when an unhandled exception occurs in the JS runtime.
**Example**
```ts
import errorManager from '@ohos.application.errorManager';
import errorManager from '@ohos.app.ability.errorManager';
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ' + JSON.stringify(errorMsg));
}
};
errorManager.registerErrorObserver(observer);
errorManager.on('error',observer);
```
......@@ -12,7 +12,7 @@ The **EventHub** module provides APIs to subscribe to, unsubscribe from, and tri
Before using any APIs in the **EventHub**, you must obtain an **EventHub** instance through the member variable **context** of the **Ability** instance.
```ts
import Ability from '@ohos.application.Ability';
import Ability from '@ohos.app.ability.UIAbility';
export default class MainAbility extends Ability {
func1(){
console.log('func1 is called');
......@@ -41,7 +41,7 @@ Subscribes to an event.
**Example**
```ts
import Ability from '@ohos.application.Ability';
import Ability from '@ohos.app.ability.UIAbility';
export default class MainAbility extends Ability {
onForeground() {
......@@ -79,7 +79,7 @@ Unsubscribes from an event.
**Example**
```ts
import Ability from '@ohos.application.Ability';
import Ability from '@ohos.app.ability.UIAbility';
export default class MainAbility extends Ability {
onForeground() {
......@@ -117,7 +117,7 @@ Triggers an event.
**Example**
```ts
import Ability from '@ohos.application.Ability';
import Ability from '@ohos.app.ability.UIAbility';
export default class MainAbility extends Ability {
onForeground() {
......
......@@ -31,8 +31,12 @@ let listener = {
onMissionMovedToFront: function (mission) {
console.log('onMissionMovedToFront mission: ' + JSON.stringify(mission));
},
onMissionLabelUpdated: function (mission) {
console.log('onMissionLabelUpdated mission: ' + JSON.stringify(mission));
},
onMissionIconUpdated: function (mission, icon) {
console.log('onMissionIconUpdated mission: ' + JSON.stringify(mission));
console.log('onMissionIconUpdated icon: ' + JSON.stringify(icon));
},
onMissionClosed: function (mission) {
console.log('onMissionClosed mission: ' + JSON.stringify(mission));
......
......@@ -12,6 +12,145 @@ The **WantAgent** module provides APIs for creating and comparing **WantAgent**
import WantAgent from '@ohos.wantAgent';
```
## WantAgent.getWant
getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void
Obtains the Want in 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](js-apis-inner-wantAgent-wantAgent.md) | Yes | **WantAgent** object. |
| callback | AsyncCallback\<Want\> | Yes | Callback used to return the Want.|
**Example**
```ts
import WantAgent from '@ohos.wantAgent';
// WantAgent object
let wantAgent;
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info('==========================>getWantAgentCallback=======================>');
if (err.code == 0) {
wantAgent = data;
} else {
console.error('getWantAgent failed, error: ' + JSON.stringify(err));
return;
}
// getWant callback
function getWantCallback(err, data) {
console.info('==========================>getWantCallback=======================>');
}
WantAgent.getWant(wantAgent, getWantCallback);
}
// WantAgentInfo object
let wantAgentInfo = {
wants: [
{
deviceId: 'deviceId',
bundleName: 'com.neu.setResultOnAbilityResultTest1',
abilityName: 'com.example.test.EntryAbility',
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]
};
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
```
## WantAgent.getWant
getWant(agent: WantAgent): Promise\<Want\>
Obtains the Want in 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](js-apis-inner-wantAgent-wantAgent.md) | Yes | **WantAgent** object.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<Want\> | Promise used to return the Want.|
**Example**
```ts
import WantAgent from '@ohos.wantAgent';
// WantAgent object
let wantAgent;
// WantAgentInfo object
let wantAgentInfo = {
wants: [
{
deviceId: 'deviceId',
bundleName: 'com.neu.setResultOnAbilityResultTest1',
abilityName: 'com.example.test.EntryAbility',
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]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info('==========================>getWantAgentCallback=======================>');
wantAgent = data;
if (wantAgent) {
WantAgent.getWant(wantAgent).then((data) => {
console.info('==========================>getWantCallback=======================>');
});
}
});
```
## WantAgent.getWantAgent
getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void
......@@ -786,135 +925,6 @@ WantAgent.equal(wantAgent1, wantAgent2).then((data) => {
});
```
## WantAgent.getOperationType<sup>9+</sup>
getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): 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\<number> | Yes | Callback used to return the operation type.|
**Example**
```ts
import WantAgent from '@ohos.wantAgent';
// WantAgent object
let wantAgent;
// WantAgentInfo object
let wantAgentInfo = {
wants: [
{
deviceId: 'deviceId',
bundleName: 'com.neu.setResultOnAbilityResultTest1',
abilityName: 'com.example.test.EntryAbility',
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]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info('==========================>getWantAgentCallback=======================>');
wantAgent = data;
if (data) {
WantAgent.getOperationType(wantAgent, (OperationType) => {
console.log('----------- getOperationType ----------, OperationType: ' + OperationType);
})
}
});
```
## WantAgent.getOperationType<sup>9+</sup>
getOperationType(agent: WantAgent): Promise\<number>;
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\<number> | Promise used to return the operation type.|
**Example**
```ts
import WantAgent from '@ohos.wantAgent';
// WantAgent object
let wantAgent;
// WantAgentInfo object
let wantAgentInfo = {
wants: [
{
deviceId: 'deviceId',
bundleName: 'com.neu.setResultOnAbilityResultTest1',
abilityName: 'com.example.test.EntryAbility',
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]
}
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);
})
});
```
## WantAgentFlags
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册