提交 9fc0a0e6 编写于 作者: G Gloria

Update docs against 13928+14123+14587+14123+14771

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 459882dd
...@@ -20,15 +20,8 @@ ...@@ -20,15 +20,8 @@
- [@ohos.application.StaticSubscriberExtensionAbility (StaticSubscriberExtensionAbility)](js-apis-application-staticSubscriberExtensionAbility.md) - [@ohos.application.StaticSubscriberExtensionAbility (StaticSubscriberExtensionAbility)](js-apis-application-staticSubscriberExtensionAbility.md)
- Stage Model (To Be Deprecated Soon) - Stage Model (To Be Deprecated Soon)
- [@ohos.application.Ability (Ability)](js-apis-application-ability.md) - [@ohos.application.Ability (Ability)](js-apis-application-ability.md)
- [@ohos.application.AbilityConstant (AbilityConstant)](js-apis-application-abilityConstant.md)
- [@ohos.application.AbilityLifecycleCallback (AbilityLifecycleCallback)](js-apis-application-abilityLifecycleCallback.md) - [@ohos.application.AbilityLifecycleCallback (AbilityLifecycleCallback)](js-apis-application-abilityLifecycleCallback.md)
- [@ohos.application.AbilityStage (AbilityStage)](js-apis-application-abilityStage.md)
- [@ohos.application.context (Context)](js-apis-application-context.md)
- [@ohos.application.EnvironmentCallback (EnvironmentCallback)](js-apis-application-environmentCallback.md) - [@ohos.application.EnvironmentCallback (EnvironmentCallback)](js-apis-application-environmentCallback.md)
- [@ohos.application.ExtensionAbility (ExtensionAbility)](js-apis-application-extensionAbility.md)
- [@ohos.application.FormExtension (FormExtension)](js-apis-application-formExtension.md)
- [@ohos.application.ServiceExtensionAbility (ServiceExtensionAbility)](js-apis-application-serviceExtensionAbility.md)
- [@ohos.application.StartOptions (StartOptions)](js-apis-application-startOptions.md)
- FA Model - FA Model
- [@ohos.ability.ability (Ability)](js-apis-ability-ability.md) - [@ohos.ability.ability (Ability)](js-apis-ability-ability.md)
- [@ohos.ability.featureAbility (FeatureAbility)](js-apis-ability-featureAbility.md) - [@ohos.ability.featureAbility (FeatureAbility)](js-apis-ability-featureAbility.md)
...@@ -110,7 +103,7 @@ ...@@ -110,7 +103,7 @@
- [MissionSnapshot](js-apis-inner-application-missionSnapshot.md) - [MissionSnapshot](js-apis-inner-application-missionSnapshot.md)
- [ProcessData](js-apis-inner-application-processData.md) - [ProcessData](js-apis-inner-application-processData.md)
- [ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md) - [ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md)
- [ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md) - [ProcessInformation](js-apis-inner-application-processInformation.md)
- [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md) - [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md)
- [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md) - [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md)
- [shellCmdResult](js-apis-inner-application-shellCmdResult.md) - [shellCmdResult](js-apis-inner-application-shellCmdResult.md)
...@@ -185,7 +178,7 @@ ...@@ -185,7 +178,7 @@
- [@ohos.i18n (Internationalization)](js-apis-i18n.md) - [@ohos.i18n (Internationalization)](js-apis-i18n.md)
- [@ohos.intl (Internationalization)](js-apis-intl.md) - [@ohos.intl (Internationalization)](js-apis-intl.md)
- [@ohos.resourceManager (Resource Manager)](js-apis-resource-manager.md) - [@ohos.resourceManager (Resource Manager)](js-apis-resource-manager.md)
- Resource Scheduling - Background Tasks
- [@ohos.distributedMissionManager (Distributed Mission Management)](js-apis-distributedMissionManager.md) - [@ohos.distributedMissionManager (Distributed Mission Management)](js-apis-distributedMissionManager.md)
- [@ohos.reminderAgentManager (Reminder Agent Management)](js-apis-reminderAgentManager.md) - [@ohos.reminderAgentManager (Reminder Agent Management)](js-apis-reminderAgentManager.md)
- [@ohos.resourceschedule.backgroundTaskManager (Background Task Management)](js-apis-resourceschedule-backgroundTaskManager.md) - [@ohos.resourceschedule.backgroundTaskManager (Background Task Management)](js-apis-resourceschedule-backgroundTaskManager.md)
...@@ -371,6 +364,7 @@ ...@@ -371,6 +364,7 @@
- [@ohos.reminderAgent (Reminder Agent)](js-apis-reminderAgent.md) - [@ohos.reminderAgent (Reminder Agent)](js-apis-reminderAgent.md)
- [@ohos.statfs (statfs)](js-apis-statfs.md) - [@ohos.statfs (statfs)](js-apis-statfs.md)
- [@ohos.systemParameter (System Parameter)](js-apis-system-parameter.md) - [@ohos.systemParameter (System Parameter)](js-apis-system-parameter.md)
- [@ohos.usb (USB Management)](js-apis-usb-deprecated.md)
- [@ohos.usbV9 (USB Management)](js-apis-usb.md) - [@ohos.usbV9 (USB Management)](js-apis-usb.md)
- [@system.app (Application Context)](js-apis-system-app.md) - [@system.app (Application Context)](js-apis-system-app.md)
- [@system.battery (Battery Information)](js-apis-system-battery.md) - [@system.battery (Battery Information)](js-apis-system-battery.md)
......
...@@ -49,10 +49,10 @@ import formBindingData from '@ohos.app.form.formBindingData'; ...@@ -49,10 +49,10 @@ import formBindingData from '@ohos.app.form.formBindingData';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm(want) { onAddForm(want) {
console.log('FormExtensionAbility onAddForm, want:' + want.abilityName); console.log('FormExtensionAbility onAddForm, want: ${want.abilityName}');
let dataObj1 = { let dataObj1 = {
temperature: "11c", temperature: '11c',
"time": "11:00" 'time': '11:00'
}; };
let obj1 = formBindingData.createFormBindingData(dataObj1); let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1; return obj1;
...@@ -81,7 +81,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; ...@@ -81,7 +81,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onCastToNormalForm(formId) { onCastToNormalForm(formId) {
console.log('FormExtensionAbility onCastToNormalForm, formId:' + formId); console.log('FormExtensionAbility onCastToNormalForm, formId: ${formId}');
} }
}; };
``` ```
...@@ -109,15 +109,15 @@ import formProvider from '@ohos.app.form.formProvider'; ...@@ -109,15 +109,15 @@ import formProvider from '@ohos.app.form.formProvider';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onUpdateForm(formId) { onUpdateForm(formId) {
console.log('FormExtensionAbility onUpdateForm, formId:' + formId); console.log('FormExtensionAbility onUpdateForm, formId: ${formId}');
let obj2 = formBindingData.createFormBindingData({ let obj2 = formBindingData.createFormBindingData({
temperature: "22c", temperature: '22c',
time: "22:00" time: '22:00'
}); });
formProvider.updateForm(formId, obj2).then((data) => { formProvider.updateForm(formId, obj2).then((data) => {
console.log('FormExtensionAbility context updateForm, data:' + data); console.log('FormExtensionAbility context updateForm, data: ${data}');
}).catch((error) => { }).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error); console.error('Operation updateForm failed. Cause: ${error}');
}); });
} }
}; };
...@@ -141,23 +141,23 @@ Called to notify the widget provider of the change of visibility. ...@@ -141,23 +141,23 @@ Called to notify the widget provider of the change of visibility.
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData' import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider'; import formProvider from '@ohos.app.form.formProvider';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onChangeFormVisibility(newStatus) { onChangeFormVisibility(newStatus) {
console.log('FormExtensionAbility onChangeFormVisibility, newStatus:' + newStatus); console.log('FormExtensionAbility onChangeFormVisibility, newStatus: ${newStatus}');
let obj2 = formBindingData.createFormBindingData({ let obj2 = formBindingData.createFormBindingData({
temperature: "22c", temperature: '22c',
time: "22:00" time: '22:00'
}); });
for (let key in newStatus) { for (let key in newStatus) {
console.log('FormExtensionAbility onChangeFormVisibility, key:' + key + ", value=" + newStatus[key]); console.log('FormExtensionAbility onChangeFormVisibility, key: ${key}, value= ${newStatus[key]}');
formProvider.updateForm(key, obj2).then((data) => { formProvider.updateForm(key, obj2).then((data) => {
console.log('FormExtensionAbility context updateForm, data:' + data); console.log('FormExtensionAbility context updateForm, data: ${data}');
}).catch((error) => { }).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error); console.error('Operation updateForm failed. Cause: ${error}');
}); });
} }
} }
...@@ -186,7 +186,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; ...@@ -186,7 +186,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) { onFormEvent(formId, message) {
console.log('FormExtensionAbility onFormEvent, formId:' + formId + ", message:" + message); console.log('FormExtensionAbility onFormEvent, formId: ${formId}, message: ${message}');
} }
}; };
``` ```
...@@ -212,7 +212,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; ...@@ -212,7 +212,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onRemoveForm(formId) { onRemoveForm(formId) {
console.log('FormExtensionAbility onRemoveForm, formId:' + formId); console.log('FormExtensionAbility onRemoveForm, formId: ${formId}');
} }
}; };
``` ```
...@@ -238,7 +238,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; ...@@ -238,7 +238,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onConfigurationUpdate(config) { onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, config:' + JSON.stringify(config)); console.log('onConfigurationUpdate, config: ${JSON.stringify(config)}');
} }
}; };
``` ```
...@@ -265,7 +265,7 @@ import formInfo from '@ohos.app.form.formInfo'; ...@@ -265,7 +265,7 @@ import formInfo from '@ohos.app.form.formInfo';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onAcquireFormState(want) { onAcquireFormState(want) {
console.log('FormExtensionAbility onAcquireFormState, want:' + want); console.log('FormExtensionAbility onAcquireFormState, want: ${want}');
return formInfo.FormState.UNKNOWN; return formInfo.FormState.UNKNOWN;
} }
}; };
...@@ -300,10 +300,10 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; ...@@ -300,10 +300,10 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onShareForm(formId) { onShareForm(formId) {
console.log('FormExtensionAbility onShareForm, formId:' + formId); console.log('FormExtensionAbility onShareForm, formId: ${formId}');
let wantParams = { let wantParams = {
"temperature": "20", 'temperature': '20',
"time": "2022-8-8 09:59", 'time': '2022-8-8 09:59',
}; };
return wantParams; return wantParams;
} }
......
# @ohos.application.AbilityConstant (AbilityConstant)
The **AbilityConstant** module defines the ability-related enums, including the initial launch reasons, reasons for the last exit, ability continuation results, and window modes.
> **NOTE**
>
> The APIs of this module are supported since API version 9 and are deprecated in versions later than API version 9. You are advised to use [@ohos.app.ability.AbilityConstant](js-apis-app-ability-abilityConstant.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import AbilityConstant from '@ohos.application.AbilityConstant';
```
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| launchReason | [LaunchReason](#abilityconstantlaunchreason)| Yes| Yes| Ability launch reason.|
| lastExitReason | [LastExitReason](#abilityconstantlastexitreason) | Yes| Yes| Reason for the last exit.|
## AbilityConstant.LaunchReason
Enumerates the initial ability launch reasons.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | Unknown reason.|
| START_ABILITY | 1 | Ability startup.|
| CALL | 2 | Call.|
| CONTINUATION | 3 | Ability continuation.|
| APP_RECOVERY | 4 | Application recovery.|
## AbilityConstant.LastExitReason
Enumerates the reasons for the last exit.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | Unknown reason.|
| ABILITY_NOT_RESPONDING | 1 | The ability does not respond.|
| NORMAL | 2 | Normal status.|
## AbilityConstant.OnContinueResult
Enumerates the ability continuation results.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| AGREE | 0 | Continuation agreed.|
| REJECT | 1 | Continuation denied.|
| MISMATCH | 2 | Mismatch.|
## AbilityConstant.WindowMode
Enumerates the window modes in which an ability can be displayed at startup.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value| Description |
| --- | --- | --- |
| WINDOW_MODE_UNDEFINED | 0 | Undefined window mode. |
| WINDOW_MODE_FULLSCREEN | 1 | The ability is displayed in full screen. |
| WINDOW_MODE_SPLIT_PRIMARY | 100 | The ability is displayed in the primary window in split-screen mode. |
| WINDOW_MODE_SPLIT_SECONDARY | 101 | The ability is displayed in the secondary window in split-screen mode. |
| WINDOW_MODE_FLOATING | 102 | The ability is displayed in a floating window.|
## AbilityConstant.MemoryLevel
Enumerates the memory levels.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value| Description |
| --- | --- | --- |
| MEMORY_LEVEL_MODERATE | 0 | Moderate memory usage. |
| MEMORY_LEVEL_LOW | 1 | Low memory usage. |
| MEMORY_LEVEL_CRITICAL | 2 | High memory usage. |
## AbilityConstant.OnSaveResult
Enumerates the result types for the operation of saving application data.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| ALL_AGREE | 0 | Agreed to save the status.|
| CONTINUATION_REJECT | 1 | Rejected to save the status in continuation.|
| CONTINUATION_MISMATCH | 2 | Continuation mismatch.|
| RECOVERY_AGREE | 3 | Agreed to restore the saved status.|
| RECOVERY_REJECT | 4 | Rejected to restore the saved state.|
| ALL_REJECT | 5 | Rejected to save the status.|
## AbilityConstant.StateType
Enumerates the scenarios for saving application data.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| CONTINUATION | 0 | Saving the status in continuation.|
| APP_RECOVERY | 1 | Saving the status in application recovery.|
# @ohos.application.AbilityStage (AbilityStage)
**AbilityStage** is a runtime class for HAP files.
The **AbilityStage** module notifies you of when you can perform HAP initialization such as resource pre-loading and thread creation during the HAP loading.
> **NOTE**
>
> The APIs of this module are supported and deprecated since API version 9. You are advised to use [@ohos.app.ability.AbilityStage](js-apis-app-ability-abilityStage.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import AbilityStage from '@ohos.application.AbilityStage';
```
## AbilityStage.onCreate
onCreate(): void
Called when the application is created.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Example**
```ts
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called")
}
}
```
## AbilityStage.onAcceptWant
onAcceptWant(want: Want): string;
Called when a UIAbility is started.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | Yes| Want information about the target UIAbility, such as the ability name and bundle name.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | Returns a UIAbility ID. If this UIAbility has been started, no new instance is created and the UIAbility is placed at the top of the stack. Otherwise, a new instance is created and started.|
**Example**
```ts
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
return "com.example.test";
}
}
```
## AbilityStage.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void;
Called when the global configuration is updated.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-application-configuration.md) | Yes| Callback invoked when the global configuration is updated. The global configuration indicates the configuration of the environment where the application is running and includes the language and color mode.|
**Example**
```ts
class MyAbilityStage extends AbilityStage {
onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, language:' + config.language);
}
}
```
## AbilityStage.onMemoryLevel
onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
Called when the system has decided to adjust the memory level. For example, this API can be used when there is not enough memory to run as many background processes as possible.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| level | [AbilityConstant.MemoryLevel](js-apis-application-abilityConstant.md#abilityconstantmemorylevel) | Yes| Memory level that indicates the memory usage status. When the specified memory level is reached, a callback will be invoked and the system will start adjustment.|
**Example**
```ts
class MyAbilityStage extends AbilityStage {
onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level));
}
}
```
## AbilityStage.context
context: AbilityStageContext;
Defines the **Context** object of **AbilityStage**.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Description |
| ------- | ------------------------------------------------------------ | -------------------------- |
| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | **Context** object of AbilityStage.|
# @ohos.application.context (Context)
The **Context** module provides all level-2 module APIs for developers to export.
> **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 of this module can be used only in the stage model.
## Modules to Import
```ts
import context from '@ohos.application.context'
```
**System capability**: SystemCapability.Ability.AbilityBase
| Name | Readable/Writable| Type | Mandatory| Description |
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| AbilityContext | Read Only | [AbilityContext](js-apis-ability-context.md) | No | Level-2 module **AbilityContext**. |
| AbilityStageContext | Read Only | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | No | Level-2 module **AbilityStageContext**.|
| ApplicationContext | Read Only | [ApplicationContext](js-apis-inner-application-applicationContext.md) | No | Level-2 module **ApplicationContext**.|
| BaseContext | Read Only | [BaseContext](js-apis-inner-application-baseContext.md) | No | Level-2 module **BaseContext**.|
| Context | Read Only | [Context](js-apis-inner-application-context.md) | No | Level-2 module **Context**.|
| ExtensionContext | Read Only | [ExtensionContext](js-apis-inner-application-extensionContext.md) | No | Level-2 module **ExtensionContext**.|
| FormExtensionContext | Read Only | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | No | Level-2 module **FormExtensionContext**.|
| EventHub | Read Only | [EventHub](js-apis-inner-application-eventHub.md) | No | Level-2 module **EventHub**.|
| PermissionRequestResult | Read Only | [PermissionRequestResult](js-apis-inner-application-permissionRequestResult.md) | No | Level-2 module **PermissionRequestResult**.|
**Example**
```ts
let abilityContext: context.AbilityContext;
let abilityStageContext: context.AbilityStageContext;
let applicationContext: context.ApplicationContext;
let baseContext: context.BaseContext;
let context: context.Context;
let extensionContext: context.ExtensionContext;
let formExtensionContext: context.FormExtensionContext;
let eventHub: context.EventHub;
let permissionRequestResult: context.PermissionRequestResult;
```
# @ohos.application.ExtensionAbility (ExtensionAbility)
The **ExtensionAbility** module manages the ExtensionAbility lifecycle and context, such as creating and destroying an ExtensionAbility, and dumping client information.
> **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 of this module can be used only in the stage model.
## Modules to Import
```ts
import ExtensionAbility from '@ohos.application.ExtensionAbility';
```
## ExtensionAbility.onConfigurationUpdated
onConfigurationUpdated(newConfig: Configuration): void;
Called when the configuration of the environment where the ability is running is updated.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| newConfig | [Configuration](js-apis-application-configuration.md) | Yes| New configuration.|
**Example**
```ts
class MyExtensionAbility extends ExtensionAbility {
onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, config:' + JSON.stringify(config));
}
}
```
## ExtensionAbility.onMemoryLevel
onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
Called when the system has decided to adjust the memory level. For example, this API can be used when there is not enough memory to run as many background processes as possible.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| level | [AbilityConstant.MemoryLevel](js-apis-application-abilityConstant.md#abilityconstantmemorylevel) | Yes| Memory level that indicates the memory usage status. When the specified memory level is reached, a callback will be invoked and the system will start adjustment.|
**Example**
```ts
class MyExtensionAbility extends ExtensionAbility {
onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level));
}
}
```
# @ohos.application.FormExtension (FormExtension)
The **FormExtension** module provides APIs related to Form Extension abilities.
> **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.
> This module is deprecated since API version 9. You are advised to use [FormExtensionAbility](js-apis-app-form-formExtensionAbility.md) instead.
> The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import FormExtension from '@ohos.application.FormExtension';
```
## Attributes
**System capability**: SystemCapability.Ability.Form
| Name | Type | Readable| Writable| Description |
| ------- | ------------------------------------------------------- | ---- | ---- | --------------------------------------------------- |
| context | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | Yes | No | Context of the **FormExtension**. This context is inherited from **ExtensionContext**.|
## onCreate
onCreate(want: Want): formBindingData.FormBindingData
Called to notify the widget provider that a **Form** instance (widget) has been created.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------------------------------- | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-want.md) | Yes | Information related to the extension, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ----------------------------------------------------------- |
| [formBindingData.FormBindingData](js-apis-application-formBindingData.md#formbindingdata) | A **formBindingData.FormBindingData** object containing the data to be displayed on the widget.|
**Example**
```ts
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onCreate(want) {
console.log('FormExtension onCreate, want:' + want.abilityName);
let dataObj1 = {
temperature:"11c",
"time":"11:00"
};
let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1;
}
}
```
## FormExtension.onCastToNormal
onCastToNormal(formId: string): void
Called to notify the widget provider that a temporary widget has been converted to a normal one.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------ |
| formId | string | Yes | ID of the widget that requests to be converted to a normal one.|
**Example**
```ts
export default class MyFormExtension extends FormExtension {
onCastToNormal(formId) {
console.log('FormExtension onCastToNormal, formId:' + formId);
}
}
```
## FormExtension.onUpdate
onUpdate(formId: string): void
Called to notify the widget provider that a widget has been updated. After obtaining the latest data, the caller invokes **updateForm** of the [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) class to update the widget data.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| formId | string | Yes | ID of the widget that requests to be updated.|
**Example**
```ts
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onUpdate(formId) {
console.log('FormExtension onUpdate, formId:' + formId);
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2).then((data)=>{
console.log('FormExtension context updateForm, data:' + data);
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error);});
}
}
```
## FormExtension.onVisibilityChange
onVisibilityChange(newStatus: { [key: string]: number }): void
Called to notify the widget provider of the change of visibility.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------- |
| newStatus | { [key: string]: number } | Yes | ID and visibility status of the widget to be changed.|
**Example**
```ts
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onVisibilityChange(newStatus) {
console.log('FormExtension onVisibilityChange, newStatus:' + newStatus);
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
for (let key in newStatus) {
console.log('FormExtension onVisibilityChange, key:' + key + ", value=" + newStatus[key]);
this.context.updateForm(key, obj2).then((data)=>{
console.log('FormExtension context updateForm, data:' + data);
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error);});
}
}
}
```
## FormExtension.onEvent
onEvent(formId: string, message: string): void
Called to instruct the widget provider to receive and process the widget event.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------- |
| formId | string | Yes | ID of the widget that requests the event.|
| message | string | Yes | Event message. |
**Example**
```ts
export default class MyFormExtension extends FormExtension {
onEvent(formId, message) {
console.log('FormExtension onEvent, formId:' + formId + ", message:" + message);
}
}
```
## FormExtension.onDestroy
onDestroy(formId: string): void
Called to notify the widget provider that a **Form** instance (widget) has been destroyed.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| formId | string | Yes | ID of the widget to be destroyed.|
**Example**
```ts
export default class MyFormExtension extends FormExtension {
onDestroy(formId) {
console.log('FormExtension onDestroy, formId:' + formId);
}
}
```
## FormExtension.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void;
Called when the configuration of the environment where the ability is running is updated.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-application-configuration.md) | Yes| New configuration.|
**Example**
```ts
class MyFormExtension extends FormExtension {
onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, config:' + JSON.stringify(config));
}
}
```
## FormExtension.onAcquireFormState
onAcquireFormState?(want: Want): formInfo.FormState;
Called when the widget provider receives the status query result of a widget. By default, the initial state is returned.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | Yes| Description of the widget state, including the bundle name, ability name, module name, widget name, and widget dimension.|
**Example**
```ts
import formInfo from '@ohos.application.formInfo'
class MyFormExtension extends FormExtension {
onAcquireFormState(want) {
console.log('FormExtension onAcquireFormState, want:' + want);
return formInfo.FormState.UNKNOWN;
}
}
```
## FormExtension.onShare
onShare?(formId: string): {[key: string]: any};
Called by the widget provider to receive shared widget data.
**System API**: This is a system API.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| formId | string | Yes | Widget ID.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ----------------------------------------------------------- |
| {[key: string]: any} | Data to be shared by the widget, in the form of key-value pairs.|
**Example**
```ts
class MyFormExtension extends FormExtension {
onShare(formId) {
console.log('FormExtension onShare, formId:' + formId);
let wantParams = {
"temperature":"20",
"time":"2022-8-8 09:59",
};
return wantParams;
}
}
```
# @ohos.application.ServiceExtensionAbility (ServiceExtensionAbility)
The **ServiceExtensionAbility** module provides APIs for Service Extension abilities.
> **NOTE**
>
> The APIs of this module are supported since API version 9 and are deprecated in versions later than API version 9. You are advised to use [@ohos.app.ability.ServiceExtensionAbility](js-apis-app-ability-serviceExtensionAbility.md) instead.
>
> Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import ServiceExtensionAbility from '@ohos.application.ServiceExtensionAbility';
```
## Required Permissions
None.
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| context | [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md) | Yes| No| Service Extension context, which is inherited from **ExtensionContext**.|
## ServiceExtensionAbility.onCreate
onCreate(want: Want): void;
Called when a Service Extension ability is created to initialize the service logic.
**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|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
**Example**
```ts
class ServiceExt extends ServiceExtension {
onCreate(want) {
console.log('onCreate, want:' + want.abilityName);
}
}
```
## ServiceExtensionAbility.onDestroy
onDestroy(): void;
Called when this Service Extension ability is destroyed to clear resources.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Example**
```ts
class ServiceExt extends ServiceExtension {
onDestroy() {
console.log('onDestroy');
}
}
```
## ServiceExtensionAbility.onRequest
onRequest(want: Want, startId: number): void;
Called after **onCreate** is invoked when a Service Extension ability is started by calling **startAbility**. The value of **startId** is incremented for each ability that is started.
**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|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
| startId | number | Yes| Number of ability start times. The initial value is **1**, and the value is automatically incremented for each ability started.|
**Example**
```ts
class ServiceExt extends ServiceExtension {
onRequest(want, startId) {
console.log('onRequest, want:' + want.abilityName);
}
}
```
## ServiceExtensionAbility.onConnect
onConnect(want: Want): rpc.RemoteObject;
Called after **onCreate** is invoked when a Service Extension ability is started by calling **connectAbility**. A **RemoteObject** object is returned for communication with the client.
**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|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
**Return value**
| Type| Description|
| -------- | -------- |
| rpc.RemoteObject | A **RemoteObject** object used for communication with the client.|
**Example**
```ts
import rpc from '@ohos.rpc'
class StubTest extends rpc.RemoteObject{
constructor(des) {
super(des);
}
onConnect(code, data, reply, option) {
}
}
class ServiceExt extends ServiceExtension {
onConnect(want) {
console.log('onConnect , want:' + want.abilityName);
return new StubTest("test");
}
}
```
## ServiceExtensionAbility.onDisconnect
onDisconnect(want: Want): void;
Called when this Service Extension ability is disconnected.
**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|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
**Example**
```ts
class ServiceExt extends ServiceExtension {
onDisconnect(want) {
console.log('onDisconnect, want:' + want.abilityName);
}
}
```
## ServiceExtensionAbility.onReconnect
onReconnect(want: Want): void;
Called when this Service Extension ability is reconnected.
**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|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
**Example**
```ts
class ServiceExt extends ServiceExtension {
onReconnect(want) {
console.log('onReconnect, want:' + want.abilityName);
}
}
```
## ServiceExtensionAbility.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void;
Called when the configuration of this Service Extension ability is updated.
**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|
| -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-application-configuration.md) | Yes| New configuration.|
**Example**
```ts
class ServiceExt extends ServiceExtension {
onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, config:' + JSON.stringify(config));
}
}
```
## ServiceExtensionAbility.dump
dump(params: Array\<string>): Array\<string>;
Dumps the client information.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| params | Array\<string> | Yes| Parameters in the form of a command.|
**Example**
```ts
class ServiceExt extends ServiceExtension {
dump(params) {
console.log('dump, params:' + JSON.stringify(params));
return ["params"]
}
}
```
# @ohos.application.StartOptions (StartOptions)
The **StartOptions** module implements ability startup options.
> **NOTE**
>
> The APIs of this module are supported since API version 9 and are deprecated in versions later than API version 9. You are advised to use [@ohos.app.ability.StartOptions](js-apis-app-ability-startOptions.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import StartOptions from '@ohos.application.StartOptions';
```
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| [windowMode](js-apis-application-abilityConstant.md#abilityconstantwindowmode) | number | No| Window mode.|
| displayId | number | No| Display ID.|
...@@ -6,8 +6,6 @@ The **BundleInfo** module defines the bundle information. A system application c ...@@ -6,8 +6,6 @@ The **BundleInfo** module defines the bundle information. A system application c
> >
> 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 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.
## BundleInfo ## BundleInfo
**System capability**: SystemCapability.BundleManager.BundleFramework.Core **System capability**: SystemCapability.BundleManager.BundleFramework.Core
......
# ExtensionAbilityInfo # ExtensionAbilityInfo
The **ExtensionAbilityInfo** module defines the ExtensionAbility information. A system application can obtain its own or others' ExtensionAbility information through [bundleManager.getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo). A third-party application can obtain its own ExtensionAbility information through [getBundleInfoForSelf](js-apis-bundleManager.md#bundlemanagergetbundleinfoforself). **GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY** must be passed in to the input parameter [bundleFlags](js-apis-bundleManager.md#bundleflag) to obtain the information. The **ExtensionAbilityInfo** module defines the ExtensionAbility information. A system application can obtain its own or others' ExtensionAbility information through [bundleManager.getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo). A third-party application can obtain its own ExtensionAbility information through [getBundleInfoForSelf](js-apis-bundleManager.md#bundlemanagergetbundleinfoforself). The input parameter [bundleFlags](js-apis-bundleManager.md#bundleflag) must be set to **GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY**.
> **NOTE** > **NOTE**
> >
...@@ -18,7 +18,7 @@ The **ExtensionAbilityInfo** module defines the ExtensionAbility information. A ...@@ -18,7 +18,7 @@ The **ExtensionAbilityInfo** module defines the ExtensionAbility information. A
| labelId | number | Yes | No | ID of the ExtensionAbility label. | | labelId | number | Yes | No | ID of the ExtensionAbility label. |
| descriptionId | number | Yes | No | ID of the ExtensionAbility description. | | descriptionId | number | Yes | No | ID of the ExtensionAbility description. |
| iconId | number | Yes | No | ID of the ExtensionAbility icon. | | iconId | number | Yes | No | ID of the ExtensionAbility icon. |
| isVisible | boolean | Yes | No | Whether the ExtensionAbility can be called by other bundles. | | exported | boolean | Yes | No | Whether the ExtensionAbility can be called by other bundles. |
| extensionAbilityType | [ExtensionAbilityType](js-apis-bundleManager.md#extensionabilitytype) | Yes | No | Type of the ExtensionAbility. | | extensionAbilityType | [ExtensionAbilityType](js-apis-bundleManager.md#extensionabilitytype) | Yes | No | Type of the ExtensionAbility. |
| permissions | Array\<string> | Yes | No | Permissions required for other bundles to call the ExtensionAbility.| | permissions | Array\<string> | Yes | No | Permissions required for other bundles to call the ExtensionAbility.|
| applicationInfo | [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | Yes | No | Application information. | | applicationInfo | [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | Yes | No | Application information. |
......
# HapModuleInfo # HapModuleInfo
The **HapModuleInfo** module defines the HAP module information. A system application can obtain its own or others' HAP module information through [bundleManager.getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo). A third-party application can obtain its own HAP module information through [getBundleInfoForSelf](js-apis-bundleManager.md#bundlemanagergetbundleinfoforself). **GET_BUNDLE_INFO_WITH_HAP_MODULE** must be passed in to the input parameter [bundleFlags](js-apis-bundleManager.md#bundleflag) to obtain the information. The **HapModuleInfo** module defines the HAP module information. A system application can obtain its own or others' HAP module information through [bundleManager.getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo). A third-party application can obtain its own HAP module information through [getBundleInfoForSelf](js-apis-bundleManager.md#bundlemanagergetbundleinfoforself). The input parameter [bundleFlags](js-apis-bundleManager.md#bundleflag) must be set to **GET_BUNDLE_INFO_WITH_HAP_MODULE**.
> **NOTE** > **NOTE**
> >
......
# PermissionRequestResult
The **PermissionRequestResult** module provides the result of a permission request.
> **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 of this module can be used only in the stage model.
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| No| Permissions requested.|
| authResults | Array&lt;number&gt; | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and a non-zero value means the opposite. |
## How to Use
The permission request result is obtained through an **AbilityStage** instance.
**Example**
```ts
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
var permissions=['com.example.permission']
var permissionRequestResult;
this.context.requestPermissionsFromUser(permissions,(err,result) => {
if(err){
console.log('requestPermissionsFromUserError: ' + JSON.stringify(err));
}else{
permissionRequestResult=result;
console.log('permissionRequestResult: ' + JSON.stringify(permissionRequestResult));
}
});
}
}
```
# ProcessRunningInformation # ProcessInformation
The **ProcessRunningInformation** module defines the running information of a process. The **ProcessInformation** module defines the running information of a process.
> **NOTE** > **NOTE**
> >
...@@ -8,13 +8,13 @@ The **ProcessRunningInformation** module defines the running information of a pr ...@@ -8,13 +8,13 @@ The **ProcessRunningInformation** module defines the running information of a pr
## How to Use ## How to Use
The process running information is obtained through [getProcessRunningInformation](js-apis-application-appManager.md#appmanagergetprocessrunninginformation9) in **appManager**. The process information is obtained by calling [getRunningProcessInformation](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinformation9) of the **appManager** module.
```ts ```ts
import appManager from '@ohos.application.appManager'; import appManager from '@ohos.app.ability.appManager';
appManager.getProcessRunningInformation((error, data) => { appManager.getRunningProcessInformation((error, data) => {
console.log("error: " + error.code + " data: " + JSON.stringify(data)); console.log('error: ${error.code}, data: ${JSON.stringify(data)}');
}); });
``` ```
...@@ -28,3 +28,5 @@ appManager.getProcessRunningInformation((error, data) => { ...@@ -28,3 +28,5 @@ appManager.getProcessRunningInformation((error, data) => {
| uid | number | Yes| No| User ID.| | uid | number | Yes| No| User ID.|
| processName | string | Yes| No| Process name.| | processName | string | Yes| No| Process name.|
| bundleNames | Array&lt;string&gt; | Yes| No| Names of all running bundles in the process.| | bundleNames | Array&lt;string&gt; | Yes| No| Names of all running bundles in the process.|
<!--no_check-->
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
The **ProcessRunningInfo** module defines the running information of a process. The **ProcessRunningInfo** module defines the running information of a process.
> **NOTE** > **NOTE**
> - The APIs provided by this module are deprecated since API version 9. You are advised to use [ProcessRunningInformation<sup>9+</sup>](js-apis-inner-application-processRunningInformation.md) instead. > - The APIs provided by this module are deprecated since API version 9. You are advised to use [ProcessInformation<sup>9+</sup>](js-apis-inner-application-processInformation.md) instead.
> - The initial APIs of this module are supported since API version 8. > - The initial APIs of this module are supported since API version 8.
## Attributes ## Attributes
...@@ -26,8 +26,8 @@ The process running information is obtained by using [getProcessRunningInfos](js ...@@ -26,8 +26,8 @@ The process running information is obtained by using [getProcessRunningInfos](js
import appManager from '@ohos.app.ability.appManager'; import appManager from '@ohos.app.ability.appManager';
appManager.getProcessRunningInfos().then((data) => { appManager.getProcessRunningInfos().then((data) => {
console.log('success:' + JSON.stringify(data)); console.log('success: ${JSON.stringify(data)}');
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringify(error)); console.log('failed: ${JSON.stringify(error)}');
}); });
``` ```
# @ohos.securityLabel (Data Label)
The **secuityLabel** module provides APIs to manage file data security levels, including obtaining and setting file data security levels.
> **NOTE**
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import securityLabel from '@ohos.securityLabel';
```
## Usage
Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox as follows:
```js
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let path = '';
context.getFilesDir().then((data) => {
path = data;
})
```
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, type:dataLevel):Promise&lt;void&gt;
Sets the security label for a file in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| type | dataLevel | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
**Return value**
| Type | Description |
| ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value will be returned.|
**Example**
```js
securityLabel.setSecurityLabel(path, "s0").then(function(){
console.info("setSecurityLabel successfully");
}).catch(function(error){
console.info("setSecurityLabel failed with error:" + error);
});
```
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, type:dataLevel, callback: AsyncCallback&lt;void&gt;):void
Sets the security label for a file in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| type | dataLevel | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example**
```js
securityLabel.setSecurityLabel(path, "s0", function(error){
console.info("setSecurityLabel:" + JSON.stringify(error));
});
```
## securityLabel.setSecurityLabelSync
setSecurityLabelSync(path:string, type:dataLevel):void
Sets the security label for a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| type | dataLevel | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
**Example**
```js
securityLabel.setSecurityLabelSync(path, "s0");
```
## securityLabel.getSecurityLabel
getSecurityLabel(path:string):Promise&lt;string&gt;
Obtains the security label of a file in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------- |
| path | string | Yes | File path.|
**Return value**
| Type | Description |
| --------------------- | ------------ |
| Promise&lt;string&gt; | Promise used to return the security label obtained.|
**Example**
```js
securityLabel.getSecurityLabel(path).then(function(type){
console.log("getSecurityLabel successfully:" + type);
}).catch(function(err){
console.log("getSecurityLabel failed with error:" + err);
});
```
## securityLabel.getSecurityLabel
getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void
Obtains the security label of a file in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | -------------------------- |
| path | string | Yes | File path. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the security label obtained.|
**Example**
```js
securityLabel.getSecurityLabel(path, function(err, type){
console.log("getSecurityLabel successfully:" + type);
});
```
## securityLabel.getSecurityLabelSync
getSecurityLabelSync(path:string):string
Obtains the security label of a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------- |
| path | string | Yes | File path.|
**Return value**
| Type | Description |
| ------ | ------------ |
| string | Security label obtained.|
**Example**
```js
let result = securityLabel.getSecurityLabelSync(path);
console.log("getSecurityLabel successfully:" + result);
```
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
- Security - Security
- [Ability Access Control Error Codes](errorcode-access-token.md) - [Ability Access Control Error Codes](errorcode-access-token.md)
- [HUKS Error Codes](errorcode-huks.md) - [HUKS Error Codes](errorcode-huks.md)
- [Crypto Framework Error Codes](errorcode-crypto-framework.md)
- [Certificate Error Codes](errorcode-cert.md)
- [User Authentication Error Codes](errorcode-useriam.md) - [User Authentication Error Codes](errorcode-useriam.md)
- Data Management - Data Management
- [RDB Error Codes](errorcode-data-rdb.md) - [RDB Error Codes](errorcode-data-rdb.md)
...@@ -57,6 +59,7 @@ ...@@ -57,6 +59,7 @@
- [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) - [Input Method Framework Error Codes](errorcode-inputmethod-framework.md)
- [Pasteboard Error Codes](errorcode-pasteboard.md) - [Pasteboard Error Codes](errorcode-pasteboard.md)
- [Screen Lock Management Error Codes](errorcode-screenlock.md) - [Screen Lock Management Error Codes](errorcode-screenlock.md)
- [Time and Time Zone Service Error Codes](errorcode-time.md)
- [Webview Error Codes](errorcode-webview.md) - [Webview Error Codes](errorcode-webview.md)
- Account Management - Account Management
- [Account Error Codes](errorcode-account.md) - [Account Error Codes](errorcode-account.md)
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
- Certificate - Certificate
- [Certificate Overview](cert-overview.md) - [Certificate Overview](cert-overview.md)
- [Certificate Development](cert-guidelines.md) - [Certificate Development](cert-guidelines.md)
- hapsigner - hapsigner
- [hapsigner Overview](hapsigntool-overview.md) - [hapsigner Overview](hapsigntool-overview.md)
- [hapsigner Guide](hapsigntool-guidelines.md) - [hapsigner Guide](hapsigntool-guidelines.md)
- [HarmonyAppProvision Configuration File](app-provision-structure.md) - [HarmonyAppProvision Configuration File](app-provision-structure.md)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册