diff --git a/CODEOWNERS b/CODEOWNERS index f020f650d38dda1d697c0cadfc2ba9b5a987ee1f..1e61b5d70d7ea0768b8683ea7956a4b34e212a5c 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -481,6 +481,7 @@ zh-cn/application-dev/reference/apis/js-apis-WorkSchedulerExtensionAbility.md @w zh-cn/application-dev/reference/apis/js-apis-xml.md @gongjunsong @ge-yafang @flyingwolf @BlackStone zh-cn/application-dev/reference/apis/js-apis-zlib.md @shuaytao @RayShih @wangzhen107 @inter515 zh-cn/application-dev/reference/apis/js-apis-webview.md @bigpumpkin @HelloCrease @litao33 @zhang-xinyue15 +zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md @bigpumpkin @HelloCrease @litao33 @zhang-xinyue15 zh-cn/application-dev/reference/apis/js-apis-ability-ability.md @littlejerry1 @RayShih @gwang2008 @chengxingzhen zh-cn/application-dev/reference/apis/js-apis-ability-abilityResult.md @littlejerry1 @RayShih @gwang2008 @chengxingzhen zh-cn/application-dev/reference/apis/js-apis-ability-Want.md @littlejerry1 @RayShih @gwang2008 @chengxingzhen @@ -516,6 +517,7 @@ zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md @jayleehw @Ra zh-cn/application-dev/reference/apis/js-apis-configPolicy.md @Buda-Liu @ningningW @budda-wang @yangqing3 zh-cn/application-dev/reference/apis/js-apis-cooperate.md @mayunteng_1 @ningningW @cococoler @alien0208 zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md @gaoyong @zengyawen @niejiteng @jumozhanjiang +zh-cn/application-dev/reference/apis/js-apis-cert.md @gaoyong @zengyawen @niejiteng @jumozhanjiang zh-cn/application-dev/reference/apis/js-apis-curve.md @huaweimaxuchu @HelloCrease @niulihua @tomatodevboy zh-cn/application-dev/reference/apis/js-apis-defaultAppManager.md @shuaytao @RayShih @wangzhen107 @inter515 zh-cn/application-dev/reference/apis/js-apis-distributedBundle.md @shuaytao @RayShih @wangzhen107 @inter515 @@ -534,7 +536,7 @@ zh-cn/application-dev/reference/apis/js-apis-matrix4.md @huaweimaxuchu @HelloCre zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md @zhang-hai-feng @zengyawen @jyh926 @gaoxi785 zh-cn/application-dev/reference/apis/js-apis-net-sharing.md @zhang-hai-feng @zengyawen @jyh926 @gaoxi785 zh-cn/application-dev/reference/apis/js-apis-nfctech.md @cheng_guohong @RayShih @cheng_guohong @quanli125 -zh-cn/application-dev/reference/apis/js-apis-promptAction.md @cheng_guohong @RayShih @cheng_guohong @quanli125 +zh-cn/application-dev/reference/apis/js-apis-promptAction.md @huaweimaxuchu @HelloCrease @niulihua @tomatodevboy zh-cn/application-dev/reference/apis/js-apis-reminderAgentManager.md @wangwenli_wolf @ningningW @tangtiantian2021 @nan-xiansen zh-cn/application-dev/reference/apis/js-apis-resourceschedule-backgroundTaskManager.md @wangwenli_wolf @ningningW @tangtiantian2021 @nan-xiansen zh-cn/application-dev/reference/apis/js-apis-resourceschedule-deviceUsageStatistics.md @wangwenli_wolf @ningningW @tangtiantian2021 @nan-xiansen diff --git a/en/application-dev/application-models/Readme-EN.md b/en/application-dev/application-models/Readme-EN.md index a9473b7f6c2d0fb75e160cafdd1fb94b43633fa7..2a920300623358bc25f7256d6af8b957665bc600 100644 --- a/en/application-dev/application-models/Readme-EN.md +++ b/en/application-dev/application-models/Readme-EN.md @@ -1,2 +1,130 @@ # Application Models +- Application Model Overview + - [Elements of the Application Model](application-model-composition.md) + - [Interpretation of the Application Model](application-model-description.md) +- Stage Model Development + - [Stage Model Development Overview](stage-model-development-overview.md) + - Stage Mode Application Components + - [Application- or Component-Level Configuration](application-component-configuration-stage.md) + - UIAbility Component + - [UIAbility Component Overview](uiability-overview.md) + - [UIAbility Component Lifecycle](uiability-lifecycle.md) + - [UIAbility Component Launch Type](uiability-launch-type.md) + - [UIAbility Component Usage](uiability-usage.md) + - [Data Synchronization Between UIAbility and UI](uiability-data-sync-with-ui.md) + - [Interaction Between Intra-Device UIAbility Components](uiability-intra-device-interaction.md) + - ExtensionAbility Component + - [ExtensionAbility Component Overview](extensionability-overview.md) + - [ServiceExtensionAbility](serviceextensionability.md) + - [DataShareExtensionAbility](datashareextensionability.md) + - [FormExtensionAbility (Widget)](widget-development-stage.md) + - [AbilityStage Component Container](abilitystage.md) + - [Context](application-context-stage.md) + - Want + - [Want Overview](want-overview.md) + - [Matching Rules of Explicit Want and Implicit Want](explicit-implicit-want-mappings.md) + - [Common action and entities Values](actions-entities.md) + - [Using Explicit Want to Start an Ability](ability-startup-with-explicit-want.md) + - [Using Implicit Want to Open a Website](ability-startup-with-implicit-want.md) + - [Using Want to Share Data Between Applications](data-share-via-want.md) + - [Component Startup Rules](component-startup-rules.md) + - Inter-Device Application Component Interaction (Continuation) + - [Continuation Overview](inter-device-interaction-hop-overview.md) + - [Cross-Device Migration](hop-cross-device-migration.md) + - [Multi-device Collaboration](hop-multi-device-collaboration.md) + - IPC + - [Process Model](process-model-stage.md) + - Common Events + - [Introduction to Common Events](common-event-overview.md) + - [Subscribing to Common Events](common-event-subscription.md) + - [Publishing Common Events](common-event-publish.md) + - [Unsubscribing from Common Events](common-event-unsubscription.md) + - [Background Services](background-services.md) + - Inter-Thread Communication + - [Thread Model](thread-model-stage.md) + - [Using Emitter for Inter-Thread Communication](itc-with-emitter.md) + - [Using Worker for Inter-Thread Communication](itc-with-worker.md) + - Mission Management + - [Mission Management Scenarios](mission-management-overview.md) + - [Mission Management and Launch Type](mission-management-launch-type.md) + - [Page Stack and MissionList](page-mission-stack.md) + - [Application Configuration File](config-file-stage.md) +- FA Model Development + - [FA Model Development Overview](fa-model-development-overview.md) + - FA Mode Application Components + - [Application- or Component-Level Configuration](application-component-configuration-fa.md) + - PageAbility Component Development + - [PageAbility Component Overview](pageability-overview.md) + - [PageAbility Component Configuration](pageability-configuration.md) + - [PageAbility Lifecycle](pageability-lifecycle.md) + - [PageAbility Launch Type](pageability-launch-type.md) + - [Creating a PageAbility](create-pageability.md) + - [Starting a Local PageAbility](start-local-pageability.md) + - [Stopping a PageAbility](stop-pageability.md) + - [Starting a Remote PageAbility](start-remote-pageability.md) + - [Starting a Specified Page](start-page.md) + - [Window Properties](window-properties.md) + - [Requesting Permissions](request-permissions.md) + - [Redirection Rules](redirection-rules.md) + - ServiceAbility Component Development + - [ServiceAbility Component Overview](serviceability-overview.md) + - [ServiceAbility Component Configuration](serviceability-configuration.md) + - [ServiceAbility Lifecycle](serviceability-lifecycle.md) + - [Creating a ServiceAbility](create-serviceability.md) + - [Starting a ServiceAbility](start-serviceability.md) + - [Connecting to a ServiceAbility](connect-serviceability.md) + - DataAbility Component Development + - [DataAbility Component Overview](dataability-overview.md) + - [DataAbility Component Configuration](dataability-configuration.md) + - [DataAbility Lifecycle](dataability-lifecycle.md) + - [Creating a DataAbility](create-dataability.md) + - [Starting a DataAbility](start-dataability.md) + - [Accessing a DataAbility](access-dataability.md) + - [DataAbility Permission Control](dataability-permission-control.md) + - [Widget Development](widget-development-fa.md) + - [Context](application-context-fa.md) + - [Want](want-fa.md) + - [Component Startup Rules](component-startup-rules-fa.md) + - IPC + - [Process Model](process-model-fa.md) + - [Common Events](common-event-fa.md) + - [Background Services](rpc.md) + - Inter-Thread Communication + - [Thread Model](thread-model-fa.md) + - [Inter-Thread Communication](itc-fa-overview.md) + - [Mission Management](mission-management-fa.md) + - [Application Configuration File](config-file-fa.md) +- Development of Component Interaction Between the FA Model and Stage Model + - [Component Interaction Between the FA Model and Stage Model](fa-stage-interaction-overview.md) + - [Starting a UIAbility from the FA Model](start-uiability-from-fa.md) + - [Connecting to a ServiceExtensionAbility from the FA Model](bind-serviceextensionability-from-fa.md) + - [Accessing a DataShareExtensionAbility from the FA Model](access-datashareextensionability-from-fa.md) + - [Starting a PageAbility from the Stage Model](start-pageability-from-stage.md) + - [Connecting to a ServiceAbility from the Stage Model](bind-serviceability-from-stage.md) +- Switching from the FA Model to the Stage Model + - [Model Switching Overview](model-switch-overview.md) + - Configuration File Switching + - [Differences in Configuration Files](configuration-file-diff.md) + - [Switching of app and deviceConfig](app-deviceconfig-switch.md) + - [Switching of module](module-switch.md) + - Component Switching + - [PageAbility Switching](pageability-switch.md) + - [ServiceAbility Switching](serviceability-switch.md) + - [DataAbility Switching](dataability-switch.md) + - [Widget Switching](widget-switch.md) + - API Switching + - [API Switching Overview](api-switch-overview.md) + - [Context Switching](context-switch.md) + - [featureAbility Switching](featureability-switch.md) + - [particleAbility Switching](particleability-switch.md) + - [LifecycleForm Switching](lifecycleform-switch.md) + - [LifecycleApp Switching](lifecycleapp-switch.md) + - [LifecycleService Switching](lifecycleservice-switch.md) + - [LifecycleData Switching](lifecycledata-switch.md) + - [DataAbilityHelper Switching](dataabilityhelper-switch.md) + - [mediaLibrary Switching](medialibrary-switch.md) + - [request Switching](request-switch.md) + - [resourceManager Switching](resourcemanager-switch.md) + - [window Switching](window-switch.md) + - [Storage Switching](storage-switch.md) diff --git a/en/application-dev/application-models/ability-startup-with-explicit-want.md b/en/application-dev/application-models/ability-startup-with-explicit-want.md new file mode 100644 index 0000000000000000000000000000000000000000..9186379f32299ee7a42b7f82af4fc7f464c160d1 --- /dev/null +++ b/en/application-dev/application-models/ability-startup-with-explicit-want.md @@ -0,0 +1,4 @@ +# Using Explicit Want to Start an Ability + + +When a user touches a button in an application, the application often needs to start a UIAbility component to complete a specific task. If the **abilityName** and **bundleName** parameters are specified when starting a UIAbility, the explicit Want is used. For details about how to use the explicit Want, see [Starting UIAbility in the Same Application](uiability-intra-device-interaction.md#starting-uiability-in-the-same-application). diff --git a/en/application-dev/application-models/ability-startup-with-implicit-want.md b/en/application-dev/application-models/ability-startup-with-implicit-want.md new file mode 100644 index 0000000000000000000000000000000000000000..0a5ba865f4b8c9894523666de1582b012f8f2237 --- /dev/null +++ b/en/application-dev/application-models/ability-startup-with-implicit-want.md @@ -0,0 +1,83 @@ +# Using Implicit Want to Open a Website + + +## Prerequisites + +One or more browsers are installed on your device. + +The **module.json5** of a browser application is as follows: + +```json +"skills": [ + { + "entities": [ + "entity.system.browsable" + // ... + ], + "actions": [ + "ohos.want.action.viewData" + // ... + ], + "uris": [ + { + "scheme": "https", + "host": "www.test.com", + "port": "8080", + // Prefix matching is used. + "pathStartWith": "query", + "type": "text/*" + }, + { + "scheme": "http", + // ... + } + // ... + ] + }, +] +``` + + +## How to Develop + +1. Use the custom function **implicitStartAbility** to start an ability. + + ```ts + async implicitStartAbility() { + try { + let want = { + // Uncomment the line below if you want to implicitly query data only in the specific bundle. + // bundleName: "com.example.myapplication", + "action": "ohos.want.action.viewData", + // entities can be omitted. + "entities": [ "entity.system.browsable" ], + "uri": "https://www.test.com:8080/query/student", + "type": "text/plain" + } + let context = getContext(this) as common.UIAbilityContext; + await context.startAbility(want) + console.info(`explicit start ability succeed`) + } catch (error) { + console.info(`explicit start ability failed with ${error.code}`) + } + let context = getContext(this) as common.UIAbilityContext; + await context.startAbility(want) + console.info(`explicit start ability succeed`) + } catch (error) { + console.info(`explicit start ability failed with ${error.code}`) + } + } + ``` + + The matching process is as follows: + 1. If **action** in the passed **want** parameter is specified and is included in **actions** under **skills**, the matching is successful. + + 2. If **entities** in the passed **want** parameter is specified and is included in **entities** under **skills**, the matching is successful. + + 3. If **uri** in the passed **want** parameter is included in **uris** under **skills**, which is concatenated into `https://www.test.com:8080/query*` (where \* is a wildcard), the matching is successful. + + 4. If **type** in the passed **want** parameter is specified and is included in **type** under **skills**, the matching is successful. + +2. When there are multiple matching applications, a dialog box is displayed for you to select one of them. + +stage-want1 \ No newline at end of file diff --git a/en/application-dev/application-models/abilitystage.md b/en/application-dev/application-models/abilitystage.md new file mode 100644 index 0000000000000000000000000000000000000000..fa3aa07c60287688749c13035451d0b470e621ea --- /dev/null +++ b/en/application-dev/application-models/abilitystage.md @@ -0,0 +1,58 @@ +# AbilityStage Component Container + + +AbilityStage is a component container at the [module](../quick-start/application-package-structure-stage.md) level. When the HAP of an application is loaded for the first time, an AbilityStage instance is created. You can perform operations such as initialization on the instance. + + +An AbilityStage instance corresponds to a module. + + +AbilityStage is not automatically generated in the default project of DevEco Studio. To use AbilityStage, you can manually create an AbilityStage file. The procedure is as follows: + + +1. In the **ets** directory of the **Module** project, right-click and choose **New > Directory** to create a directory named **myabilitystage**. + +2. In the **myabilitystage** directory, right-click and choose **New > ts File** to create a file named **MyAbilityStage.ts**. + +3. Open the **MyAbilityStage.ts** file, and import the dependency package of AbilityStage. Customize a class that inherits from AbilityStage, and add the required lifecycle callbacks. The following code snippet adds the **onCreate()** lifecycle callback. + + ```ts + import AbilityStage from '@ohos.app.ability.AbilityStage'; + + export default class MyAbilityStage extends AbilityStage { + onCreate() { + // When the HAP of the application is loaded for the first time, initialize the module. + } + onAcceptWant(want) { + // Triggered only for the ability with the specified launch type. + return "MyAbilityStage"; + } + } + ``` + + +[AbilityStage](../reference/apis/js-apis-app-ability-abilityStage.md) has the lifecycle callback [onCreate()](../reference/apis/js-apis-app-ability-abilityStage.md#abilitystageoncreate) and the event callbacks [onAcceptWant()](../reference/apis/js-apis-app-ability-abilityStage.md#abilitystageonacceptwant), [onConfigurationUpdated()](../reference/apis/js-apis-app-ability-abilityStage.md#abilitystageonconfigurationupdate), and [onMemoryLevel()](../reference/apis/js-apis-app-ability-abilityStage.md#abilitystageonmemorylevel). + + +- **onCreate()** lifecycle callback: Before the first UIAbility instance of a module is loaded, an AbilityStage instance is created. This callback is invoked when the AbilityStage instance is created. The AbilityStage module notifies you of when you can perform module initialization such as resource pre-loading and thread creation during module loading. + +- **onAcceptWant()** event callback: triggered when the UIAbility is started in [specified mode](uiability-launch-type.md#specified). For details, see [UIAbility Component Launch Type](uiability-launch-type.md). + +- **onConfigurationUpdated()** event callback: triggered when the global system configuration changes. The global system configuration, such as the system language and theme, are defined in the [Configuration](../reference/apis/js-apis-app-ability-configuration.md) class before project configuration. + +- **onMemoryLevel()** event callback: triggered when the system adjusts the memory. + +When an application is switched to the background, it is cached in the background. This adversely affects the overall system performance. When system resources are insufficient, the system reclaims memory from applications in multiple ways. For example, the system may stop applications to release memory for executing key tasks. To further maintain the balance of the system memory and prevent the system from stopping application processes, you can subscribe to the system memory changes in the **onMemoryLevel()** lifecycle callback of AbilityStage to release unnecessary resources. + + + ```ts + import AbilityStage from '@ohos.app.ability.AbilityStage'; + + export default class MyAbilityStage extends AbilityStage { + onMemoryLevel(level) { + // Release unnecessary memory based on the change of available system memory. + } + } + ``` + + \ No newline at end of file diff --git a/en/application-dev/application-models/access-dataability.md b/en/application-dev/application-models/access-dataability.md new file mode 100644 index 0000000000000000000000000000000000000000..24dc9305f194a61c974c63db224f2e7727689f5f --- /dev/null +++ b/en/application-dev/application-models/access-dataability.md @@ -0,0 +1,204 @@ +# Accessing a DataAbility + + +To access a DataAbility, import the basic dependency packages and obtain the URI string for communicating with the DataAbility. + + +The basic dependency packages include: + + +- @ohos.ability.featureAbility + +- @ohos.data.dataAbility + +- @ohos.data.rdb + + +The sample code for accessing a DataAbility is as follows: + + +1. Create a **DataAbilityHelper** instance. + + ```ts + // Different from the URI defined in the config.json file, the URI passed in the parameter has an extra slash (/), three slashes in total. + import featureAbility from '@ohos.ability.featureAbility' + import ohos_data_ability from '@ohos.data.dataAbility' + import ohos_data_rdb from '@ohos.data.rdb' + + let urivar = "dataability:///com.ix.DataAbility" + let DAHelper = featureAbility.acquireDataAbilityHelper(urivar); + ``` + +2. Construct RDB data. + + ```ts + let valuesBucket = {"name": "gaolu"} + let da = new ohos_data_ability.DataAbilityPredicates() + let valArray =new Array("value1"); + let cars = new Array({"batchInsert1" : "value1",}); + ``` + + For details about DataAbilityPredicates, see [DataAbility Predicates](../reference/apis/js-apis-data-ability.md). + +3. Use **insert** to insert data to the DataAbility. + + ```ts + // Callback mode: + DAHelper.insert( + urivar, + valuesBucket, + (error, data) => { + console.info("DAHelper insert result: " + data) + } + ); + ``` + + + ```ts + // Promise mode (await needs to be used in the asynchronous method): + let datainsert = await DAHelper.insert(urivar, valuesBucket).then((data) => { + console.info("insert success."); + }).catch((error) => { + console.error("insert failed."); + }); + ``` + +4. Use **delete** to delete data from the DataAbility. + + ```ts + // Callback mode: + DAHelper.delete( + urivar, + da, + (error, data) => { + console.info("DAHelper delete result: " + data) + } + ); + ``` + + + ```ts + // Promise mode (await needs to be used in the asynchronous method): + let datadelete = await DAHelper.delete( + urivar, + da, + ); + ``` + +5. Use **update** to update data in the DataAbility. + + ```ts + // Callback mode: + DAHelper.update( + urivar, + valuesBucket, + da, + (error, data) => { + console.info("DAHelper update result: " + data) + } + ); + ``` + + + ```ts + // Promise mode (await needs to be used in the asynchronous method): + let dataupdate = await DAHelper.update( + urivar, + valuesBucket, + da, + ); + ``` + +6. Use **query** to query data in the DataAbility. + + ```ts + // Callback mode: + DAHelper.query( + urivar, + valArray, + da, + (error, data) => { + console.info("DAHelper query result: " + data) + } + ); + ``` + + + ```ts + // Promise mode (await needs to be used in the asynchronous method): + let dataquery = await DAHelper.query( + urivar, + valArray, + da + ); + ``` + +7. Use **batchInsert** to insert data in batches to the DataAbility. + + ```ts + // Callback mode: + DAHelper.batchInsert( + urivar, + cars, + (error, data) => { + console.info("DAHelper batchInsert result: " + data) + } + ); + ``` + + + ```ts + // Promise mode (await needs to be used in the asynchronous method): + let databatchInsert = await DAHelper.batchInsert( + urivar, + cars + ); + ``` + +8. Use **executeBatch** to process data in batches in the DataAbility. + + ```ts + // Callback mode: + DAHelper.executeBatch( + urivar, + [ + { + uri: urivar, + type: featureAbility.DataAbilityOperationType.TYPE_INSERT, + valuesBucket: {"executeBatch" : "value1",}, + predicates: da, + expectedCount:0, + predicatesBackReferences: null, + interrupted:true, + } + ], + (error, data) => { + console.info("DAHelper executeBatch result: " + data) + } + ); + ``` + + + ```ts + // Promise mode (await needs to be used in the asynchronous method): + let dataexecuteBatch = await DAHelper.executeBatch( + urivar, + [ + { + uri: urivar, + type: featureAbility.DataAbilityOperationType.TYPE_INSERT, + valuesBucket: + { + "executeBatch" : "value1", + }, + predicates: da, + expectedCount:0, + predicatesBackReferences: null, + interrupted:true, + } + ] + ); + ``` + + +The APIs for operating a DataAbility are provided by **DataAbilityHelper**. For details about the APIs, see [DataAbilityHelper](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md). diff --git a/en/application-dev/application-models/access-datashareextensionability-from-fa.md b/en/application-dev/application-models/access-datashareextensionability-from-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..0abc7e3b8e948529b9916f936bf59b4a60a93637 --- /dev/null +++ b/en/application-dev/application-models/access-datashareextensionability-from-fa.md @@ -0,0 +1,52 @@ +# Accessing a DataShareExtensionAbility from the FA Model + + +## Overview + +Regardless of the FA model or stage model, the data read/write function consists of the client and server. + +- In the FA model, the client uses the **DataAbilityHelper** class to provide external APIs, and the server uses the **DataAbility** class to provide database read and write services. + +- In the stage model, the client uses the **DataShareHelper** class to provide external APIs, and the server uses the **DataShareExtensionAbility** class to provide database read and write services. + +If the client uses the FA model whereas the server is upgraded to the stage model, the client cannot access the server. + +To resolve this issue, OpenHarmony provides a solution on the framework side for smooth evolution. + + +## Basic Principles + +A compatible method is that **DataAbilityHelper** determines whether to call the **DataShareHelper** APIs based on the URI prefix (either **DataAbility** or **DataShare**). However, this method requires modification to the URI in the original client code. + +Instead of manual modification, OpenHarmony adopts the following processing: + +1. The system attempts to start the DataAbility based on the URI passed in. If the startup fails, the system converts the URI prefix to **DataShare** and attempts to start the DataShareExtensionAbility. + +2. If the URI does not map to any DataAbility or DataShareExtensionAbility, the startup fails. Otherwise, either the DataAbility or DataShareExtensionAbility is started. + + +## Constraints + +1. When you switch a DataAbility to a DataShareExtensionAbility, only the URI prefix can be modified.![FAvsStage-uri](figures/FAvsStage-uri.png) + +2. The **DataShareHelper** class implements only certain APIs of **DataAbilityHelper**. For details about the APIs, see the table below. + + **Table 1** APIs invoked when the FA model accesses a DataShareExtensionAbility of the stage model + + | API| Provided by DataAbilityHelper| Provided by DataShareHelper| Compatible| + | -------- | -------- | -------- | -------- | + | on | Yes| Yes| Yes| + | off | Yes| Yes| Yes| + | notifyChange | Yes| Yes| Yes| + | insert | Yes| Yes| Yes| + | delete | Yes| Yes| Yes| + | query | Yes| Yes| Yes| + | update | Yes| Yes| Yes| + | batchInsert | Yes| Yes| Yes| + | getType | Yes| No| No| + | getFileTypes | Yes| No| No| + | normalizeUri | Yes| Yes| Yes| + | denormalizeUri | Yes| Yes| Yes| + | openFile | Yes| No| No| + | call | Yes| No| No| + | executeBatch | Yes| No| No| diff --git a/en/application-dev/application-models/actions-entities.md b/en/application-dev/application-models/actions-entities.md new file mode 100644 index 0000000000000000000000000000000000000000..2479ab317cfdff8bc642f3f307fb4d8423efe112 --- /dev/null +++ b/en/application-dev/application-models/actions-entities.md @@ -0,0 +1,25 @@ +# Common action and entities Values + +The [action](../reference/apis/js-apis-ability-wantConstant.md#wantconstantaction) field specifies the common operation (such as viewing, sharing, and application details) to be performed by the caller. In implicit Want, you can define this field and use it together with **uri** or **parameters** to specify the operation to be performed on the data, for example, viewing URI data. For example, if the URI is a website and the action is **ohos.want.action.viewData**, the ability that supports website viewing is matched. Declaring the **action** field in Want indicates that the invoked application should support the declared operation. The **actions** field under **skills** in the configuration file indicates the operations supported by the application. + +**Common action Values** + + +- **ACTION_HOME**: action of starting the application entry component. It must be used together with **ENTITY_HOME**. The application icon on the home screen is an explicit entry component. Users can touch the icon to start the entry component. Multiple entry components can be configured for an application. + +- **ACTION_CHOOSE**: action of selecting local resource data, such as Contacts and Gallery. Generally, the system has corresponding Picker applications for different types of data. + +- **ACTION_VIEW_DATA**: action of viewing data. A website URI indicates the action for opening the website. + +- **ACTION_VIEW_MULTIPLE_DATA**: action of launching the UI for sending multiple data records. + +The [entities](../reference/apis/js-apis-ability-wantConstant.md#wantconstantentity) field specifies the additional category information (such as browser and video player) of the target ability. It is a supplement to **action** in implicit Want. You can define this field to filter application categories, for example, browser. Declaring the **entities** field in Want indicates that the invoked application should belong to the declared category. The **entities** field under **skills** in the configuration file indicates the categories supported by the application. + +**Common entities Values** + + +- **ENTITY_DEFAULT**: default category, which is meaningless. + +- **ENTITY_HOME**: abilities with an icon displayed on the home screen. + +- **ENTITY_BROWSABLE**: browser type. diff --git a/en/application-dev/application-models/api-switch-overview.md b/en/application-dev/application-models/api-switch-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..461e321d410a7f0036f5b4a1700c6176d7d451da --- /dev/null +++ b/en/application-dev/application-models/api-switch-overview.md @@ -0,0 +1,41 @@ +# API Switching Overview + + +Due to the differences in the thread model and process model, certain APIs (marked with **FAModelOnly** in the SDK) can be used only in the FA model. When switching an application from the FA model to the stage model, replace the APIs marked with **FAModelOnly** in the application with the APIs supported in the stage model. This topic uses the switching of **startAbility()** as an example. + +![api-switch-overview](figures/api-switch-overview.png) + + + +- Sample code of **startAbility()** in the FA model: + + ```ts + import fa from '@ohos.ability.featureAbility'; + let parameter = { + "want": { + bundleName: "ohos.samples.demo", + abilityName: "ohos.samples.demo.MainAbility" + } + } + fa.startAbility(parameter).then((data) => { + console.info('startAbility success'); + }).catch((error) => { + console.error('startAbility failed.'); + }) + ``` + +- Sample code of **startAbility()** in the stage model: + + ```ts + // context is a member of the ability object and is required for invoking inside a non-ability object. + // Pass in the Context object. + let wantInfo = { + bundleName: "ohos.samples.demo", + abilityName: "ohos.samples.demo.MainAbility" + }; + this.context.startAbility(wantInfo).then((data) => { + console.info('startAbility success.'); + }).catch((error) => { + console.error('startAbility failed.'); + }) + ``` diff --git a/en/application-dev/application-models/app-deviceconfig-switch.md b/en/application-dev/application-models/app-deviceconfig-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..8630746cb46979d1a7e37c2c6e30787ad5fe91ec --- /dev/null +++ b/en/application-dev/application-models/app-deviceconfig-switch.md @@ -0,0 +1,31 @@ +# Switching of app and deviceConfig + + +To help you better maintain the configuration of application-level attributes, OpenHarmony has extracted the **app** and **deviceConfig** tags from the **config.json** file to the **app.json5** file and changed certain tag names in the stage model. + +**Table 1** Comparison of the app tag in the configuration files + +| Configuration Item| app in config.json| app in app.json5| +| -------- | -------- | -------- | +| Internal version number of an application| "version": {
"code": 1,
} | "versionCode": 1 , | +| Text description of the version number, which is displayed to users| "version": {
"name": "1.0.0",
} | "versionName" : "1.0.0" , | +| Earliest compatible version of the application| "version": {
"minCompatibleVersionCode": 1,
} | "minCompatibleVersionCode" : 1 , | +| Minimum API version required for application running| "apiVersion": {
"compatible": 7,
} | "minAPIVersion" : 7 , | +| Target API version required for application running| "apiVersion": {
"target": 8,
} | "targetApiVersion" : 8 , | +| Type of the target API version required for application running| "apiVersion": {
"releaseType": Release,
} | "apiReleaseType": "Release" , | + + +OpenHarmony has reconstructed the [deviceConfig](../quick-start/deviceconfig-structure.md) tag of the **config.json** file in the **app.json5** file. It has integrated the fields related to device information under **deviceConfig** into the **app** tag of the [app.json5](../quick-start/app-configuration-file.md) file. + +**Table 2** Comparison of the deviceConfig tag in the configuration files + +| deviceConfig in the FA Model| Description| Stage Model| Difference| +| -------- | -------- | -------- | -------- | +| deviceConfig| Device information.| / | This tag is no longer available in the stage model. In the stage model, device information is configured under the **app** tag.| +| process | Name of the process running the application or ability. If the **process** attribute is configured in the **deviceConfig** tag, all abilities of the application run in this process. You can set the **process** attribute for a specific ability in the **abilities** attribute, so that the ability can run in the particular process.| / | The stage model does not support the configuration of process names.| +| keepAlive | Whether the application is always running. This attribute applies only to system applications and does not take effect for third-party applications.| / | The stage model does not support changing of the model control mode for system applications.| +| supportBackup | Whether the application supports data backup and restore.| / | This configuration is not supported in the stage model.| +| compressNativeLibs | Whether the **libs** libraries are packaged in the HAP file after being compressed.| / | This configuration is not supported in the stage model.| +| network | Network security configuration.| / | This configuration is not supported in the stage model.| + + \ No newline at end of file diff --git a/en/application-dev/application-models/application-component-configuration-fa.md b/en/application-dev/application-models/application-component-configuration-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..d460966545bc6e4901169779f0450308b44c8866 --- /dev/null +++ b/en/application-dev/application-models/application-component-configuration-fa.md @@ -0,0 +1,41 @@ +# Application- or Component-Level Configuration (FA Model) + + +When developing an application, you may need to configure certain tags to identify the application, such as the bundle name and application icon. This topic describes key tags that need to be configured during application development. + + +- **Configuring the bundle name** + + The bundle name is specified by the **bundleName** field under **app** in the **config.json** file. This field uniquely identifies an application. The bundle name can contain only letters, digits, underscores (_), and periods (.). It must start with a letter. The bundle name is a string with 7 to 127 bytes of a reverse domain name, for example, **com.example.myapplication**. It is recommended that the first part is the top-level domain **"com"**, and the second part is the vendor or individual name, which can be of multiple levels. For details about the configuration, see [app](../quick-start/app-structure.md). + +- **Configuring the application icon and label** + + The FA model does not support direct configuration of application icons and labels. Instead, the icon and label of a PageAbility component that meet the rules are used as the application icon and label. For details about the rules, see [PageAbility Component](pageability-configuration.md). The icon is specified by the **icon** field under **abilities** in the **config.json** file. The icon must be configured in the resource file on DevEco Studio, and the path of the icon must be **/resource/base/media**. An example value is **$media:ability_icon**. The label is the index of the resource file. It identifies the name of the ability presented to users. The label value can be an ability name or a resource index to the ability name in multiple languages. In the **skills** attribute of the ability, if the **actions** value contains **action.system.home** and the **entities** value contains **entity.system.home**, the icon and label of the ability is used as the application icon and label. If multiple abilities address this condition, the icon and label of the first candidate ability is used as the application icon and label. For details about the configuration, see [abilities](../quick-start/module-structure.md). + + ```json + "abilities": [ + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "skills": [ + { + "entities": ["entity.system.home"], + "actions": ["action.system.home"] + } + ] + // ... + } + ``` + +- **Configuring application version declaration** + + To declare the application version, set the **version** field under **app** in the **config.json** file to specify the version number, version name, and earliest compatible version number. For details about the configuration, see [version](../quick-start/module-structure.md). + +- **Configuring device types supported by the module** + + To configure the device types supported by the module, set the **deviceType** field in the **config.json** file. If a certain device type is added to **deviceTypes**, the module can run on that device. For details about the configuration, see [deviceType](../quick-start/module-structure.md). + +- **Configuring the component permission** + + To request component permissions, set the **reqPermission** field under **module** in the **config.json** file. This field declares the name of the permission to request, the reason for requesting the permission, and the scenario where the permission is used. For details about the configuration, see [reqPermission](../quick-start/module-structure.md). + + \ No newline at end of file diff --git a/en/application-dev/application-models/application-component-configuration-stage.md b/en/application-dev/application-models/application-component-configuration-stage.md new file mode 100644 index 0000000000000000000000000000000000000000..56a5ddac56d43e09609fa8e6e9669fab39681988 --- /dev/null +++ b/en/application-dev/application-models/application-component-configuration-stage.md @@ -0,0 +1,74 @@ +# Application- or Component-Level Configuration (Stage Model) + + +When developing an application, you may need to configure certain tags to identify the application, such as the bundle name and application icon. This topic describes key tags that need to be configured during application development. Icons and labels are usually configured together. There is the application icon, application label, entry icon, and entry label, which correspond to the **icon** and **label** fields in the [app.json5 file](../quick-start/app-configuration-file.md) and [module.json5 file](../quick-start/module-configuration-file.md). The application icon and label are used in **Settings**. For example, they are displayed in the application list in **Settings**. The entry icon is displayed on the device's home screen after the application is installed. The entry icon maps to a [UIAbility](uiability-overview.md) component. Therefore, an application can have multiple entry icons and labels. When you touch one of them, the corresponding UIAbility page is displayed. + + + **Figure 1** Icons and labels + +![application-component-configuration-stage](figures/application-component-configuration-stage.png) + + +- **Configuring the bundle name** + + The bundle name is specified by the **bundleName** field in the [app.json5 file](../quick-start/app-configuration-file.md) in the **AppScope** directory of the project. This field uniquely identifies an application. You are advised to use the reverse domain name notion, for example, *com.example.demo*, where the first part is the domain suffix **com**, the second part is the vendor/individual name, and the third part is the application name, which can be of multiple levels. + +- **Configuring the application icon and label** + + The application icon is specified by the **icon** field in the [app.json5 file](../quick-start/app-configuration-file.md) in the **AppScope** directory of the project. The **icon** field must be set to the index of an image so that the image is displayed as the application icon. The application icon is usually displayed in an application list, for example, the application list in **Settings**. + + The application label is specified by the **label** field in the [app.json5 file](../quick-start/app-configuration-file.md) in the **AppScope** module of the project. The **label** field specifies the application name displayed to users. It must be set to the index of a string resource. + + The **icon** and **label** fields in the **app.json5** file are under **app**, as follows: + + ```json + { + "app": { + "icon": "$media:app_icon", + "label": "$string:app_name" + // ... + } + } + ``` + +- **Configuring the entry icon and label** + + The entry icon and label are configured by specifying **icon** and **label** under **abilities** in the [module.json5 file](../quick-start/module-configuration-file.md). For example, if you want to display the icon and label of the UIAbility component on the home screen, add **entity.system.home** to **entities** and **action.system.home** to **actions** under **skills**. If the preceding fields are configured for multiple UIAbility components of an application, multiple icons and labels are displayed on the home screen, corresponding to their respective UIAbility component. + + ```json + { + "module": { + // ... + "abilities": [ + { + // The information starting with $ is the resource value. + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + } + ] + } + } + ``` +- **Configuring application version declaration** + + To declare the application version, configure the **versionCode** and **versionName** fields in the [app.json5 file](../quick-start/app-configuration-file.md) in the **AppScope** directory of the project. **versionCode** specifies the version number of the application. The value is a 32-bit non-negative integer. It is used only to determine whether a version is later than another version. A larger value indicates a later version. **versionName** provides the text description of the version number. + +- **Configuring device types supported by the module** + + To configure the device types supported by the module, set the **deviceTypes** field in the [module.json5 file](../quick-start/module-configuration-file.md). If a certain device type is added to **deviceTypes**, the module can run on that device. + +- **Configuring the module permission** + + The **requestPermission** field in the [module.json5 file](../quick-start/module-configuration-file.md) is used to configure the permission information required by the module to access the protected part of the system or other applications. This field declares the name of the permission to request, the reason for requesting the permission, and the scenario where the permission is used. + + \ No newline at end of file diff --git a/en/application-dev/application-models/application-context-fa.md b/en/application-dev/application-models/application-context-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..9f68b42a873782c9fd1693c73724354cbf347ced --- /dev/null +++ b/en/application-dev/application-models/application-context-fa.md @@ -0,0 +1,66 @@ +# Context (FA Model) + + +There is only one context in the FA model. All capabilities in the context are provided through methods. The context uses these methods to extend the capabilities of the **featureAbility** class. + + +## Available APIs + +To use the context in the FA model, first import the **featureAbility** module. + + +```ts +import featureAbility from "@ohos.ability.featureAbility"; +``` + +Then, call **getContext()** to obtain the **Context** object: + + +```ts +let context = featureAbility.getContext() +``` + +For details about the APIs, see [API Reference](../reference/apis/js-apis-inner-app-context.md). + + +## How to Develop + +1. Query bundle information. + + ```ts + import featureAbility from '@ohos.ability.featureAbility' + export default { + onCreate() { + // Obtain the context and call related APIs. + let context = featureAbility.getContext(); + context.getBundleName((data, bundleName)=>{ + console.info("ability bundleName:" + bundleName) + }); + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, + } + ``` + +2. Set the display orientation of the host featureAbility. + + ```ts + import featureAbility from '@ohos.ability.featureAbility' + import bundle from '@ohos.bundle'; + + export default { + onCreate() { + // Obtain the context and call related APIs. + let context = featureAbility.getContext(); + context.setDisplayOrientation(bundle.DisplayOrientation.LANDSCAPE).then(() => { + console.info("Set display orientation.") + }) + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, + } + ``` diff --git a/en/application-dev/application-models/application-context-stage.md b/en/application-dev/application-models/application-context-stage.md new file mode 100644 index 0000000000000000000000000000000000000000..af8f5d82a3f162381f4b970c82e0def06b91070b --- /dev/null +++ b/en/application-dev/application-models/application-context-stage.md @@ -0,0 +1,311 @@ +# Context (Stage Model) + + +## Overview + +[Context](../reference/apis/js-apis-inner-application-context.md) is the context of an object in an application. It provides basic information about the application, for example, **resourceManager**, **applicationInfo**, **dir** (application development path), and **area** (encrypted area). It also provides basic methods such as **createBundleContext()** and **getApplicationContext()**. The UIAbility component and ExtensionAbility derived class components have their own **Context** classes, for example, the base class **Context**, **ApplicationContext**, **AbilityStageContext**, **UIAbilityContext**, **ExtensionContext**, and **ServiceExtensionContext**. + +- The figure below illustrates the inheritance relationship of contexts. + context-inheritance + +- The figure below illustrates the holding relationship of contexts. + context-holding + +- The following describes the information provided by different contexts. + - [UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md): Each UIAbility has the **Context** attribute, which provides APIs to operate the ability, obtain the ability configuration, request permissions from users, and more. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility'; + export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + let uiAbilityContext = this.context; + // ... + } + } + ``` + - Scenario-specific [ExtensionContext](../reference/apis/js-apis-inner-application-extensionContext.md): For example, ServiceExtensionContext, inherited from ExtensionContext, provides APIs related to background services. + + ```ts + import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; + export default class MyService extends ServiceExtensionAbility { + onCreate(want) { + let serviceExtensionContext = this.context; + // ... + } + } + ``` + - [AbilityStageContext](../reference/apis/js-apis-inner-application-abilityStageContext.md): module-level context. It provides **HapModuleInfo** and **Configuration** in addition to those provided by the base class **Context**. + + ```ts + import AbilityStage from "@ohos.app.ability.AbilityStage"; + export default class MyAbilityStage extends AbilityStage { + onCreate() { + let abilityStageContext = this.context; + // ... + } + } + ``` + - [ApplicationContext](../reference/apis/js-apis-inner-application-applicationContext.md): application-level context. It provides APIs for subscribing to ability lifecycle changes, system memory changes, and system environment changes. The application-level context can be obtained from UIAbility, ExtensionAbility, and AbilityStage. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility'; + export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + let applicationContext = this.context.getApplicationContext(); + // ... + } + } + ``` + + +## Typical Usage Scenarios of Context + + +This topic describes how to use the context in the following scenarios: + + +- [Obtaining the Application Development Path](#obtaining-the-application-development-path) + +- [Obtaining and Modifying Encrypted Areas](#obtaining-and-modifying-encrypted-areas) + +- [Creating Context of Another Application or Module](#creating-context-of-another-application-or-module) + +- [Subscribing to Ability Lifecycle Changes in a Process](#subscribing-to-ability-lifecycle-changes-in-a-process) + +- [Requesting Permissions from Users Through AbilityContext](#requesting-permissions-from-users-through-uiabilitycontext) + + +### Obtaining the Application Development Path + +The following table describes the application development paths obtained from context. + +**Table 1** Application development paths + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| cacheDir | string | Yes| No| Cache directory of the application on the internal storage.
It is the content of **Storage** of an application under **Settings > Apps & services > Apps**.| +| tempDir | string | Yes| No| Temporary file directory of the application.
Files in this directory are deleted after the application is uninstalled.| +| filesDir | string | Yes| No| File directory of the application on the internal storage.
Files in this directory may be synchronized to other directories during application migration or backup.| +| databaseDir | string | Yes| No| Storage directory of the local database.| +| bundleCodeDir | string | Yes| No| Installation directory of the application on the internal storage.| +| distributedFilesDir | string | Yes| No| Storage directory of distributed application data files.| +| preferencesDir | string | Yes| Yes| Preferences directory of the application.| + +The capability of obtaining the application development path is provided by the base class **Context**. This capability is also provided by **ApplicationContext**, **AbilityStageContext**, **UIAbilityContext**, and **ExtensionContext**. However, the paths obtained from different contexts may differ, as shown below. + +**Figure 1** Application development paths obtained from context +context-dir + +- Obtain the application-level path through **ApplicationContext**. It is recommended that global application information be stored in this path. Files stored in this path will be deleted only when the application is uninstalled. + | Name| Path| + | -------- | -------- | + | bundleCodeDir | {Path prefix}/el1/bundle/| + | cacheDir | {Path prefix}/{Encryption level}/base/cache/| + | filesDir | {Path prefix}/{Encryption level}/base/files/| + | preferencesDir | {Path prefix}/{Encryption level}/base/preferences/| + | tempDir | {Path prefix}/{Encryption level}/base/temp/| + | databaseDir | {Path prefix}/{Encryption level}/database/| + | distributedFilesDir | {Path prefix}/el2/distributedFiles/| + +- Obtain the HAP level path through **AbilityStageContext**, **UIAbilityContext**, and **ExtensionContext**. It is recommended that the HAP information be stored in this path. The file content stored in this path will be deleted when the HAP is uninstalled. The file content in the application-level path will be deleted only after all the HAPs of the application are uninstalled. + | Name| Path| + | -------- | -------- | + | bundleCodeDir | {Path prefix}/el1/bundle/| + | cacheDir | {Path prefix}/{Encryption level}/base/**haps/{moduleName}**/cache/| + | filesDir | {Path prefix}/{Encryption level}/base/**haps/{moduleName}**/files/| + | preferencesDir | {path prefix}/{encryption level}/base/**haps/{moduleName}**/preferences/| + | tempDir | {Path prefix}/{Encryption level}/base/**haps/{moduleName}**/temp/| + | databaseDir | {Path prefix}/{Encryption level}/database/**{moduleName}**/| + | distributedFilesDir | {Path prefix}/el2/distributedFiles/**{moduleName}**/| + +The sample code for obtaining the application development paths is as follows: + + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + let cacheDir = this.context.cacheDir; + let tempDir = this.context.tempDir; + let filesDir = this.context.filesDir; + let databaseDir = this.context.databaseDir; + let bundleCodeDir = this.context.bundleCodeDir; + let distributedFilesDir = this.context.distributedFilesDir; + let preferencesDir = this.context.preferencesDir; + // ... + } +} +``` + + +### Obtaining and Modifying Encrypted Areas + +You can read and write [the area attribute in the context](../reference/apis/js-apis-inner-application-context.md) to obtain and set an encrypted area. Two encryption levels are supported: + +- AreaMode.EL1: device-level encryption area, which is accessible after the device is powered on. + +- AreaMode.EL2: user-level encryption area, which is accessible only after the device is powered on and the password is entered (for the first time). + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + // Before storing common information, switch the encryption level to EL1. + if (this.context.area === 1) {// Obtain the area. + this.context.area = 0; // Modify the area. + } + // Store common information. + + // Before storing sensitive information, switch the encryption level to EL2. + if (this.context.area === 0) { // Obtain the area. + this.context.area = 1; // Modify the area. + } + // Store sensitive information. + } +} +``` + + +### Creating Context of Another Application or Module + +The base class **Context** provides the [createBundleContext(bundleName:string)](../reference/apis/js-apis-inner-application-context.md#contextcreatebundlecontext), [createModuleContext(moduleName:string)](../reference/apis/js-apis-inner-application-context.md#contextcreatemodulecontext), and [createModuleContext(bundleName:string, moduleName:string)](../reference/apis/js-apis-inner-application-context.md#contextcreatemodulecontext-1) methods for creating the context of other applications or modules, so as to obtain the resource information, for example, [obtaining the application development paths](#obtaining-the-application-development-path) of other modules. + +- Call **createBundleContext(bundleName:string)** to create the context of another application. + > **NOTE** + > + > To obtain the context of another application: + > + > - Request the **ohos.permission.GET_BUNDLE_INFO_PRIVILEGED** permission. For details, see [Permission Application Guide](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file). + > +> - This is a system API and cannot be called by third-party applications. + + For example, application information displayed on the home screen includes the application name and icon. The home screen application calls the foregoing method to obtain the context information, so as to obtain the resource information including the application name and icon. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility'; + + export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + let bundleName2 = "com.example.application"; + let context2 = this.context.createBundleContext(bundleName2); + let label2 = context2.applicationInfo.label; + // ... + } + } + ``` + +- Call **createModuleContext(bundleName:string, moduleName:string)** to obtain the context of a specified module of another application. After obtaining the context, you can obtain the resource information of that module. + > **NOTE** + > + > To obtain the context of a specified module of another application: + > + > - Request the **ohos.permission.GET_BUNDLE_INFO_PRIVILEGED** permission. For details, see [Permission Application Guide](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file). + > +> - This is a system API and cannot be called by third-party applications. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility'; + + export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + let bundleName2 = "com.example.application"; + let moduleName2 = "module1"; + let context2 = this.context.createModuleContext(bundleName2, moduleName2); + // ... + } + } + ``` + +- Call **createModuleContext(moduleName:string)** to obtain the context of another module in the current application. After obtaining the context, you can obtain the resource information of that module. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility'; + + export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + let moduleName2 = "module1"; + let context2 = this.context.createModuleContext(moduleName2); + // ... + } + } + ``` + + +### Subscribing to Ability Lifecycle Changes in a Process + +In the DFX statistics scenario of an application, if you need to collect statistics on the stay duration and access frequency of a page, you can subscribe to ability lifecycle changes. + +When the ability lifecycle changes in a process, for example, being created or destroyed, becoming visible or invisible, or gaining or losing focus, the corresponding callback is triggered, and a listener ID is returned. The ID is incremented by 1 each time the listener is registered. When the number of listeners exceeds the upper limit (2^63-1), -1 is returned. The following uses [UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md) as an example. + + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; +import Window from '@ohos.window'; + +const TAG: string = "[Example].[Entry].[EntryAbility]"; + +export default class EntryAbility extends UIAbility { + lifecycleId: number; + + onCreate(want, launchParam) { + let abilityLifecycleCallback = { + onAbilityCreate(ability) { + console.info(TAG, "onAbilityCreate ability:" + JSON.stringify(ability)); + }, + onWindowStageCreate(ability, windowStage) { + console.info(TAG, "onWindowStageCreate ability:" + JSON.stringify(ability)); + console.info(TAG, "onWindowStageCreate windowStage:" + JSON.stringify(windowStage)); + }, + onWindowStageActive(ability, windowStage) { + console.info(TAG, "onWindowStageActive ability:" + JSON.stringify(ability)); + console.info(TAG, "onWindowStageActive windowStage:" + JSON.stringify(windowStage)); + }, + onWindowStageInactive(ability, windowStage) { + console.info(TAG, "onWindowStageInactive ability:" + JSON.stringify(ability)); + console.info(TAG, "onWindowStageInactive windowStage:" + JSON.stringify(windowStage)); + }, + onWindowStageDestroy(ability, windowStage) { + console.info(TAG, "onWindowStageDestroy ability:" + JSON.stringify(ability)); + console.info(TAG, "onWindowStageDestroy windowStage:" + JSON.stringify(windowStage)); + }, + onAbilityDestroy(ability) { + console.info(TAG, "onAbilityDestroy ability:" + JSON.stringify(ability)); + }, + onAbilityForeground(ability) { + console.info(TAG, "onAbilityForeground ability:" + JSON.stringify(ability)); + }, + onAbilityBackground(ability) { + console.info(TAG, "onAbilityBackground ability:" + JSON.stringify(ability)); + }, + onAbilityContinue(ability) { + console.info(TAG, "onAbilityContinue ability:" + JSON.stringify(ability)); + } + } + // 1. Obtain the application context through the context attribute. + let applicationContext = this.context.getApplicationContext(); + // 2. Register a listener for the lifecycle changes through the application context. + this.lifecycleId = applicationContext.on("abilityLifecycle", abilityLifecycleCallback); + console.info(TAG, "register callback number: " + JSON.stringify(this.lifecycleId)); + } + + onDestroy() { + let applicationContext = this.context.getApplicationContext(); + applicationContext.off("abilityLifecycle", this.lifecycleId, (error, data) => { + console.info(TAG, "unregister callback success, err: " + JSON.stringify(error)); + }); + } +} +``` + + +### Requesting Permissions from Users Through UIAbilityContext + +Each ability has the **Context** attribute. The ability is used to process the lifecycle. Methods use to operate the ability (such as **startAbility()**, **connectServiceExtensionAbility()**, and **terminateSelf()**) are implemented in the corresponding context. The context also provides methods for obtaining the ability configuration and requesting permissions from users. For details about how to obtain the context, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability). + + +When an application needs to obtain users' privacy information or use system capabilities, for example, to obtain location information, to access the calendar, or to use the camera to take photos or record videos, the application must request permissions from users, as shown below. For details, see [Permission Application Guide](../security/accesstoken-guidelines.md). + +**Figure 2** Requesting the permission to access the calendar from users +application-context-stage \ No newline at end of file diff --git a/en/application-dev/application-models/application-model-composition.md b/en/application-dev/application-models/application-model-composition.md new file mode 100644 index 0000000000000000000000000000000000000000..2d7ed88490136c6e94277e94da375278fcab0adf --- /dev/null +++ b/en/application-dev/application-models/application-model-composition.md @@ -0,0 +1,27 @@ +# Elements of the Application Model + + +The application model is the abstraction of capabilities required by OpenHarmony applications. It provides necessary components and running mechanisms for applications. With application models, you can develop applications based on a unified set of models, making application development simpler and more efficient. + + +The OpenHarmony application model consists of the following elements: + + +- Application component + + An application component is the basic unit and running entry of an application. When a user starts, uses, or exits an application, the application component transits in different states. This is called the application component lifecycle. The application component provides lifecycle callback functions, through which you can detect application [status changes](uiability-lifecycle.md). When compiling an application, you needs to compile application components and their lifecycle callback functions, and configure related information in the application configuration file. In this way, the operating system creates an application component instance based on the configuration file during running, and schedules the lifecycle callback functions, so as to execute your code. +- Application process model + + The application process model defines how application processes are created, destroyed, and communicate with each other. + +- Application thread model + + The application thread model defines how a thread in an application process is created and destroyed, how the main thread and UI thread are created, and how the threads communicate with each other. + +- Application mission management model + + The application mission management model defines how a mission is created and destroyed, and the relationship between missions and components. A mission is a record about the use of an application component instance. Each time a user starts an application component instance, a mission is generated. For example, when a user starts a video application, the video application mission is displayed on the **Recents** page. When the user clicks the mission, the system switches the mission to the foreground. If the video editing functionality in the video application is compiled by using an application component, an application component instance for video editing is created when the user starts video editing. In this case, both the video application mission and video editing mission are displayed on the **Recents** page. + +- Application configuration file + + The application configuration file contains information about the application configuration, application components, and permissions, as well as custom information. The information will be provided for the compiler, application market, and operating system in the build, distribution, and running phases. diff --git a/en/application-dev/application-models/application-model-description.md b/en/application-dev/application-models/application-model-description.md new file mode 100644 index 0000000000000000000000000000000000000000..2c15a15ee2aa30c9e56a04fb21497af01969cd07 --- /dev/null +++ b/en/application-dev/application-models/application-model-description.md @@ -0,0 +1,61 @@ +# Interpretation of the Application Model + + +## Application Model Overview + +Along its evolution, OpenHarmony has provided two application models: + +- Feature Ability (FA) model. This model is supported by OpenHarmony API version 7 and 8. It is no longer recommended. + +- Stage model. This model is supported since OpenHarmony API version 9. It is recommended and will evolve for a long time. In this model, classes such as **AbilityStage** and **WindowStage** are provided as the stage of application components and windows. That's why it is named stage model. + +The stage model is designed based on the following considerations, which make it become the recommended model: + +1. **Designed for complex applications** + + - In the stage model, multiple application components share an ArkTS engine (VM running the programming language ArkTS) instance, making it easy for application components to share objects and status while requiring less memory. +- The object-oriented development mode makes the code of complex applications easy to read, maintain, and scale. + +2. **Native support for [cross-device migration](hop-cross-device-migration.md) and [multi-device collaboration](hop-multi-device-collaboration.md) at the application component level** + + The stage model decouples application components from User Interfaces (UIs). + + - In cross-device migration scenarios, after the system migrates application component data or status between devices, it can use the declarative feature of ArkUI to restore the UI based on the data or status saved in the application components. + + - In multi-device collaboration scenarios, application components can initiate Remote Procedure Calls (RPCs) and support interaction with cross-device application components. + +3. **Support for multiple device types and window forms** + + Application component management and window management are decoupled at the architecture level. This decoupling makes it: + + - Easy to tailor application components. For example, windows can be tailored for devices without screens. + + - Easy to extend the window forms. + + - Possible for application components to use the same lifecycle on multiple devices (such as desktop devices and mobile devices). + +4. **Well balanced application capabilities and system management costs** + + The stage model redefines the boundary of application capabilities to well balance application capabilities and system management costs. + + - Diverse application components (such as widgets and input methods) for specific scenarios. + - Standardized background process management. To deliver a better user experience, the stage model manages background application processes in a more orderly manner. Applications cannot reside in the background randomly, and their background behavior is strictly managed to minimize malicious behavior. + + +## Differences Between the FA Model and Stage Model + +In the stage model, multiple application components share the same ArkTS engine instance. In the FA model, each application component exclusively uses an ArkTS engine instance. This is their biggest difference. In the stage model, application components can easily share objects and status while requiring less memory. Therefore, you are advised to use the stage model when developing complex applications in distributed scenarios. + +The table below describes their differences in detail. + + **Table 1** Differences between the FA model and stage model + +| Item| FA model| Stage model| +| -------- | -------- | -------- | +| **Application component**| 1. Component classification
- PageAbility: has the UI and supports user interaction. For details, see [PageAbility Component Overview](pageability-overview.md).
- ServiceAbility: provides background services and has no UI. For details, see [ServiceAbility Component Overview](serviceability-overview.md).
- DataAbility: provides the data sharing capability and has no UI. For details, see [DataAbility Component Overview](dataability-overview.md).
2. Development mode
Application components are specified by exporting anonymous objects and fixed entry files. You cannot perform derivation. It is inconvenient for capability expansion.| 1. Component classification
- UIAbility: has the UI and supports user interaction. For details, see [UIAbility Component Overview](uiability-overview.md).
- ExtensionAbility: provides extension capabilities (such as widget and input methods) for specific scenarios. For details, see [ExtensionAbility Component Overview](extensionability-overview.md).
2. Development mode
The object-oriented mode is used to provide open application components as classes. You can derive application components for capability expansion.| +| **Process model**| There are two types of processes:
1. Main process
2. Rendering process
For details, see [Process Model (FA Model)](process-model-fa.md). | There are three types of processes:
1. Main process
2. ExtensionAbility process
3. Rendering process
For details, see [Process Model (Stage Model)](process-model-stage.md). | +| **Thread model**| 1. ArkTS engine instance creation
A process can run multiple application component instances, and each application component instance runs in an independent ArkTS engine instance.
2. Thread model
Each ArkTS engine instance is created on an independent thread (non-main thread). The main thread does not have an ArkTS engine instance.
3. Intra-process object sharing: not supported.
For details, see [Thread Model (FA Model)](thread-model-fa.md). | 1. ArkTS engine instance creation
A process can run multiple application component instances, and all application component instances share one ArkTS engine instance.
2. Thread model
The ArkTS engine instance is created on the main thread.
3. Intra-process object sharing: supported.
For details, see [Thread Model (Stage Model)](thread-model-stage.md). | +| **Mission management model**| - A mission is created for each PageAbility component instance.
- Missions are stored persistently until the number of missions exceeds the maximum (customized based on the product configuration) or users delete missions.
- PageAbility components do not form a stack structure.
For details, see [Mission Management Scenarios](mission-management-overview.md).| - A mission is created for each UIAbility component instance.
- Missions are stored persistently until the number of missions exceeds the maximum (customized based on the product configuration) or users delete missions.
- UIAbility components do not form a stack structure.
For details, see [Mission Management Scenarios](mission-management-overview.md).| +| **Application configuration file**| The **config.json** file is used to describe the application, HAP, and application component information.
For details, see [Application Configuration File Overview (FA Model)](../quick-start/application-configuration-file-overview-fa.md).| The **app.json5** file is used to describe the application information, and the **module.json5** file is used to describe the HAP and application component information.
For details, see [Application Configuration File Overview (Stage Model)](../quick-start/application-configuration-file-overview-stage.md).| + + \ No newline at end of file diff --git a/en/application-dev/application-models/background-services.md b/en/application-dev/application-models/background-services.md new file mode 100644 index 0000000000000000000000000000000000000000..77ed5d98c0798037e57f2867b8e216928bfc2240 --- /dev/null +++ b/en/application-dev/application-models/background-services.md @@ -0,0 +1,7 @@ +# Background Services (Stage Model) + + +The stage model uses ServiceExtensionAbility to provide background services. A system application can implement a background service and provide external capabilities. For example, if system application A implements a background service, third-party application B can communicate with A by connecting to A's background service. + + +For details about ServiceExtensionAbility, see [Background Service Development](serviceextensionability.md). diff --git a/en/application-dev/application-models/bind-serviceability-from-stage.md b/en/application-dev/application-models/bind-serviceability-from-stage.md new file mode 100644 index 0000000000000000000000000000000000000000..0ee35195b8810efea9af4382c80d0c8e37e0fd70 --- /dev/null +++ b/en/application-dev/application-models/bind-serviceability-from-stage.md @@ -0,0 +1,90 @@ +# Connecting to a ServiceAbility from the Stage Model + + +This topic describes how the two application components of the stage model connect to the ServiceAbility component of the FA model. + + +## UIAbility Accessing a ServiceAbility + +A UIAbility accesses a ServiceAbility in the same way as it accesses a ServiceExtensionAbility. + + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; + +export default class MainAbility extends UIAbility { + onCreate(want, launchParam) { + console.info("MainAbility onCreate"); + } + onDestroy() { + console.info("MainAbility onDestroy") + } + onWindowStageCreate(windowStage) { + console.info("MainAbility onWindowStageCreate") + let want = { + bundleName: "com.ohos.fa", + abilityName: "ServiceAbility", + }; + + let options = { + onConnect:function (elementName, proxy) { + console.info("onConnect called."); + }, + onDisconnect:function (elementName) { + console.info("onDisconnect called."); + }, + onFailed:function (code) { + console.info("onFailed code is: " + code); + } + }; + let connectionId = this.context.connectServiceExtensionAbility(want, options); + } + onWindowStageDestroy() { + console.info("MainAbility onWindowStageDestroy") + } + onForeground() { + console.info("MainAbility onForeground") + } + onBackground() { + console.info("MainAbility onBackground") + } +} +``` + + +## ExtensionAbility Accessing a ServiceAbility + +The following uses the ServiceExtensionAbility component as an example to describe how an ExtensionAbility accesses a ServiceAbility. A ServiceExtensionAbility accesses a ServiceAbility in the same way as it accesses another ServiceExtensionAbility. + + +```ts +import Extension from '@ohos.app.ability.ServiceExtensionAbility' + +export default class ServiceExtension extends Extension { + onCreate(want) { + console.info("ServiceExtension onCreate") + } + onDestroy() { + console.info("ServiceExtension onDestroy") + } + onRequest(want, startId) { + console.info("ServiceExtension onRequest") + let wantFA = { + bundleName: "com.ohos.fa", + abilityName: "ServiceAbility", + }; + let options = { + onConnect:function (elementName, proxy) { + console.info("onConnect called."); + }, + onDisconnect:function (elementName) { + console.info("onDisconnect called."); + }, + onFailed:function (code) { + console.info("onFailed code is: " + code); + } + }; + let connectionId = this.context.connectServiceExtensionAbility(wantFA, options); + } +} +``` diff --git a/en/application-dev/application-models/bind-serviceextensionability-from-fa.md b/en/application-dev/application-models/bind-serviceextensionability-from-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..e5f90bf9d6b7616261d2ae1eb1e62438fe2e71e3 --- /dev/null +++ b/en/application-dev/application-models/bind-serviceextensionability-from-fa.md @@ -0,0 +1,60 @@ +# Connecting to a ServiceExtensionAbility from the FA Model + + +This topic describes how the three application components of the FA model connect to the ServiceExtensionAbility component of the stage model. + + +## PageAbility Accessing a ServiceExtensionAbility + +A PageAbility accesses a ServiceExtensionAbility in the same way as it accesses a ServiceAbility. + + +```ts +import featureAbility from '@ohos.ability.featureAbility'; + +let want = { + bundleName: "com.ohos.stage", + abilityName: "com.ohos.stage.ServiceExtensionAbility" +}; + +let faConnect = { + onConnect:function (elementName, proxy) { + console.info("Faconnection onConnect called."); + }, + onDisconnect:function (elementName) { + console.info("Faconnection onDisconnect called."); + }, + onFailed:function (code) { + console.info("Faconnection onFailed code is: " + code); + } +}; +let connectionId = featureAbility.connectAbility(want, faConnect); +``` + + +## ServiceAbility or DataAbility Accessing a ServiceExtensionAbility + +A ServiceAbility or DataAbility accesses a ServiceExtensionAbility in the same way as it accesses a ServiceAbility. + + +```ts +import particleAbility from '@ohos.ability.particleAbility'; + +let want = { + bundleName: "com.ohos.stage", + abilityName: "com.ohos.stage.ServiceExtensionAbility" +}; + +let faConnect = { + onConnect:function (elementName, proxy) { + console.info("Faconnection onConnect called."); + }, + onDisconnect:function (elementName) { + console.info("Faconnection onDisconnect called."); + }, + onFailed:function (code) { + console.info("Faconnection onFailed code is: " + code); + } +}; +let connectionId = particleAbility.connectAbility(want, faConnect); +``` diff --git a/en/application-dev/application-models/common-event-fa.md b/en/application-dev/application-models/common-event-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..9e2f44144d8f028c61c538b48797f5842a48d2a7 --- /dev/null +++ b/en/application-dev/application-models/common-event-fa.md @@ -0,0 +1,4 @@ +# Common Events (FA Model) + + +For details, see [Common Events](common-event-overview.md) in the stage model. diff --git a/en/application-dev/application-models/common-event-overview.md b/en/application-dev/application-models/common-event-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..0d3788b41b516d0af9619d320ceeefc3f52c74c5 --- /dev/null +++ b/en/application-dev/application-models/common-event-overview.md @@ -0,0 +1,28 @@ +# Introduction to Common Events + + +OpenHarmony provides Common Event Service (CES) for applications to subscribe to, publish, and unsubscribe from common events. + + +Common events are classified into system common events and custom common events. + + +- System common events: defined in CES. Only system applications and system services can publish system common events, such as HAP installation, update, and uninstall. For details about the supported system common events, see [Support](../reference/apis/js-apis-commonEventManager.md#support). + +- Custom common events: customized by applications to implement cross-process event communication. + + +Common events are also classified into unordered, ordered, and sticky common events. + + +- Unordered common events: CES forwards common events based on the subscription sequence, regardless of whether subscribers receive the events. + +- Ordered common event: CES forwards common events to the next subscriber only after receiving a reply from the previous subscriber. + +- Sticky common event: a public event that can be sent to a subscriber before they initiate a subscription. Only system applications or system services can send sticky common event, and they must request the **ohos.permission.COMMONEVENT_STICKY** permission. For details about the configuration, see [Permission Application Guide](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file). + + +Each application can subscribe to common events as required. After your application subscribes to a common event, the system sends it to your application every time the event is published. Such an event may be published by the system, other applications, or your own application. + +**Figure 1** Common events +![common-event](figures/common-event.png) \ No newline at end of file diff --git a/en/application-dev/application-models/common-event-publish.md b/en/application-dev/application-models/common-event-publish.md new file mode 100644 index 0000000000000000000000000000000000000000..b29c137319fcbb1fe4eaff8e262dca1a403c87e4 --- /dev/null +++ b/en/application-dev/application-models/common-event-publish.md @@ -0,0 +1,78 @@ +# Publishing Common Events + + +## When to Use + +You can use [publish()](../reference/apis/js-apis-commonEventManager.md#commoneventmanagerpublish) to publish a custom common event, which can carry data for subscribers to parse and process. + +> **NOTE** +> +> Subscribers can receive sticky common events that have been sent. However, they must subscribe to common events of other types before receiving them. For details about subscription, see [Subscribing to Common Events](common-event-subscription.md). + + +## Available APIs + +For details about the APIs, see [API Reference](../reference/apis/js-apis-commonEventManager.md#commoneventmanagerpublish). + +| API| Description| +| -------- | -------- | +| publish(event: string, callback: AsyncCallback) | Publishes a common event.| +| publish(event: string, options: [CommonEventPublishData](../reference/apis/js-apis-commonEventManager.md#commoneventpublishdata), callback: AsyncCallback) | Publishes a common event with given attributes.| + + +## Publishing a Common Event That Does Not Carry Information + +Common events that do not carry information can be published only as unordered common events. + +1. Import the **commonEventManager** module. + + ```ts + import commonEventManager from '@ohos.commonEventManager'; + ``` + +2. Pass in the common event name and callback, and publish the event. + + ```ts + // Publish a common event. + commonEventManager.publish("usual.event.SCREEN_OFF", (err) => { + if (err) { + console.error(`[CommonEvent] PublishCallBack err=${JSON.stringify(err)}`); + } else { + console.info(`[CommonEvent] Publish success`); + } + }) + ``` + + +## Publishing a Common Event That Carries Information + +Common events that carry information can be published as unordered, ordered, and sticky common events, which are specified by the **isOrdered** and **isSticky** fields of [CommonEventPublishData](../reference/apis/js-apis-commonEventManager.md#commoneventpublishdata). + +1. Import the **commonEventManager** module. + + ```ts + import commonEventManager from '@ohos.commonEventManager'; + ``` + +2. Pass in the common event name and callback, and publish the event. + + ```ts + // Attributes of a common event. + let options = { + code: 1, // Result code of the common event. + data: "initial data", // Result data of the common event. + } + ``` + +3. Pass in the common event name, attributes of the common event, and callback, and publish the event. + + ```ts + // Publish a common event. + commonEventManager.publish("usual.event.SCREEN_OFF", options, (err) => { + if (err) { + console.error('[CommonEvent] PublishCallBack err=' + JSON.stringify(err)); + } else { + console.info('[CommonEvent] Publish success') + } + }) + ``` diff --git a/en/application-dev/application-models/common-event-subscription.md b/en/application-dev/application-models/common-event-subscription.md new file mode 100644 index 0000000000000000000000000000000000000000..ce61e40458a7cbd5c9ec226138535da93d3766b1 --- /dev/null +++ b/en/application-dev/application-models/common-event-subscription.md @@ -0,0 +1,69 @@ +# Subscribing to Common Events + + +## When to Use + +You can create a subscriber object to subscribe to a common event so as to obtain the parameters passed in the event. Certain system common events [require specific permissions](../security/accesstoken-guidelines.md) to subscribe to. For details, see [Required Permissions](../reference/apis/js-apis-commonEventManager.md#support). + + +## Available APIs + +For details about the APIs, see [API Reference](../reference/apis/js-apis-commonEventManager.md#commoneventmanagersubscribe). + +| API| Description| +| -------- | -------- | +| createSubscriber(subscribeInfo: [CommonEventSubscribeInfo](../reference/apis/js-apis-commonEventManager.md#commoneventsubscribeinfo), callback: AsyncCallback<[CommonEventData](../reference/apis/js-apis-commonEventManager.md#commoneventdata)>): void | Creates a subscriber. This API uses an asynchronous callback to return the result.| +| createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise<CommonEventSubscriber> | Creates a subscriber. This API uses a promise to return the result.| +| subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback): void | Subscribes to common events.| + + +## How to Develop + +1. Import the **commonEventManager** module. + + ```ts + import commonEventManager from '@ohos.commonEventManager'; + ``` + +2. Create a **subscribeInfo** object. For details about the data types and parameters of the object, see [CommonEventSubscribeInfo](../reference/apis/js-apis-commonEventManager.md#commoneventsubscribeinfo). + + ```ts + // Used to save the created subscriber object for subsequent subscription and unsubscription. + let subscriber = null; + // Subscriber information. + let subscribeInfo = { + events: ["usual.event.SCREEN_OFF"], // Subscribe to the common event screen-off. + } + ``` + +3. Create a subscriber object and save the returned object for subsequent operations such as subscription and unsubscription. + + ```ts + // Callback for subscriber creation. + commonEventManager.createSubscriber(subscribeInfo, (err, data) => { + if (err) { + console.error(`[CommonEvent] CreateSubscriberCallBack err=${JSON.stringify(err)}`); + } else { + console.info(`[CommonEvent] CreateSubscriber success`); + subscriber = data; + // Callback for common event subscription. + } + }) + ``` + +4. Create a subscription callback, which is triggered when an event is received. The data returned in the subscription callback contains information such as the common event name and data carried by the publisher. For details about the data types and parameters of the common event data, see [CommonEventData](../reference/apis/js-apis-commonEventManager.md#commoneventdata). + + ```ts + // Callback for common event subscription. + if (subscriber !== null) { + commonEventManager.subscribe(subscriber, (err, data) => { + if (err) { + console.error(`[CommonEvent] SubscribeCallBack err=${JSON.stringify(err)}`); + } else { + console.info(`[CommonEvent] SubscribeCallBack data=${JSON.stringify(data)}`); + } + }) + } else { + console.error(`[CommonEvent] Need create subscriber`); + } + ``` diff --git a/en/application-dev/application-models/common-event-unsubscription.md b/en/application-dev/application-models/common-event-unsubscription.md new file mode 100644 index 0000000000000000000000000000000000000000..c87017ef08c05e8a22097c4bd2a05f52fc758134 --- /dev/null +++ b/en/application-dev/application-models/common-event-unsubscription.md @@ -0,0 +1,40 @@ +# Unsubscribing from Common Events + + +## When to Use + +You can call [unsubscribe()](../reference/apis/js-apis-commonEventManager.md#commoneventmanagerunsubscribe) to unsubscribe from a common event that is no longer required. + + +## Available APIs + +| API| Description| +| -------- | -------- | +| unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback) | Unsubscribes from a common event.| + + +## How to Develop + +1. Import the **commonEventManager** module. + + ```ts + import commonEventManager from '@ohos.commonEventManager'; + ``` + +2. Subscribe to an event by following the procedure described in [Subscribing to Common Events](common-event-subscription.md). + +3. Call **unsubscribe** in **CommonEvent** to unsubscribe from the common event. + + ```ts + // The subscriber object iscreated during event subscription. + if (subscriber !== null) { + commonEventManager.unsubscribe(subscriber, (err) => { + if (err) { + console.error(`[CommonEvent] UnsubscribeCallBack err=${JSON.stringify(err)}`); + } else { + console.info(`[CommonEvent] Unsubscribe`); + subscriber = null; + } + }) + } + ``` diff --git a/en/application-dev/application-models/component-startup-rules-fa.md b/en/application-dev/application-models/component-startup-rules-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..15788e109c4406d740f403d3e21a27d7d0a451c6 --- /dev/null +++ b/en/application-dev/application-models/component-startup-rules-fa.md @@ -0,0 +1,70 @@ +# Component Startup Rules (FA Model) + + +Component startup refers to the behavior of starting or connecting to an application component. + + +- Start the PageAbility and ServiceAbility. For example, you can use **startAbility()**. + +- Connect to the ServiceAbility and DataAbility. For example, you can use **connectAbility()** and **acquireDataAbilityHelper()**. + + +To deliver a better user experience, OpenHarmony restricts the following behavior: + + +- A background application randomly displays a dialog box, such as an ads pop-up. + +- Background applications wake up each other. This type of behavior occupies system resources and increases power consumption, or even causes system frozen. + +- A foreground application randomly redirects to another application, for example, redirecting to the payment page of another application. This type of behavior poses security risks. + + +In view of this, OpenHarmony formulates a set of component startup rules, as follows: + + +- **Before starting a component of another application, verify the visible field of the target component.** + - This rule applies only to cross-application scenarios. + - If the **visible** field of the target component is **false**, verify the **ohos.permission.START_INVISIBLE_ABILITY** permission. + - For details, see [Component Visible Configuration](../quick-start/module-configuration-file.md#abilities-tag) + +- **Before starting a component of a background application, verify the BACKGROUND permission.** + - An application is considered as a foreground application only when the application process gains focus or its UIAbility component is running in the foreground. + - Verify the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. + +- **Before starting the ServiceAbility or DataAbility component of an application, verify the AssociateWakeUp field of the target application.** + - This rule applies only to cross-application scenarios. + - This rule is valid only when the target component is ServiceAbility or DataAbility. + - The ServiceAbility and DataAbility of an application can be accessed by others only when **AssociateWakeUp** of the target application is set to **true**. + - The **AssociateWakeUp** field can be configured only for preset applications. For other applications, this field is set to **false** by default. + + +> **NOTE** +> 1. Component startup control has been implemented since OpenHarmony v3.2 Release. +> +> 2. The new component startup rules are more strict than the original ones. You must be familiar with the new startup rules to prevent service exceptions. + + + + +## Intra-Device Component Startup Rules + + The rules for starting components on the same device vary in the following scenarios: + +- Starting a PageAbility + +- Starting a ServiceAbility or DataAbility + +![startup-rule](figures/component-startup-inner-fa.png) + + +## Inter-Device Component Startup Rules + + The rules for starting components on a different device vary in the following scenarios: + +- Starting a PageAbility + +- Starting a ServiceAbility + +![component-startup-rules](figures/component-startup-inter-fa.png) + + \ No newline at end of file diff --git a/en/application-dev/application-models/component-startup-rules.md b/en/application-dev/application-models/component-startup-rules.md new file mode 100644 index 0000000000000000000000000000000000000000..a00d01780d9bf67b6b64ec90b4c3bd0635865c74 --- /dev/null +++ b/en/application-dev/application-models/component-startup-rules.md @@ -0,0 +1,65 @@ +# Component Startup Rules (Stage Model) + + +Component startup refers to the behavior of starting or connecting to an application component. + + +- Start the UIAbility, ServiceExtensionAbility, and DataShareExtensionAbility components. For example, you can use **startAbility()**, **startServiceExtensionAbility()**, and **startAbilityByCall()**. + +- Connect to the ServiceExtensionAbility and DataShareExtensionAbility components. For example, you can use **connectServiceExtensionAbility()** and **createDataShareHelper()**. + + +To deliver a better user experience, OpenHarmony restricts the following behavior: + + +- A background application randomly displays a dialog box, such as an ads pop-up. + +- Background applications wake up each other. This type of behavior occupies system resources and increases power consumption, or even causes system frozen. + +- A foreground application randomly redirects to another application, for example, redirecting to the payment page of another application. This type of behavior poses security risks. + + +In view of this, OpenHarmony formulates a set of component startup rules, as follows: + + +- **Before starting a component of another application, verify the visible field of the target component.** + - If the **visible** field of the target component is **false**, verify the **ohos.permission.START_INVISIBLE_ABILITY** permission. + - For details, see [Component Visible Configuration](../quick-start/module-configuration-file.md#abilities-tag) + +- **Before starting a component of a background application, verify the BACKGROUND permission.** + - An application is considered as a foreground application only when the application process gains focus or its UIAbility component is running in the foreground. + - Verify the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. + +- **When the startAbilityByCall() method is used, verify the call permission.** For details, see [Using Ability Call to Implement UIAbility Interaction](uiability-intra-device-interaction.md#using-ability-call-to-implement-uiability-interaction) and [Using Cross-Device Ability Call](hop-multi-device-collaboration.md#using-cross-device-ability-call). + - Verify the **ohos.permission.ABILITY_BACKGROUND_COMMUNICATION** permission. + + +> **NOTE** +> +> - Component startup control has been implemented since OpenHarmony v3.2 Release. +> +> - The new component startup rules are more strict than the original ones. You must be familiar with the new startup rules to prevent service exceptions. + + +## Intra-Device Component Startup Rules + + The rules for starting components on the same device vary in the following scenarios: + +- Starting or connecting to the UIAbility, ServiceExtensionAbility, and DataShareExtensionAbility components + +- Using **startAbilityByCall()** to start the UIAbility component + +![startup-rule](figures/component-startup-inner-stage.png) + + +## Inter-Device Component Startup Rules + + The rules for starting components on a different device vary in the following scenarios: + +- Starting or connecting to the UIAbility, ServiceExtensionAbility, and DataShareExtensionAbility components + +- Using **startAbilityByCall()** to start the UIAbility component + +![component-startup-rules](figures/component-startup-inter-stage.png) + + \ No newline at end of file diff --git a/en/application-dev/application-models/config-file-fa.md b/en/application-dev/application-models/config-file-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..f19104d0db5b36346ff3f868d0fb9e5773460ac1 --- /dev/null +++ b/en/application-dev/application-models/config-file-fa.md @@ -0,0 +1,7 @@ +# Application Configuration File (FA Model) + +The application configuration file contains information about the application configuration, application components, and permissions, as well as custom information. The information will be provided for the compiler, application market, and operating system in the build, distribution, and running phases. + +The application project code developed based on the FA model contains a **config.json** file. For details about common configuration items, see [Application- or Component-Level Configuration](application-component-configuration-fa.md). For details about the file, see [Application Configuration File Overview (FA Model)](../quick-start/application-configuration-file-overview-fa.md). + + \ No newline at end of file diff --git a/en/application-dev/application-models/config-file-stage.md b/en/application-dev/application-models/config-file-stage.md new file mode 100644 index 0000000000000000000000000000000000000000..bf667dcb0d33228581cfbec3a7ab4750a3cb4b94 --- /dev/null +++ b/en/application-dev/application-models/config-file-stage.md @@ -0,0 +1,7 @@ +# Application Configuration File (Stage Model) + +The application configuration file contains information about the application configuration, application components, and permissions, as well as custom information. The information will be provided for the compiler, application market, and operating system in the build, distribution, and running phases. + +The application project code developed based on the stage model contains one **app.json5** file and one or more **module.json5** files. For details about common configuration items, see [Application- or Component-Level Configuration (Stage Model)](application-component-configuration-stage.md). For details about the two files, see [Application Configuration File Overview (Stage Model)](../quick-start/application-configuration-file-overview-stage.md). + + \ No newline at end of file diff --git a/en/application-dev/application-models/configuration-file-diff.md b/en/application-dev/application-models/configuration-file-diff.md new file mode 100644 index 0000000000000000000000000000000000000000..141eeab16f692b144c57488918e978217e61d08f --- /dev/null +++ b/en/application-dev/application-models/configuration-file-diff.md @@ -0,0 +1,12 @@ +# Differences in Configuration Files + + +The FA model uses the [config.json file](../quick-start/application-configuration-file-overview-fa.md) to describe the basic information about an application. An application can have multiple modules, and each module has a **config.json** file. The **config.json** file consists of three parts: **app**, **deviceConfig**, and **module**. The **app** tag is used to configure application-level attributes. If an application has multiple modules, the **app** configuration in each **config.json** file must be consistent. + + +The stage model uses the [app.json5](../quick-start/app-configuration-file.md) and [module.json](../quick-start/module-configuration-file.md) files to describe the basic information about an application. An application can have multiple modules but only one **app.json5** file. This file is used to configure application-level attributes and takes effect for all the modules. Each module has a **module.json5** file, which is used to configure module-level attributes and takes effect only for the current module. + +**Figure 1** Configuration file differences +![comparison-of-configuration-file](figures/comparison-of-configuration-file.png) + + \ No newline at end of file diff --git a/en/application-dev/application-models/connect-serviceability.md b/en/application-dev/application-models/connect-serviceability.md new file mode 100644 index 0000000000000000000000000000000000000000..ac2acb898a3bd7ef905b8a33dc10f7980ce74548 --- /dev/null +++ b/en/application-dev/application-models/connect-serviceability.md @@ -0,0 +1,93 @@ +# Connecting to a ServiceAbility + + +If a ServiceAbility wants to interact with a PageAbility or a ServiceAbility in another application, you must first create a connection by calling **connectAbility()**. This method is defined in the **featureAbility** class for the PageAbility and in the **particleAbility** class for the ServiceAbility. For details about the connection rules, see [Component Startup Rules](component-startup-rules.md). When calling **connectAbility()**, you should pass in a **Want** object containing information about the target ServiceAbility and an **IAbilityConnection** object. **IAbilityConnection** provides the following APIs that you need to implement. + +**Table 1** IAbilityConnection APIs + +| API| Description| +| -------- | -------- | +| onConnect() | Callback invoked when the ServiceAbility is connected.| +| onDisconnect() | Callback invoked when the ServiceAbility is disconnected.| +| onFailed() | Callback invoked when the connection to the ServiceAbility fails.| + + +The following sample code enables the PageAbility to create connection callback instances and connect to the local ServiceAbility: + +```ts +import rpc from "@ohos.rpc" +import prompt from '@system.prompt' +import featureAbility from '@ohos.ability.featureAbility' + +let option = { + onConnect: function onConnectCallback(element, proxy) { + console.info(`onConnectLocalService onConnectDone`) + if (proxy === null) { + prompt.showToast({ + message: "Connect service failed" + }) + return + } + let data = rpc.MessageParcel.create() + let reply = rpc.MessageParcel.create() + let option = new rpc.MessageOption() + data.writeInterfaceToken("connect.test.token") + proxy.sendRequest(0, data, reply, option) + prompt.showToast({ + message: "Connect service success" + }) + }, + onDisconnect: function onDisconnectCallback(element) { + console.info(`onConnectLocalService onDisconnectDone element:${element}`) + prompt.showToast({ + message: "Disconnect service success" + }) + }, + onFailed: function onFailedCallback(code) { + console.info(`onConnectLocalService onFailed errCode:${code}`) + prompt.showToast({ + message: "Connect local service onFailed" + }) + } +} + +let request = { + bundleName: "com.example.myapplication", + abilityName: "com.example.myapplication.ServiceAbility", +} +let connId = featureAbility.connectAbility(request, option) +``` + + +When the ServiceAbility is connected, the **onConnect()** callback is invoked and returns an **IRemoteObject** defining the proxy used for communicating with the ServiceAbility. OpenHarmony provides a default implementation of **IRemoteObject**. You can extend **rpc.RemoteObject** to implement your own class of **IRemoteObject**. + + +The following sample code shows how the ServiceAbility returns itself to the caller: + +```ts +import rpc from "@ohos.rpc" + +class FirstServiceAbilityStub extends rpc.RemoteObject { + constructor(des: any) { + if (typeof des === 'string') { + super(des) + } else { + return + } + } + + onRemoteRequest(code: number, data: any, reply: any, option: any) { + console.info(`onRemoteRequest called`) + if (code === 1) { + let string = data.readString() + console.info(`string=${string}`) + let result = Array.from(string).sort().join('') + console.info(`result=${result}`) + reply.writeString(result) + } else { + console.info(`unknown request code`) + } + return true + } +} +``` diff --git a/en/application-dev/application-models/context-switch.md b/en/application-dev/application-models/context-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..2f52158f5d36be8c59f747376195e9e43078d1f9 --- /dev/null +++ b/en/application-dev/application-models/context-switch.md @@ -0,0 +1,28 @@ +# Context Switching + + + | API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API or Field in the Stage Model| +| -------- | -------- | -------- | +| [getOrCreateLocalDir(callback:AsyncCallback<string>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetorcreatelocaldir7)
[getOrCreateLocalDir():Promise<string>;](../reference/apis/js-apis-inner-app-context.md#contextgetorcreatelocaldir7-1) | There is no corresponding API in the stage model.| Applications developed on the stage model do not have the operation permission in the application root directory. Therefore, no corresponding API is provided.| +| [verifyPermission(permission:string,options:PermissionOptions,callback:AsyncCallback<number>):void;](../reference/apis/js-apis-inner-app-context.md#contextverifypermission7)
[verifyPermission(permission:string,callback:AsyncCallback<number>):void;](../reference/apis/js-apis-inner-app-context.md#contextverifypermission7-1)
[verifyPermission(permission:string,options?:PermissionOptions):Promise<number>;](../reference/apis/js-apis-inner-app-context.md#contextverifypermission7-2) | \@ohos.abilityAccessCtrl.d.ts | [verifyAccessTokenSync(tokenID: number, permissionName: Permissions): GrantStatus;](../reference/apis/js-apis-abilityAccessCtrl.md#verifyaccesstokensync9)
[verifyAccessToken(tokenID: number, permissionName: Permissions): Promise<GrantStatus>;](../reference/apis/js-apis-abilityAccessCtrl.md#verifyaccesstoken9) | +| [requestPermissionsFromUser(permissions:Array<string>,requestCode:number,resultCallback:AsyncCallback<PermissionRequestResult>):void;](../reference/apis/js-apis-inner-app-context.md#contextrequestpermissionsfromuser7)
[requestPermissionsFromUser(permissions:Array<string>,requestCode:number):Promise<PermissionRequestResult>;](../reference/apis/js-apis-inner-app-context.md#contextrequestpermissionsfromuser7-1) | application\UIAbilityContext.d.ts | [requestPermissionsFromUser(permissions: Array<string>, requestCallback: AsyncCallback<PermissionRequestResult>) : void;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextrequestpermissionsfromuser)
[requestPermissionsFromUser(permissions: Array<string>) : Promise<PermissionRequestResult>;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextrequestpermissionsfromuser-1) | +| [getApplicationInfo(callback:AsyncCallback<ApplicationInfo>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetapplicationinfo7)
[getApplicationInfo():Promise<ApplicationInfo>;](../reference/apis/js-apis-inner-app-context.md#contextgetapplicationinfo7-1) | application\Context.d.ts | [applicationInfo: ApplicationInfo;](../reference/apis/js-apis-inner-application-context.md#attributes)| +| [getBundleName(callback : AsyncCallback<string>): void;](../reference/apis/js-apis-inner-app-context.md#contextgetbundlename7)
[getBundleName(): Promise<string>;](../reference/apis/js-apis-inner-app-context.md#contextgetbundlename7-1) | application\UIAbilityContext.d.ts | [abilityInfo.bundleName: string;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#attributes)| +| [getDisplayOrientation(callback : AsyncCallback<bundle.DisplayOrientation>): void;](../reference/apis/js-apis-inner-app-context.md#contextgetdisplayorientation7)
[getDisplayOrientation(): Promise<bundle.DisplayOrientation>;](../reference/apis/js-apis-inner-app-context.md#contextgetdisplayorientation7-1) | \@ohos.screen.d.ts | [readonly orientation: Orientation;](../reference/apis/js-apis-screen.md#orientation) | +| [setDisplayOrientation(orientation:bundle.DisplayOrientation, callback:AsyncCallback<void>):void;](../reference/apis/js-apis-inner-app-context.md#contextsetdisplayorientation7)
[setDisplayOrientation(orientation:bundle.DisplayOrientation):Promise<void>;](../reference/apis/js-apis-inner-app-context.md#contextsetdisplayorientation7-1) | \@ohos.screen.d.ts | [setOrientation(orientation: Orientation, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-screen.md#setorientation)
[setOrientation(orientation: Orientation): Promise<void>;](../reference/apis/js-apis-screen.md#setorientation-1) | +| [setShowOnLockScreen(show:boolean, callback:AsyncCallback<void>):void;](../reference/apis/js-apis-inner-app-context.md#contextsetshowonlockscreen7)
[setShowOnLockScreen(show:boolean):Promise<void>;](../reference/apis/js-apis-inner-app-context.md#contextsetshowonlockscreen7-1) | \@ohos.window.d.ts | [setShowOnLockScreen(showOnLockScreen: boolean): void;](../reference/apis/js-apis-window.md#setshowonlockscreen9) | +| [setWakeUpScreen(wakeUp:boolean, callback:AsyncCallback<void>):void;](../reference/apis/js-apis-inner-app-context.md#contextsetwakeupscreen7)
[setWakeUpScreen(wakeUp:boolean):Promise<void>;](../reference/apis/js-apis-inner-app-context.md#contextsetwakeupscreen7-1) | \@ohos.window.d.ts | [setWakeUpScreen(wakeUp: boolean): void;](../reference/apis/js-apis-window.md#setwakeupscreen9) | +| [getProcessInfo(callback:AsyncCallback<ProcessInfo>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetprocessinfo7)
[getProcessInfo():Promise<ProcessInfo>;](../reference/apis/js-apis-inner-app-context.md#contextgetprocessinfo7-1) | \@ohos.app.ability.abilityManager.d.ts | [getAbilityRunningInfos(callback: AsyncCallback<Array<AbilityRunningInfo>>): void;](../reference/apis/js-apis-app-ability-abilityManager.md#getabilityrunninginfos)
[getAbilityRunningInfos(): Promise<Array<AbilityRunningInfo>>;](../reference/apis/js-apis-app-ability-abilityManager.md#getabilityrunninginfos-1) | +| [getElementName(callback:AsyncCallback<ElementName>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetelementname7)
[getElementName():Promise<ElementName>;](../reference/apis/js-apis-inner-app-context.md#contextgetelementname7-1) | application\UIAbilityContext.d.ts | [abilityInfo.name: string;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#attributes)
[abilityInfo.bundleName: string;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#attributes)| +| [getProcessName(callback:AsyncCallback<string>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetprocessname7)
[getProcessName():Promise<string>;](../reference/apis/js-apis-inner-app-context.md#contextgetprocessname7-1) | \@ohos.app.ability.abilityManager.d.ts | [getAbilityRunningInfos(callback: AsyncCallback<Array<AbilityRunningInfo>>): void;](../reference/apis/js-apis-app-ability-abilityManager.md#getabilityrunninginfos)
[getAbilityRunningInfos(): Promise<Array<AbilityRunningInfo>>;](../reference/apis/js-apis-app-ability-abilityManager.md#getabilityrunninginfos-1) | +| [getCallingBundle(callback:AsyncCallback<string>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetcallingbundle7)
[getCallingBundle():Promise<string>;](../reference/apis/js-apis-inner-app-context.md#contextgetcallingbundle7-1) | There is no corresponding API in the stage model.| Applications developed on the stage model can use the **ohos.aafwk.param.callerUid** parameter of **Want.parameters** to obtain the application information of the caller.| +| [getFilesDir(callback:AsyncCallback<string>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetfilesdir)
[getFilesDir():Promise<string>;](../reference/apis/js-apis-inner-app-context.md#contextgetfilesdir-1) | application\Context.d.ts | [filesDir: string;](../reference/apis/js-apis-inner-application-context.md#attributes)| +| [getCacheDir(callback:AsyncCallback<string>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetcachedir)
[getCacheDir():Promise<string>;](../reference/apis/js-apis-inner-app-context.md#contextgetcachedir-1) | application\Context.d.ts | [cacheDir: string;](../reference/apis/js-apis-inner-application-context.md#attributes)| +| [getOrCreateDistributedDir(callback:AsyncCallback<string>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetorcreatedistributeddir7)
[getOrCreateDistributedDir():Promise<string>;](../reference/apis/js-apis-inner-app-context.md#contextgetorcreatedistributeddir7-1) | application\Context.d.ts | [distributedFilesDir: string;](../reference/apis/js-apis-inner-application-context.md#attributes)| +| [getAppType(callback:AsyncCallback<string>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetapptype7)
[getAppType():Promise<string>;](../reference/apis/js-apis-inner-app-context.md#contextgetapptype7-1) | application\UIAbilityContext.d.ts | The stage model obtains the application type through the **type** attribute of the **abilityInfo** field.
[abilityInfo.type: bundleManager.AbilityType;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#attributes)| +| [getHapModuleInfo(callback:AsyncCallback<HapModuleInfo>):void;](../reference/apis/js-apis-inner-app-context.md#contextgethapmoduleinfo7)
[getHapModuleInfo():Promise<HapModuleInfo>;](../reference/apis/js-apis-inner-app-context.md#contextgethapmoduleinfo7-1) | application\UIAbilityContext.d.ts | [currentHapModuleInfo: HapModuleInfo;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#attributes)| +| [getAppVersionInfo(callback:AsyncCallback<AppVersionInfo>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetappversioninfo7)
[getAppVersionInfo():Promise<AppVersionInfo>;](../reference/apis/js-apis-inner-app-context.md#contextgetappversioninfo7-1) | bundle\bundleInfo.d.ts | [readonly name: string;](../reference/apis/js-apis-bundleManager-bundleInfo.md#bundleinfo-1)
[readonly versionCode: number;](../reference/apis/js-apis-bundleManager-bundleInfo.md#bundleinfo-1)
[readonly versionName: string;](../reference/apis/js-apis-bundleManager-bundleInfo.md#bundleinfo-1) | +| [getApplicationContext():Context;](../reference/apis/js-apis-inner-app-context.md#contextgetapplicationcontext7) | application\Context.d.ts | [getApplicationContext(): ApplicationContext;](../reference/apis/js-apis-inner-application-context.md#contextgetapplicationcontext) | +| [getAbilityInfo(callback:AsyncCallback<AbilityInfo>):void;](../reference/apis/js-apis-inner-app-context.md#contextgetabilityinfo7)
[getAbilityInfo():Promise<AbilityInfo>;](../reference/apis/js-apis-inner-app-context.md#contextgetabilityinfo7-1) | application\UIAbilityContext.d.ts | [abilityInfo: AbilityInfo;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#attributes)| +| [isUpdatingConfigurations(callback:AsyncCallback<boolean>):void;](../reference/apis/js-apis-inner-app-context.md#contextisupdatingconfigurations7)
[isUpdatingConfigurations():Promise<boolean>;](../reference/apis/js-apis-inner-app-context.md#contextisupdatingconfigurations7-1) | There is no corresponding API in the stage model.| OpenHarmony applications do not restart when the system environment changes. The **onConfigurationUpdated** callback is invoked to notify the applications of the changes. This API provides an empty implementation in the FA model, and the stage model does not provide a corresponding API.| +| [printDrawnCompleted(callback:AsyncCallback<void>):void;](../reference/apis/js-apis-inner-app-context.md#contextprintdrawncompleted7)
[printDrawnCompleted():Promise<void>;](../reference/apis/js-apis-inner-app-context.md#contextprintdrawncompleted7-1) | There is no corresponding API in the stage model.| This API provides an empty implementation in the FA model. The stage model does not provide a corresponding API.| diff --git a/en/application-dev/application-models/create-dataability.md b/en/application-dev/application-models/create-dataability.md new file mode 100644 index 0000000000000000000000000000000000000000..488b0593dbdc23bc1e6ea30c17f9165a92c79f20 --- /dev/null +++ b/en/application-dev/application-models/create-dataability.md @@ -0,0 +1,62 @@ +# Creating a DataAbility + + +To meet the basic requirements of the database storage service, implement the **Insert**, **Query**, **Update**, and **Delete** methods for a DataAbility. The **BatchInsert** and **ExecuteBatch** methods have already implemented the traversal logic, but not batch data processing. + + +The following sample code shows how to create a DataAbility: + +```ts +import featureAbility from '@ohos.ability.featureAbility' +import dataAbility from '@ohos.data.dataAbility' +import dataRdb from '@ohos.data.rdb' + +const TABLE_NAME = 'book' +const STORE_CONFIG = { name: 'book.db' } +const SQL_CREATE_TABLE = 'CREATE TABLE IF NOT EXISTS book(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, introduction TEXT NOT NULL)' +let rdbStore: dataRdb.RdbStore = undefined + +export default { + onInitialized(abilityInfo) { + console.info('DataAbility onInitialized, abilityInfo:' + abilityInfo.bundleName) + let context = featureAbility.getContext() + dataRdb.getRdbStore(context, STORE_CONFIG, 1, (err, store) => { + console.info('DataAbility getRdbStore callback') + store.executeSql(SQL_CREATE_TABLE, []) + rdbStore = store + }); + }, + insert(uri, valueBucket, callback) { + console.info('DataAbility insert start') + rdbStore.insert(TABLE_NAME, valueBucket, callback) + }, + batchInsert(uri, valueBuckets, callback) { + console.info('DataAbility batch insert start') + for (let i = 0;i < valueBuckets.length; i++) { + console.info('DataAbility batch insert i=' + i) + if (i < valueBuckets.length - 1) { + rdbStore.insert(TABLE_NAME, valueBuckets[i], (err: any, num: number) => { + console.info('DataAbility batch insert ret=' + num) + }) + } else { + rdbStore.insert(TABLE_NAME, valueBuckets[i], callback) + } + } + }, + query(uri, columns, predicates, callback) { + console.info('DataAbility query start') + let rdbPredicates = dataAbility.createRdbPredicates(TABLE_NAME, predicates) + rdbStore.query(rdbPredicates, columns, callback) + }, + update(uri, valueBucket, predicates, callback) { + console.info('DataAbilityupdate start') + let rdbPredicates = dataAbility.createRdbPredicates(TABLE_NAME, predicates) + rdbStore.update(valueBucket, rdbPredicates, callback) + }, + delete(uri, predicates, callback) { + console.info('DataAbilitydelete start') + let rdbPredicates = dataAbility.createRdbPredicates(TABLE_NAME, predicates) + rdbStore.delete(rdbPredicates, callback) + } +}; +``` diff --git a/en/application-dev/application-models/create-pageability.md b/en/application-dev/application-models/create-pageability.md new file mode 100644 index 0000000000000000000000000000000000000000..7a79770c309a165b8421974b28263bb20fa587ee --- /dev/null +++ b/en/application-dev/application-models/create-pageability.md @@ -0,0 +1,96 @@ +# Creating a PageAbility + + +When you create a PageAbility on DevEco Studio, DevEco Studio automatically generates the **onCreate()** and **onDestroy()** callbacks in **app.js** and **app.ets**. You need to implement the other lifecycle callbacks in **app.js** and **app.ets**. The following code snippet shows how to create a PageAbility: + +```ts +export default { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, + onShow() { + console.info('Application onShow') + }, + onHide() { + console.info('Application onHide') + }, + onActive() { + console.info('Application onActive') + }, + onInactive() { + console.info('Application onInactive') + }, + onNewWant() { + console.info('Application onNewWant') + }, +} +``` + + +After the PageAbility is created, its abilities-related configuration items are displayed in the **config.json** file. The following is an example **config.json** file of an ability named MainAbility: + +```json +{ + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "formsEnabled": false, + "label": "$string:MainAbility_label", + "type": "page", + "launchType": "singleton" + } + ] +} +``` + + +In the FA model, you can call **getContext** of **featureAbility** to obtain the application context and then use the capabilities provided by the context. + +**Table 1** featureAbility APIs + +| API| Description| +| -------- | -------- | +| getContext() | Obtains the application context.| + + +The following code snippet shows how to use **getContext()** to obtain the application context and distributed directory: + +```ts +import featureAbility from '@ohos.ability.featureAbility' +import fileIo from '@ohos.fileio' + +(async () => { + let dir: string + try { + console.info('Begin to getOrCreateDistributedDir') + dir = await featureAbility.getContext().getOrCreateDistributedDir() + console.info('distribute dir is ' + dir) + } catch (error) { + console.error('getOrCreateDistributedDir failed with ' + error) + } + + let fd: number; + let path = dir + "/a.txt"; + fd = fileIo.openSync(path, 0o2 | 0o100, 0o666); + fileIo.close(fd); +})() +``` diff --git a/en/application-dev/application-models/create-serviceability.md b/en/application-dev/application-models/create-serviceability.md new file mode 100644 index 0000000000000000000000000000000000000000..78623839266f4e97de26d0a3d66c19236eacf815 --- /dev/null +++ b/en/application-dev/application-models/create-serviceability.md @@ -0,0 +1,61 @@ +# Creating a ServiceAbility + + +1. Create a ServiceAbility. + + Override the ServiceAbility lifecycle callbacks to implement your own logic for processing interaction requests. + + ```ts + import rpc from "@ohos.rpc" + + class FirstServiceAbilityStub extends rpc.RemoteObject { + constructor(des: any) { + if (typeof des === 'string') { + super(des) + } else { + return + } + } + } + + export default { + onStart() { + console.info('ServiceAbility onStart') + }, + onStop() { + console.info('ServiceAbility onStop') + }, + onCommand(want, startId) { + console.info('ServiceAbility onCommand') + }, + onConnect(want) { + console.info('ServiceAbility onConnect' + want) + return new FirstServiceAbilityStub('test') + }, + onDisconnect(want) { + console.info('ServiceAbility onDisconnect' + want) + } + } + ``` + +2. Register the ServiceAbility. + + Declare the ServiceAbility in the **config.json** file by setting its **type** attribute to **service**. The **visible** attribute specifies whether the ServiceAbility can be called by other applications. The value **true** means that the ServiceAbility can be called by other applications, and **false** means that the ServiceAbility can be called only within the application. To enable the ServiceAbility to be called by other applications, set **visible** to **true** when registering the ServiceAbility and enable associated startup. For details about the startup rules, see [Component Startup Rules](component-startup-rules.md). + + ```json + { + "module": { + "abilities": [ + { + "name": ".ServiceAbility", + "srcLanguage": "ets", + "srcPath": "ServiceAbility", + "icon": "$media:icon", + "description": "hap sample empty service", + "type": "service", + "visible": true + } + ] + } + } + ``` diff --git a/en/application-dev/application-models/data-share-via-want.md b/en/application-dev/application-models/data-share-via-want.md new file mode 100644 index 0000000000000000000000000000000000000000..63d7d26d47b64407e30fc03c2edb7ead210dc392 --- /dev/null +++ b/en/application-dev/application-models/data-share-via-want.md @@ -0,0 +1,111 @@ +# Using Want to Share Data Between Applications + + +Users often need to share data (such as a text or an image) from one application to another. The following uses PDF file sharing as an example to describe how to use Want to share data between applications. + + +## Prerequisites + +1. There are two UIAbility components (one for the sharing party and the other for the shared party) and one system component (used as the application selector). When the sharing party initiates data sharing through **startAbility()**, the application selector is started. The system implicitly matches and displays all applications that support the type of data to share. After the user selects an application, the system starts that application to complete data sharing. + +2. In this section, data sharing is triggered by touching a button. You can use other ways to trigger data sharing during application development. This section focuses on the Want configuration used for data sharing. + +3. The following actions are involved in this section: + - **ACTION_SELECT (ohos.want.action.select)**: action of displaying the application selector. + - **ACTION_SEND_DATA (ohos.want.action.sendData)**: action of launching the UI for sending a single data record. It is used to transfer data to the shared party. + + +## How to Develop + +- Sharing party + 1. In the stage mode, the [File Descriptor (FD)](../reference/apis/js-apis-fileio.md#fileioopensync) is used for file transfer. This example assumes that the path of the file to share is obtained. + + ```ts + import fileIO from '@ohos.fileio'; + + // let path = ... + // Open the file whose path is a variable. + let fileFd = fileIO.openSync(path, 0o102, 0o666); + ``` + + 2. As described in the prerequisites, the sharing party starts an application selector and shares the data to the selector, and the selector transfers the data to the shared party. Want of the sharing party must be nested at two layers. At the first layer, implicit Want is used together with the **ohos.want.action.select** action to display the application selector. At the second layer, complete Want is declared in the custom field **parameters** to transfer the data to share. + + ```ts + import wantConstant from '@ohos.app.ability.wantConstant'; + + // let path = ... + // let fileFd = ... + // let fileSize = ... + let want = { + / This action is used to implicitly match the application selector. + action: wantConstant.Action.ACTION_SELECT, + // This is the custom parameter in the first layer of Want, + / which is intended to add information to the application selector. + parameters: { + // MIME type of PDF. + "ability.picker.type": "application/pdf", + "ability.picker.fileNames": [path], + "ability.picker.fileSizes": [fileSize], + // This nested Want ,which will be directly sent to the selected application. + "ability.want.params.INTENT": { + "action": "ohos.want.action.sendData", + "type": "application/pdf", + "parameters": { + "keyFd": {"type": "FD", "value": fileFd} + } + } + } + } + ``` + + In the preceding code, the custom field **parameters** is used. The **ability.picker.\*** fields in the first-layer **parameters** are used to pass the information to be displayed on the application selector. The following fields are involved: + + - **"ability.picker.type"**: The application selector renders the file type icon based on this field. + - **"ability.picker.fileNames"**: The application selector displays the file name based on this field. + - **"ability.picker.fileSizes"**: The application selector displays the file size based on this field. The unit is byte. + - **"ability.picker.fileNames"** and **"ability.picker.fileSizes"** are arrays and have a one-to-one mapping. + + For example, when **"ability.picker.type"** is **"application/pdf"**, **"ability.picker.fileNames"** is **"["APIs.pdf"]"**, and **"ability.picker.fileSizes"** is **"[350 \* 1024]"**, the application selector is displayed as follows: + + stage-want2 + + In the preceding code, the **ability.want.params.INTENT** field is nested Want. In this field, **action** and **type** are used for implicit matching by the application selector. For details about implicit matching, see [Implicit Want Matching Rules](explicit-implicit-want-mappings.md#interpretation-of-implicit-want-matching-rules). After the user selects an application, the nested Want of the **ability.want.params.INTENT** field is passed to that application. + +- Shared party + 1. As mentioned above, the application selector performs implicit matching based on the **ability.want.params.INTENT** field. Therefore, you must set **skills** in the ability configuration file (**module.json5** file in the stage model) of the shared party as follows: + + ```ts + "skills": [ + { + "entities": [ + // ... + ], + "actions": [ + "ohos.want.action.sendData" + // ... + ], + "uris": [ + { + "type": "application/pdf" + }, + // ... + ] + }, + ] + ``` + + The **actions** and **type** fields in **uris** match the **action** and **type** fields in **ability.want.params.INTENT**, respectively. + + Files can be transferred in FD mode, but not URI mode. In implicit matching, the **type** field in Want must match the **type** field in **uris** under **skills** of the shared party. Therefore, specify only the **type** field in **uris**. If **host** and **port** are specified, the matching fails. The application selector initiates implicit matching based on **ability.want.params.INTENT**. Therefore, when the **uri** field added to **ability.want.params.INTENT** matches the **uris** field under **skills**, the matching is successful and additional data can be transferred. + 2. After the application selector starts the shared party, the system calls **onCreate** and passes **ability.want.params.INTENT** to the **want** parameter. + + ```ts + onCreate(want, launchParam) { + // When keyFd is undefined, the application crashes. + if (want["parameters"]["keyFd"] !== undefined) { + // Receive the file descriptor. + let fd = want["parameters"]["keyFd"].value; + // ... + } + } + ``` diff --git a/en/application-dev/application-models/dataability-configuration.md b/en/application-dev/application-models/dataability-configuration.md new file mode 100644 index 0000000000000000000000000000000000000000..d3618ea7a026311004524a9eb79ff3d1951d6a93 --- /dev/null +++ b/en/application-dev/application-models/dataability-configuration.md @@ -0,0 +1,62 @@ +# DataAbility Component Configuration + + +## URI Introduction + +A Uniform Resource Identifier (URI) is used to identify a specific data item, such as a table in the database or a file on the disk. URIs used in OpenHarmony comply with the commonly used URI standard. A URI consists of the components: + +![fa-dataability-uri](figures/fa-dataability-uri.png) + +- **scheme**: name of the scheme used by the DataAbility. The value is fixed at **dataability**. + +- **authority**: device ID. To access data on a remote device, set this component to the ID of the remote device. To access data on the local device, leave this component empty. + +- **path**: location of the specific resource to access. + +- **query**: query parameters. + +- **fragment**: subordinate resources to access. + +Example URIs: + +- Cross-device communication: dataability://*device*id_/*com.domainname.dataability.persondata*/*person*/*10* + +- Local-device communication: dataability:///*com.domainname.dataability.persondata*/*person*/*1* + +> **NOTE** +> +> In the case of local-device communication, **device_id** is empty, and therefore, there are three slashes (/) after **dataability:**. + + +## Introduction to Certain Configuration Items + +Similar to a PageAbility, a DataAbility is configured in **abilities** under **module** of the **config.json** file. The difference between a DataAbility and PageAbility lies in the **type** and **uri** fields. + +**Table 1** DataAbility configuration items + +| Name| Description| +| -------- | -------- | +| "name" | Ability name.| +| "type" | Type of the ability. The value **data** indicates a DataAbility.| +| "uri" | URI used for communication.| +| "visible" | Whether the ability is visible to other applications. Data sharing is allowed only when the value is **true**.| + +The following is an example **config.json** file: + + +```json +"abilities": [{ + "srcPath": "DataAbility", + "name": ".DataAbility", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_dataability", + "type": "data", + "visible": true, + "uri": "dataability://ohos.samples.etsdataability.DataAbility" +}] +``` + +For details about the configuration items, see [Internal Structure of module](../quick-start/module-structure.md). + + \ No newline at end of file diff --git a/en/application-dev/application-models/dataability-lifecycle.md b/en/application-dev/application-models/dataability-lifecycle.md new file mode 100644 index 0000000000000000000000000000000000000000..f35f46ffd9504a29897694054efc15f9a8465a57 --- /dev/null +++ b/en/application-dev/application-models/dataability-lifecycle.md @@ -0,0 +1,23 @@ +# DataAbility Lifecycle + + +You can override lifecycle callbacks (described in the table below) for a DataAbility based on service requirements. + + +**Table 1** DataAbility lifecycle APIs + +| API| Description| +| -------- | -------- | +| onInitialized?(info: AbilityInfo): void | Called during ability initialization to initialize the relational database (RDB).| +| update?(uri: string, valueBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void | Updates data in the database.| +| query?(uri: string, columns: Array<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void | Queries data in the database.| +| delete?(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void | Deletes one or more data records from the database.| +| normalizeUri?(uri: string, callback: AsyncCallback<string>): void | Normalizes the URI. A normalized URI applies to cross-device use, persistence, backup, and restore. When the context changes, it ensures that the same data item can be referenced.| +| batchInsert?(uri: string, valueBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback<number>): void | Inserts multiple data records into the database.| +| denormalizeUri?(uri: string, callback: AsyncCallback<string>): void | Converts a normalized URI generated by **normalizeUri** into a denormalized URI.| +| insert?(uri: string, valueBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void | Inserts a data record into the database.| +| openFile?(uri: string, mode: string, callback: AsyncCallback<number>): void | Opens a file.| +| getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>): void | Obtains the MIME type of a file.| +| getType?(uri: string, callback: AsyncCallback<string>): void | Obtains the MIME type matching the data specified by the URI.| +| executeBatch?(ops: Array<DataAbilityOperation>, callback: AsyncCallback<Array<DataAbilityResult>>): void | Operates data in the database in batches.| +| call?(method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void | Calls a custom API.| diff --git a/en/application-dev/application-models/dataability-overview.md b/en/application-dev/application-models/dataability-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..b89ee68bb5fe6cda341dea332a24cf1010c4935f --- /dev/null +++ b/en/application-dev/application-models/dataability-overview.md @@ -0,0 +1,10 @@ +# DataAbility Component Overview + + +A DataAbility is an ability that uses the Data template. It provides unified data access for external systems, but not a UI for user interaction. A DataAbility can be started by a PageAbility, a ServiceAbility, or other applications. It remains to run in the background even after the user switches to another application. + + +A DataAbility helps applications manage access to data stored by themselves and other applications, and provides methods for sharing data with other applications, either on the same device or across devices. + + +Data can be stored in a database or files on disks. The DataAbility provide methods for inserting, deleting, updating, and querying data, and opening files. You should implement these methods. diff --git a/en/application-dev/application-models/dataability-permission-control.md b/en/application-dev/application-models/dataability-permission-control.md new file mode 100644 index 0000000000000000000000000000000000000000..25c5e82726dbc3a7dba8158a0847b5c59ea0c98e --- /dev/null +++ b/en/application-dev/application-models/dataability-permission-control.md @@ -0,0 +1,60 @@ +# DataAbility Permission Control + + +The DataAbility uses permission control to determine whether an ability can access the data service it provides. There are static and dynamic permission controls. + + +## Static Permission Control + +The DataAbility functions as the server. When being started, the DataAbility verifies the client permissions against the settings of the optional fields **readPermission**, **writePermission**, and **Permission** fields in the **config.json** file. The following is an example: + + +```json +"abilities": [{ + "srcPath": "DataAbility", + "name": ".DataAbility", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_dataability", + "type": "data", + "visible": true, + "uri": "dataability://ohos.samples.etsdataability.DataAbility", + "readPermission":"ohos.permission.READ_CONTACTS", + "writePermission":"ohos.permission.WRITE_CONTACTS" +}] +``` + +The client permission is configured in **reqPermissions** under **module** in the **config.json** file. The following is an example: + + +```json +{ + "module": { + "reqPermissions":{ + { + "name":"ohos.permission.READ_CONTACTS" + }, + { + "name":"ohos.permission.WRITE_CONTACTS" + } + } + } +} +``` + + +## Dynamic Permission Control + +Static permission control determines whether a DataAbility can be started by another ability or application. It does not verify the permission of each read/write interface. + +Dynamic permission control verifies whether the client has the corresponding permission for every read/write interface. The table below lists the permissions required for calling these interfaces. + +**Table 1** Permission configuration for data read/write interfaces + +| Interface with the Read Permission| Interface with the Write Permission| Interface with the Read/Write Permission Based on Actual Requirements| +| -------- | -------- | -------- | +| query, normalizeUri, denormalizeUri, openfile (with **mode** set to **'r'**)| insert, batchInsert, delete, update, openfile (with **mode** set to **'w'**)| executeBatch | + +For interfaces that require the read permission, the server must have **readPermission** specified, and the client must obtain the read permission before calling them. + +For interfaces that require the write permission, the server must have **writePermission** specified, and the client must obtain the write permission before calling them. diff --git a/en/application-dev/application-models/dataability-switch.md b/en/application-dev/application-models/dataability-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..b91d50ca37a97fdc1d4824a93a6093bac7cd0f77 --- /dev/null +++ b/en/application-dev/application-models/dataability-switch.md @@ -0,0 +1,44 @@ +# DataAbility Switching + + +The DataAbility component in the FA model corresponds to the DataShareExtensionAbility component in the stage model. + + +The DataShareExtensionAbility class provides system APIs. Only system applications can create DataShareExtensionAbility instances. Therefore, DataAbility switching adopts different policies for system applications and third-party applications. + + +## Switching a DataAbility of a System Application + +The procedure for switching a DataAbility of a system application is similar to the procedure of PageAbility switching. + +1. Create a DataShareExtensionAbility in the stage model. + +2. Migrate the DataAbility code to the DataShareExtensionAbility. + + The table below describes the lifecycle comparison of the DataAbility and DataShareExtensionAbility. + + | DataAbility| DataShareExtensionAbility| Comparison Description| + | -------- | -------- | -------- | + | onInitialized?(info: AbilityInfo): void | onCreate?(want: Want, callback: AsyncCallback<void>): void
| The two methods have the same invoking time but different input parameters. In the stage model, the **want** parameter is added so that you can obtain parameters during creation.| + | update?(uri: string, valueBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void | update?(uri: string, predicates: dataSharePredicates.DataSharePredicates, value: ValuesBucket, callback: AsyncCallback<number>): void | The two methods have the same meaning and invoking time, but slightly different parameter sequence and parameter type. A simple reconstruction is required.| + | query?(uri: string, columns: Array<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void | query?(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>): void;| The two methods have the same meaning and invoking time, but slightly different parameter sequence and parameter type. A simple reconstruction is required.| + | delete?(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void | delete?(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>):| The two methods have the same meaning and invoking time, but slightly different parameter type. A simple reconstruction is required.| + | normalizeUri?(uri: string, callback: AsyncCallback<string>): void | normalizeUri?(uri: string, callback: AsyncCallback<string>): void| The two methods have the same meaning, invoking time, and parameters.| + | batchInsert?(uri: string, valueBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback<number>): void | batchInsert?(uri: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>): void| The two methods have the same meaning and invoking time, but slightly different parameter type. A simple reconstruction is required.| + | denormalizeUri?(uri: string, callback: AsyncCallback<string>): void | denormalizeUri?(uri: string, callback: AsyncCallback<string>): void | The two methods have the same meaning, invoking time, and parameters.| + | insert?(uri: string, valueBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void | insert?(uri: string, value: ValuesBucket, callback: AsyncCallback<number>): void | The two methods have the same meaning and invoking time, but slightly different parameter type. A simple reconstruction is required.| + | openFile?(uri: string, mode: string, callback: AsyncCallback<number>): void | NA | The stage model does not support cross-process URI access. You are advised to use [the **want** parameter to carry the file descriptor and file information](data-share-via-want.md) for cross-process file access.| + | getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>): void | NA | The stage model does not support cross-process URI access. You are advised to use [the **want** parameter to carry the file descriptor and file information](data-share-via-want.md) for cross-process file access.| + | getType?(uri: string, callback: AsyncCallback<string>): void | NA | The stage model does not support cross-process URI access. You are advised to use [the **want** parameter to carry the file descriptor and file information](data-share-via-want.md) for cross-process file access.| + | executeBatch?(ops: Array<DataAbilityOperation>, callback: AsyncCallback<Array<DataAbilityResult>>): void | NA | This method is not provided in the stage model. You need to implement the functionality based on service functions.| + | call?(method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void | NA | This method is not provided in the stage model. You need to implement the functionality based on service functions.| + + +## Switching a DataAbility of a Third-Party Application + +In the stage model, third-party applications cannot provide data services for other third-party applications. You can select a switching solution based on your service requirements. + +| Service Type| Switching Solution| +| -------- | -------- | +| Providing data for third-party applications| Match a scenario-specific [ExtensionAbility](../reference/apis/js-apis-bundleManager.md#extensionabilitytype).| +| Providing data within the application| Extract the component code as a common module for other components to use.| diff --git a/en/application-dev/application-models/dataabilityhelper-switch.md b/en/application-dev/application-models/dataabilityhelper-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..c709e30ae9c25bcbd47f781e1f43a51100960998 --- /dev/null +++ b/en/application-dev/application-models/dataabilityhelper-switch.md @@ -0,0 +1,20 @@ +# DataAbilityHelper Switching + + + | API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API in the Stage Model| +| -------- | -------- | -------- | +| [openFile(uri: string, mode: string, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperopenfile)
[openFile(uri: string, mode: string): Promise<number>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperopenfile-1) | \@ohos.data.fileAccess.d.ts | [openFile(uri: string, flags: OPENFLAGS) : Promise<number>;](../reference/apis/js-apis-fileAccess.md#fileaccesshelperopenfile)
[openFile(uri: string, flags: OPENFLAGS, callback: AsyncCallback<number>) : void;](../reference/apis/js-apis-fileAccess.md#fileaccesshelperopenfile) | +| [on(type: 'dataChange', uri: string, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperon) | \@ohos.data.dataShare.d.ts | [on(type: 'dataChange', uri: string, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-data-dataShare.md#ondatachange) | +| [off(type: 'dataChange', uri: string, callback?: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperoff) | \@ohos.data.dataShare.d.ts | [off(type: 'dataChange', uri: string, callback?: AsyncCallback<void>): void;](../reference/apis/js-apis-data-dataShare.md#offdatachange) | +| [getType(uri: string, callback: AsyncCallback<string>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelpergettype)
[getType(uri: string): Promise<string>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelpergettype-1) | There is no corresponding API in the stage model.| The stage model does not support cross-process URI access. You are advised to use [the want parameter to carry the file descriptor and file information](data-share-via-want.md) for cross-process file access.| +| [getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelpergetfiletypes)
[getFileTypes(uri: string, mimeTypeFilter: string): Promise<Array<string>>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelpergetfiletypes-1) | There is no corresponding API in the stage model.| The stage model does not support cross-process URI access. You are advised to use [the want parameter to carry the file descriptor and file information](data-share-via-want.md) for cross-process file access.| +| [normalizeUri(uri: string, callback: AsyncCallback<string>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelpernormalizeuri)
[normalizeUri(uri: string): Promise<string>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelpernormalizeuri-1) | \@ohos.data.dataShare.d.ts | [normalizeUri(uri: string, callback: AsyncCallback<string>): void;](../reference/apis/js-apis-data-dataShare.md#normalizeuri)
[normalizeUri(uri: string): Promise<string>;](../reference/apis/js-apis-data-dataShare.md#normalizeuri-1) | +| [denormalizeUri(uri: string, callback: AsyncCallback<string>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperdenormalizeuri)
[denormalizeUri(uri: string): Promise<string>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperdenormalizeuri-1) | \@ohos.data.dataShare.d.ts | [denormalizeUri(uri: string, callback: AsyncCallback<string>): void;](../reference/apis/js-apis-data-dataShare.md#denormalizeuri)
[denormalizeUri(uri: string): Promise<string>;](../reference/apis/js-apis-data-dataShare.md#denormalizeuri-1) | +| [notifyChange(uri: string, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelpernotifychange)
[notifyChange(uri: string): Promise<void>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelpernotifychange-1) | \@ohos.data.dataShare.d.ts | [notifyChange(uri: string, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-data-dataShare.md#notifychange)
[notifyChange(uri: string): Promise<void>;](../reference/apis/js-apis-data-dataShare.md#notifychange-1) | +| [insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperinsert)
[insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise<number>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperinsert-1) | \@ohos.data.dataShare.d.ts | [insert(uri: string, value: ValuesBucket, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-data-dataShare.md#insert)
[insert(uri: string, value: ValuesBucket): Promise<number>;](../reference/apis/js-apis-data-dataShare.md#insert-1) | +| [batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperbatchinsert)
[batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>): Promise<number>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperbatchinsert-1) | \@ohos.data.dataShare.d.ts | [batchInsert(uri: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-data-dataShare.md#batchinsert)
[batchInsert(uri: string, values: Array<ValuesBucket>): Promise<number>;](../reference/apis/js-apis-data-dataShare.md#batchinsert-1) | +| [delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperdelete)
[delete(uri: string, predicates?: dataAbility.DataAbilityPredicates): Promise<number>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperdelete-1)
[delete(uri: string, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperdelete) | \@ohos.data.dataShare.d.ts | [delete(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-data-dataShare.md#delete)
[delete(uri: string, predicates: dataSharePredicates.DataSharePredicates): Promise<number>;](../reference/apis/js-apis-data-dataShare.md#delete-1) | +| [update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperupdate)
[update(uri: string, valuesBucket: rdb.ValuesBucket, predicates?: dataAbility.DataAbilityPredicates): Promise<number>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperupdate-1)
[update(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperupdate) | \@ohos.data.dataShare.d.ts | [update(uri: string, predicates: dataSharePredicates.DataSharePredicates, value: ValuesBucket, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-data-dataShare.md#update)
[update(uri: string, predicates: dataSharePredicates.DataSharePredicates, value: ValuesBucket): Promise<number>;](../reference/apis/js-apis-data-dataShare.md#update-1) | +| [query(uri: string, columns: Array<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperquery)
[query(uri: string, callback: AsyncCallback<ResultSet>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperquery)
[query(uri: string, columns: Array<string>, callback: AsyncCallback<ResultSet>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperquery)
[query(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperquery)
[query(uri: string, columns?: Array<string>, predicates?: dataAbility.DataAbilityPredicates): Promise<ResultSet>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperquery-1) | \@ohos.data.dataShare.d.ts | [query(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<DataShareResultSet>): void;](../reference/apis/js-apis-data-dataShare.md#query)
[query(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>): Promise<DataShareResultSet>;](../reference/apis/js-apis-data-dataShare.md#query-1) | +| [call(uri: string, method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelpercall-1)
[call(uri: string, method: string, arg: string, extras: PacMap): Promise<PacMap>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelpercall) | There is no corresponding API in the stage model.| No corresponding API is provided.| +| [executeBatch(uri: string, operations: Array<DataAbilityOperation>, callback: AsyncCallback<Array<DataAbilityResult>>): void;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperexecutebatch)
[executeBatch(uri: string, operations: Array<DataAbilityOperation>): Promise<Array<DataAbilityResult>>;](../reference/apis/js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperexecutebatch-1) | There is no corresponding API in the stage model.| No corresponding API is provided.| diff --git a/en/application-dev/application-models/datashareextensionability.md b/en/application-dev/application-models/datashareextensionability.md new file mode 100644 index 0000000000000000000000000000000000000000..5b07ba68180fbcc2a51047d37ca9a82addd89cd8 --- /dev/null +++ b/en/application-dev/application-models/datashareextensionability.md @@ -0,0 +1,4 @@ +# DataShareExtensionAbility + + +DataShareExtensionAbility is available only for system application. It provides the data sharing capability. System applications can implement a DataShareExtensionAbility or access an existing DataShareExtensionAbility in the system. Third-party applications can only access an existing DataShareExtensionAbility. For details, see [DataShare Development](../database/database-datashare-guidelines.md). diff --git a/en/application-dev/application-models/explicit-implicit-want-mappings.md b/en/application-dev/application-models/explicit-implicit-want-mappings.md new file mode 100644 index 0000000000000000000000000000000000000000..99aa45c9f8f387e5717a90478a0a24d2be60f463 --- /dev/null +++ b/en/application-dev/application-models/explicit-implicit-want-mappings.md @@ -0,0 +1,162 @@ +# Matching Rules of Explicit Want and Implicit Want + + +Both explicit Want and implicit Want can be used to match an ability to start based on certain rules. These rules determine how the parameters set in Want match the configuration file declared by the target ability. + + +- **Matching rules of explicit Want** + + | Name| Type| Matching Item| Mandatory| Rule Description| + | -------- | -------- | -------- | -------- | -------- | + | deviceId | string | Yes| No| If this field is unspecified, only abilities on the local device are matched.| + | bundleName | string | Yes| Yes| If **abilityName** is specified but **bundleName** is unspecified, the matching fails.| + | moduleName | string | Yes| No| If this field is unspecified and multiple modules with the same ability name exist in the application, the first ability is matched by default.| + | abilityName | string | Yes| Yes| To use explicit Want, this field must be specified.| + | uri | string | No| No| This field is not used for matching. It is passed to the target ability as a parameter.| + | type | string | No| No| This field is not used for matching. It is passed to the target ability as a parameter.| + | action | string | No| No| This field is not used for matching. It is passed to the target ability as a parameter.| + | entities | Array<string> | No| No| This field is not used for matching. It is passed to the target ability as a parameter.| + | flags | number | No| No| This field is not used for matching and is directly transferred to the system for processing. It is generally used to set runtime information, such as URI data authorization.| +| parameters | {[key: string]: any} | No| No| This field is not used for matching. It is passed to the target ability as a parameter.| + +- **Matching rules for implicit Want** + | Name| Type| Matching Item| Mandatory| Rule Description| + | -------- | -------- | -------- | -------- | -------- | + | deviceId | string | Yes| No| Implicit invoking is not supported across devices.| + | abilityName | string | No| No| To use implicit Want, this field must be left unspecified.| + | bundleName | string | Yes| No| - When only **bundleName** is specified, matching is limited to that application.
- When both **bundleName** and **moduleName** are specified, matching is limited to that module in that application.
- When only **moduleName** is specified, the setting is invalid.
For details, see [Interpretation of Implicit Want Matching Rules](#interpretation-of-implicit-want-matching-rules). | + | moduleName | string | Yes| No|| + | uri | string | Yes| No|| + | type | string | Yes| No|| + | action | string | Yes| No|| + | entities | Array<string> | Yes| No|| + | flags | number | No| No| This field is not used for matching and is directly transferred to the system for processing. It is generally used to set runtime information, such as URI data authorization.| + | parameters | {[key: string]: any} | No| No| This field is not used for matching. It is passed to the target ability as a parameter.| + + +## Interpretation of Implicit Want Matching Rules + + +Get familiar with the following about implicit Want: + + +- The **want** parameter passed by the caller indicates the operation to be performed by the caller. It also provides data and application type restrictions. + +- The **skills** field declares the capabilities of the target ability. For details, see [the skills tag](../quick-start/module-configuration-file.md#skills-tag) in the [module.json5 file](../quick-start/module-configuration-file.md). + + +The system matches the **want** parameter (including the **action**, **entities**, **uri**, and **type** attributes) passed by the caller against the **skills** configuration (including the **actions**, **entities**, **uris**, and **type** attributes) of the abilities one by one. When all the four attributes are matched, a dialog box is displayed for users to select a matched application. + + +### Matching Rules of action in the want Parameter + +The system matches the [action](../reference/apis/js-apis-ability-wantConstant.md#wantconstantaction) attribute in the **want** parameter passed by the caller against **actions** under **skills** of the abilities. + +- If **action** in the passed **want** parameter is specified but **actions** under **skills** of an ability is unspecified, the matching fails. + +- If **action** in the passed **want** parameter is unspecified but **actions** under **skills** of an ability is specified, the matching is successful. + +- If **action** in the passed **want** parameter is specified, and **actions** under **skills** of an ability is specified and contains **action** in the passed **want** parameter, the matching is successful. + +- If **action** in the passed **want** parameter is specified, and **actions** under **skills** of an ability is specified but does not contain **action** in the passed **want** parameter, the matching fails. + + Figure 1 Matching rules of action in the want parameter + + want-action + + +### Matching Rules of entities in the want Parameter + +The system matches the [entities](../reference/apis/js-apis-ability-wantConstant.md#wantconstantentity) attribute in the **want** parameter passed by the caller against **entities** under **skills** of the abilities. + +- If **entities** in the passed **want** parameter is unspecified but **entities** under **skills** of an ability is specified, the matching is successful. + +- If **entities** in the passed **want** parameter is unspecified but **entities** under **skills** of an ability is unspecified, the matching is successful. + +- If **entities** in the passed **want** parameter is specified but **entities** under **skills** of an ability is unspecified, the matching fails. + +- If **entities** in the passed **want** parameter is specified, and **entities** under **skills** of an ability is specified and contains **entities** in the passed **want** parameter, the matching is successful. + +- If **entities** in the passed **want** parameter is specified, and **entities** under **skills** of an ability is specified but does not contain **entities** in the passed **want** parameter, the matching fails. + + Figure 2 Matching rule of entities in the want parameter +want-entities + + +### Matching Rules of uri and type in the want Parameter + +When the **uri** and **type** parameters are specified in the **want** parameter to initiate a component startup request, the system traverses the list of installed components and matches the **uris** array under **skills** of the abilities one by one. If one of the **uris** arrays under **skills** matches the **uri** and **type** in the passed **want**, the matching is successful. + +Figure 3 Matching rules when uri and type are specified in the want parameter +want-uri-type1 + +There are four combinations of **uri** and **type** settings. The matching rules are as follows: + +- Neither **uri** or **type** is specified in the **want** parameter. + - If the **uris** array under **skills** of an ability is unspecified, the matching is successful. + - If the **uris** array under **skills** of an ability contains an URI element whose **scheme** and **type** are unspecified, the matching is successful. + - In other cases, the matching fails. + +- Only **uri** is specified in the **want** parameter. + - If the **uris** array under **skills** of an ability is unspecified, the matching fails. + - If the **uris** array under **skills** of an ability contains an element whose [uri is matched](#matching-rules-of-uri) and **type** is unspecified, the matching is successful. Otherwise, the matching fails. + +- Only **type** is specified in the **want** parameter. + - If the **uris** array under **skills** of an ability is unspecified, the matching fails. + - If the **uris** array under **skills** of an ability contains an URI element whose **scheme** is unspecified and [type is matched](#matching-rules-of-type), the matching is successful. Otherwise, the matching fails. + +- Both **uri** and **type** are specified in the **want** parameter, as shown in Figure 3. + - If the **uris** array under **skills** of an ability is unspecified, the matching fails. + - If the **uris** array under **skills** of an ability contains an element whose [uri is matched](#matching-rules-of-uri) and [type is matched](#matching-rules-of-type), the matching is successful. Otherwise, the matching fails. + + +To simplify the description, **uri** and **type** passed in the **want** parameter are called **w_uri** and **w_type**, respectively; the **uris** array under **skills** of an ability to match is called **s_uris**; each element in the array is called **s_uri**. Matching is performed from top to bottom. + +Figure 4 Matching rules of uri and type in the want parameter +want-uri-type2 + + +### Matching Rules of uri + +To simplify the description, **uri** in the passed **want** parameter is called **w_uri**; **uri** under **skills** of an ability to match is called **s_uri**. The matching rules are as follows: + +- If **scheme** of **s_uri** is unspecified and **w_uri** is unspecified, the matching is successful. Otherwise, the matching fails. + +- If **host** of **s_uri** is unspecified and **scheme** of **w_uri** and **scheme** of **s_uri** are the same, the matching is successful. Otherwise, the matching fails. + +- If **path**, **pathStartWith**, and **pathRegex** of **s_uri** are unspecified and **w_uri** and **s_uri** are the same, the matching is successful. Otherwise, the matching fails. + +- If **path** of **s_uri** is specified and the **full path expressions** of **w_uri** and **s_uri** are the same, the matching is successful. Otherwise, the matching of **pathStartWith** continues. + +- If **pathStartWith** of **s_uri** is specified and **w_uri** contains the prefix expression of **s_uri**, the matching is successful. Otherwise, **pathRegex** matching continues. + +- If **pathRegex** of **s_uri** is specified and **w_uri** meets the regular expression of **s_uri**, the matching is successful. Otherwise, the matching fails. + +> **NOTE** +> +> The **scheme**, **host**, **port**, **path**, **pathStartWith**, and **pathRegex** attributes of **uris** under **skills** of an ability are concatenated. If **path**, **pathStartWith**, and **pathRegex** are declared in sequence, **uris** can be concatenated into the following expressions: +> +> - **Full path expression**: `scheme://host:port/path` +> +> - **Prefix expression**: `scheme://host:port/pathStartWith` +> +> - **Regular expression**: `scheme://host:port/pathRegex` + + +### Matching Rules of type + +> **NOTE** +> +> The matching rules of **type** described in this section are based on the fact that **type** in the **want** parameter is specified. If **type** is unspecified, follow the [matching rules of uri and type in the want parameter](#matching-rules-of-uri-and-type-in-the-want-parameter). + +To simplify the description, **uri** in the passed **want** parameter is called **w_type**, and **type** of **uris** under **skills** of an ability to match is called **s_type**. The matching rules are as follows: + +- If **s_type** is unspecified, the matching fails. + +- If **s_type** or **w_type** contains the wildcard `*/*`, the matching is successful. + +- If the last character of **s_type** is the wildcard `*`, for example, `prefixType/*`, the matching is successful only when **w_type** contains `prefixType/`. + +- If the last character of **w_type** is the wildcard `*`, for example, `prefixType/*`, the matching is successful only when **s_type** contains `prefixType/`. + + \ No newline at end of file diff --git a/en/application-dev/application-models/extensionability-overview.md b/en/application-dev/application-models/extensionability-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..d85f02ace879e409a8d42d6f09408680a99f8056 --- /dev/null +++ b/en/application-dev/application-models/extensionability-overview.md @@ -0,0 +1,58 @@ +# ExtensionAbility Component Overview + + +The ExtensionAbility component is used for specific scenarios such as widgets and input methods. + + +An [ExtensionAbilityType](../reference/apis/js-apis-bundleManager.md#extensionabilitytype) is provided for every specific scenario. All types of ExtensionAbility components are managed by the corresponding system services in a unified manner. For example, the InputMethodExtensionAbility component is managed by the input method management service. The following ExtensionAbility types are supported: + + +- [FormExtensionAbility](../reference/apis/js-apis-app-form-formExtensionAbility.md): ExtensionAbility component of the form type, which provides APIs related to widgets. + +- [WorkSchedulerExtensionAbility](../reference/apis/js-apis-resourceschedule-workScheduler.md): ExtensionAbility component of the work_scheduler type, which provides APIs for registering, canceling, and querying Work Scheduler tasks. + +- [InputMethodExtensionAbility](../reference/apis/js-apis-inputmethod.md): ExtensionAbility component of the input_method type, which provides an input method framework that can be used to hide the keyboard, obtain the list of installed input methods, display the dialog box for input method selection, and more. + +- [ServiceExtensionAbility](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md): ExtensionAbility component of the service type, which provides APIs related to background service scenarios. + +- [AccessibilityExtensionAbility](../reference/apis/js-apis-application-accessibilityExtensionAbility.md): ExtensionAbility component of the accessibility type, which provides APIs related to the accessibility feature. + +- [DataShareExtensionAbility](../reference/apis/js-apis-application-dataShareExtensionAbility.md): ExtensionAbility component of the data_share type, which provides APIs for data sharing. + +- [StaticSubscriberExtensionAbility](../reference/apis/js-apis-application-staticSubscriberExtensionAbility.md): ExtensionAbility component of the static_subscriber type, which provides APIs for static broadcast. + +- [WindowExtensionAbility](../reference/apis/js-apis-application-windowExtensionAbility.md): ExtensionAbility component of the window type, which allows system applications to display UIs of other applications. + +- [EnterpriseAdminExtensionAbility](../reference/apis/js-apis-EnterpriseAdminExtensionAbility.md): ExtensionAbility component of the enterprise_admin type, which provides APIs for processing enterprise management events, such as application installation events on devices and events indicating too many incorrect screen-lock password attempts. + + +## Using ExtensionAbility of the Specified Type + +All types of ExtensionAbility components are started by the corresponding system management service, rather than applications, so that their lifecycles are under control by the system. The caller of the ExtensionAbility component does not need to care about its lifecycle. + +The following uses [InputMethodExtensionAbility](../reference/apis/js-apis-inputmethod.md) as an example. As shown in the figure below, when an application calls the InputMethodExtensionAbility component, the input method management service is called first. The input method management service starts the InputMethodExtensionAbility component, returns the component to the application, and starts to manage its lifecycle. + +**Figure 1** Using the InputMethodExtensionAbility component +![ExtensionAbility-start](figures/ExtensionAbility-start.png) + + +## Implementing ExtensionAbility of the Specified Type + +The following uses [FormExtensionAbility](../reference/apis/js-apis-app-form-formExtensionAbility.md) as an example. The widget framework provides the base class [FormExtensionAbility](../reference/apis/js-apis-app-form-formExtensionAbility.md). You derive this base class to create your own class (such as **MyFormExtensionAbility**), implement the callbacks, such as **onCreate()** and **onUpdateForm()**, to provide specific widget functionalities. For details, see [FormExtensionAbility](Widget-development-stage.md). + +You do not need to care when to add or delete a widget. The lifecycle of the FormExtensionAbility instance and the lifecycle of the ExtensionAbility process where the FormExtensionAbility instance is located are scheduled and managed by FormManagerService. + +![form_extension](figures/form_extension.png) + + +> **NOTE** +> +> For an application, all ExtensionAbility components of the same type run in an independent process, whereas UIAbility, ServiceExtensionAbility, and DataShareExtensionAbility run in another independent process. For details, see [Process Model (Stage Model)](process-model-stage.md). +> +> For example, an application has one UIAbility component, one ServiceExtensionAbility, one DataShareExtensionAbility, two FormExtensionAbility, and one ImeExtensionAbility. When the application is running, there are three processes: +> +> - UIAbility, ServiceExtensionAbility, and DataShareExtensionAbility run in an independent process. +> +> - The two FormExtensionAbility components run in an independent process. +> +> - The two ImeExtensionAbility components run in an independent process. diff --git a/en/application-dev/application-models/fa-model-development-overview.md b/en/application-dev/application-models/fa-model-development-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..07e7ef8a0bdaea927762c15e4123ae728c026cb7 --- /dev/null +++ b/en/application-dev/application-models/fa-model-development-overview.md @@ -0,0 +1,15 @@ +# FA Model Development Overview + + +During application development based on the Feature Ability (FA) model, the following tasks are involved in the application model. + + + **Table 1** FA model development process + +| Task| Introduction| Guide| +| -------- | -------- | -------- | +| Application component development| Use the PageAbility, ServiceAbility, DataAbility, and widgets of the FA model to develop applications.| - [Application- or Component-Level Configuration](application-component-configuration-fa.md)
- [PageAbility Component](pageability-overview.md)
- [ServiceAbility Component](serviceability-overview.md)
- [DataAbility Component](dataability-overview.md)
- [Widget Development](Widget-development-fa.md)
- [Context](application-context-fa.md)
- [Want](want-fa.md) | +| Inter-process communication (IPC)| Learn the process model and common IPC modes of the FA model.| [Common Events](common-event-fa.md)
[Background Services](rpc.md) | +| Inter-thread communication| Learn the thread model and common inter-thread communication modes of the FA model.| [Inter-Thread Communication](itc-fa-overview.md)| +| Mission management| Learn the basic concepts and typical scenarios of mission management in the FA model.| [Mission Management](mission-management-fa.md)| +| Application configuration file| Learn the requirements for developing application configuration files in the FA model.| [Application Configuration File](config-file-fa.md) | diff --git a/en/application-dev/application-models/fa-stage-interaction-overview.md b/en/application-dev/application-models/fa-stage-interaction-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..0d1ed27f0df2d4964b0d69faf48afcb42e32bf91 --- /dev/null +++ b/en/application-dev/application-models/fa-stage-interaction-overview.md @@ -0,0 +1,25 @@ +# Component Interaction Between the FA Model and Stage Model + + +The FA model is supported by API version 8 and earlier versions, and the stage model is recommended since API version 9. The FA model and stage model have their respective components. The FA model provides three types of application components: PageAbility, ServiceAbility, and DataAbility. The stage model provides two types of application components: UIAbility and ExtensionAbility. + + +You cannot use both models for the development of an application (see the figure below). However, a device (system) can contain applications developed on both models (scenario 3 in the figure below). In this case, their components may interact with each other. + +Figure 1 Coexistent application components of the FA model and stage model +![coexistence-of-FAandStage](figures/coexistence-of-FAandStage.png) + + +The following table lists the possible interaction scenarios. You must pay attention to the concerns listed below during your application development. + + +Table 1 Application component interaction scenarios + +| Interaction Scenario| Concerns| +| -------- | -------- | +| [Starting a UIAbility from the FA Model](start-uiability-from-fa.md) | Set **bundleName** and **abilityName** in the **want** parameter to the bundle name and ability name of the UIAbility in the stage model.| +| [Connecting to a ServiceExtensionAbility from the FA Model](bind-serviceextensionability-from-fa.md) | Set **bundleName** and **abilityName** in the **want** parameter to the bundle name and ability name of the ServiceExtensionAbility in the stage model.| +| [Accessing a DataShareExtensionAbility from the FA Model](access-datashareextensionability-from-fa.md) | No code modification is required. However, you need to understand the API compatibility of **DataShareHelper** and **DataAbilityHelper**.| +| [Starting a PageAbility from the Stage Model](start-pageability-from-stage.md) | Set **bundleName** and **abilityName** in the **want** parameter to the bundle name and ability name of the PageAbility in the FA model.| +| [Connecting to a ServiceAbility from the Stage Model](bind-serviceability-from-stage.md) | Set **bundleName** and **abilityName** in the **want** parameter to the bundle name and ability name of the ServiceAbility in the FA model.| +| Accessing a DataAbility from the Stage Model | This type of access is not supported.| diff --git a/en/application-dev/application-models/featureability-switch.md b/en/application-dev/application-models/featureability-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..f7db8056ea156650e11b55a78137de194ce9d43f --- /dev/null +++ b/en/application-dev/application-models/featureability-switch.md @@ -0,0 +1,16 @@ +# featureAbility Switching + + +| API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API in the Stage Model| +| -------- | -------- | -------- | +| [getWant(callback: AsyncCallback<Want>): void;](../reference/apis/js-apis-ability-featureAbility.md#featureabilitygetwant)
[getWant(): Promise<Want>;](../reference/apis/js-apis-ability-featureAbility.md#featureabilitygetwant-1) | \@ohos.app.ability.UIAbility.d.ts | [launchWant: Want;](../reference/apis/js-apis-app-ability-uiAbility.md#attributes)| +| [startAbility(parameter: StartAbilityParameter, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-ability-featureAbility.md#featureabilitystartability)
[startAbility(parameter: StartAbilityParameter): Promise<number>;](../reference/apis/js-apis-ability-featureAbility.md#featureabilitystartability-1) | application\UIAbilityContext.d.ts | [startAbility(want: Want, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartability)
[startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartability-1)
[startAbility(want: Want, options?: StartOptions): Promise<void>;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartability-2) | +| [getContext(): Context;](../reference/apis/js-apis-ability-featureAbility.md#featureabilitygetcontext) | \@ohos.app.ability.UIAbility.d.ts | [context: UIAbilityContext;](../reference/apis/js-apis-app-ability-uiAbility.md#attributes)| +| [startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback<AbilityResult>): void;](../reference/apis/js-apis-ability-featureAbility.md#featureabilitystartabilityforresult7)
[startAbilityForResult(parameter: StartAbilityParameter): Promise<AbilityResult>;](../reference/apis/js-apis-ability-featureAbility.md#featureabilitystartabilityforresult7-1) | application\UIAbilityContext.d.ts | [startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartabilityforresult)
[startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): void;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartabilityforresult-1)
[startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult>;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartabilityforresult-2) | +| [terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-ability-featureAbility.md#featureabilityterminateselfwithresult7)
[terminateSelfWithResult(parameter: AbilityResult): Promise<void>;](../reference/apis/js-apis-ability-featureAbility.md#featureabilityterminateselfwithresult7-1) | application\UIAbilityContext.d.ts | [terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextterminateselfwithresult)
[terminateSelfWithResult(parameter: AbilityResult): Promise<void>;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextterminateselfwithresult-1) | +| [terminateSelf(callback: AsyncCallback<void>): void;](../reference/apis/js-apis-ability-featureAbility.md#featureabilityterminateself7)
[terminateSelf(): Promise<void>;](../reference/apis/js-apis-ability-featureAbility.md#featureabilityterminateself7-1) | application\UIAbilityContext.d.ts | [terminateSelf(callback: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextterminateself)
[terminateSelf(): Promise<void>;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextterminateself-1) | +| [acquireDataAbilityHelper(uri: string): DataAbilityHelper;](../reference/apis/js-apis-ability-featureAbility.md#featureabilityacquiredataabilityhelper7) | \@ohos.data.dataShare.d.ts
\@ohos.data.fileAccess.d.ts | [createDataShareHelper(context: Context, uri: string, callback: AsyncCallback<DataShareHelper>): void;](../reference/apis/js-apis-data-dataShare.md#datasharecreatedatasharehelper)
[createDataShareHelper(context: Context, uri: string): Promise<DataShareHelper>;](../reference/apis/js-apis-data-dataShare.md#datasharecreatedatasharehelper-1)
[createFileAccessHelper(context: Context): FileAccessHelper;](../reference/apis/js-apis-fileAccess.md#fileaccesscreatefileaccesshelper-1)
[createFileAccessHelper(context: Context, wants: Array<Want>): FileAccessHelper;](../reference/apis/js-apis-fileAccess.md#fileaccesscreatefileaccesshelper) | +| [hasWindowFocus(callback: AsyncCallback<boolean>): void;](../reference/apis/js-apis-ability-featureAbility.md#featureabilityhaswindowfocus7)
[hasWindowFocus(): Promise<boolean>;](../reference/apis/js-apis-ability-featureAbility.md#featureabilityhaswindowfocus7-1) | \@ohos.window.d.ts | [on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void;](../reference/apis/js-apis-window.md#onwindowstageevent9)
Checks whether the [active window](../reference/apis/js-apis-window.md#windowstageeventtype9) has the focus.| +| [connectAbility(request: Want, options:ConnectOptions ): number;](../reference/apis/js-apis-ability-featureAbility.md#featureabilityconnectability7) | application\UIAbilityContext.d.ts | [connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextconnectserviceextensionability) | +| [disconnectAbility(connection: number, callback:AsyncCallback<void>): void;](../reference/apis/js-apis-ability-featureAbility.md#featureabilitydisconnectability7)
[disconnectAbility(connection: number): Promise<void>;](../reference/apis/js-apis-ability-featureAbility.md#featureabilitydisconnectability7-1) | application\UIAbilityContext.d.ts | [disconnectAbility(connection: number, callback:AsyncCallback<void>): void;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextdisconnectserviceextensionability-1)
[disconnectAbility(connection: number): Promise<void>;](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextdisconnectserviceextensionability) | +| [getWindow(callback: AsyncCallback<window.Window>): void;](../reference/apis/js-apis-ability-featureAbility.md#featureabilitygetwindow7)
[getWindow(): Promise<window.Window>;](../reference/apis/js-apis-ability-featureAbility.md#featureabilitygetwindow7-1) | \@ohos.window.d.ts | [getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void;](../reference/apis/js-apis-window.md#windowgetlastwindow9)
[getLastWindow(ctx: BaseContext): Promise<Window>;](../reference/apis/js-apis-window.md#windowgetlastwindow9-1) | diff --git a/en/application-dev/application-models/figures/Ability-Life-Cycle-WindowStage.png b/en/application-dev/application-models/figures/Ability-Life-Cycle-WindowStage.png new file mode 100644 index 0000000000000000000000000000000000000000..e140763dfda32a5ad168e8a6daa38a9c51baf147 Binary files /dev/null and b/en/application-dev/application-models/figures/Ability-Life-Cycle-WindowStage.png differ diff --git a/en/application-dev/application-models/figures/Ability-Life-Cycle.png b/en/application-dev/application-models/figures/Ability-Life-Cycle.png new file mode 100644 index 0000000000000000000000000000000000000000..cc0681f5f2678ca15008d7b98d7ddc34d20dcf83 Binary files /dev/null and b/en/application-dev/application-models/figures/Ability-Life-Cycle.png differ diff --git a/en/application-dev/application-models/figures/ExtensionAbility-start.png b/en/application-dev/application-models/figures/ExtensionAbility-start.png new file mode 100644 index 0000000000000000000000000000000000000000..3bd844f462199d5b7792cc5229fa763eb851a2d3 Binary files /dev/null and b/en/application-dev/application-models/figures/ExtensionAbility-start.png differ diff --git a/en/application-dev/application-models/figures/FAvsStage-uri.png b/en/application-dev/application-models/figures/FAvsStage-uri.png new file mode 100644 index 0000000000000000000000000000000000000000..132c1ba0f09f7da7344d6edcfae3c59fe355e7f9 Binary files /dev/null and b/en/application-dev/application-models/figures/FAvsStage-uri.png differ diff --git a/en/application-dev/application-models/figures/ServiceExtensionAbility-lifecycle.png b/en/application-dev/application-models/figures/ServiceExtensionAbility-lifecycle.png new file mode 100644 index 0000000000000000000000000000000000000000..fd3a15c8b1588e19d88938b39dbbc12b98d3c723 Binary files /dev/null and b/en/application-dev/application-models/figures/ServiceExtensionAbility-lifecycle.png differ diff --git a/en/application-dev/application-models/figures/api-switch-overview.png b/en/application-dev/application-models/figures/api-switch-overview.png new file mode 100644 index 0000000000000000000000000000000000000000..c17f5d3deb13d9c2d31d1b1d8b8569c7bc842676 Binary files /dev/null and b/en/application-dev/application-models/figures/api-switch-overview.png differ diff --git a/en/application-dev/application-models/figures/application-component-configuration-stage.png b/en/application-dev/application-models/figures/application-component-configuration-stage.png new file mode 100644 index 0000000000000000000000000000000000000000..8957b1b4a85a7bdc8d0d9ab422d7cf379ae6cf75 Binary files /dev/null and b/en/application-dev/application-models/figures/application-component-configuration-stage.png differ diff --git a/en/application-dev/application-models/figures/application-context-stage.png b/en/application-dev/application-models/figures/application-context-stage.png new file mode 100644 index 0000000000000000000000000000000000000000..9423fd5f99deb310315c13173422cb050d93fbb7 Binary files /dev/null and b/en/application-dev/application-models/figures/application-context-stage.png differ diff --git a/en/application-dev/application-models/figures/call.png b/en/application-dev/application-models/figures/call.png new file mode 100644 index 0000000000000000000000000000000000000000..5a374f942e7754fa7b4e9303c89ee53d4ff8ee2b Binary files /dev/null and b/en/application-dev/application-models/figures/call.png differ diff --git a/en/application-dev/application-models/figures/coexistence-of-FAandStage.png b/en/application-dev/application-models/figures/coexistence-of-FAandStage.png new file mode 100644 index 0000000000000000000000000000000000000000..02e09b48b3f146371ddb6acac7e4a259be4448fb Binary files /dev/null and b/en/application-dev/application-models/figures/coexistence-of-FAandStage.png differ diff --git a/en/application-dev/application-models/figures/common-event.png b/en/application-dev/application-models/figures/common-event.png new file mode 100644 index 0000000000000000000000000000000000000000..24b51ff8718ae504ba69c1e12656d4daad797a62 Binary files /dev/null and b/en/application-dev/application-models/figures/common-event.png differ diff --git a/en/application-dev/application-models/figures/comparison-of-configuration-file.png b/en/application-dev/application-models/figures/comparison-of-configuration-file.png new file mode 100644 index 0000000000000000000000000000000000000000..e0a2b47835f7814511049807f8582c50057bb459 Binary files /dev/null and b/en/application-dev/application-models/figures/comparison-of-configuration-file.png differ diff --git a/en/application-dev/application-models/figures/component-startup-inner-fa.png b/en/application-dev/application-models/figures/component-startup-inner-fa.png new file mode 100644 index 0000000000000000000000000000000000000000..f6ed21c09d9ae0d409a180885c172918a123c728 Binary files /dev/null and b/en/application-dev/application-models/figures/component-startup-inner-fa.png differ diff --git a/en/application-dev/application-models/figures/component-startup-inner-stage.png b/en/application-dev/application-models/figures/component-startup-inner-stage.png new file mode 100644 index 0000000000000000000000000000000000000000..00514276f4ac3eb8ead650e5858cebb0a344d2c6 Binary files /dev/null and b/en/application-dev/application-models/figures/component-startup-inner-stage.png differ diff --git a/en/application-dev/application-models/figures/component-startup-inter-fa.png b/en/application-dev/application-models/figures/component-startup-inter-fa.png new file mode 100644 index 0000000000000000000000000000000000000000..2d50fb61e502ae2d2af917931d579ca2404d19b0 Binary files /dev/null and b/en/application-dev/application-models/figures/component-startup-inter-fa.png differ diff --git a/en/application-dev/application-models/figures/component-startup-inter-stage.png b/en/application-dev/application-models/figures/component-startup-inter-stage.png new file mode 100644 index 0000000000000000000000000000000000000000..a6f79e6803edc160e5570729456569f46cc80967 Binary files /dev/null and b/en/application-dev/application-models/figures/component-startup-inter-stage.png differ diff --git a/en/application-dev/application-models/figures/context-dir.png b/en/application-dev/application-models/figures/context-dir.png new file mode 100644 index 0000000000000000000000000000000000000000..f16b56b43fbd0f493a10acecfb9b1edb79b2421f Binary files /dev/null and b/en/application-dev/application-models/figures/context-dir.png differ diff --git a/en/application-dev/application-models/figures/context-holding.png b/en/application-dev/application-models/figures/context-holding.png new file mode 100644 index 0000000000000000000000000000000000000000..fe4fbd4a4dff7024e3d5d35bd46d304d23e1f8c9 Binary files /dev/null and b/en/application-dev/application-models/figures/context-holding.png differ diff --git a/en/application-dev/application-models/figures/context-inheritance.png b/en/application-dev/application-models/figures/context-inheritance.png new file mode 100644 index 0000000000000000000000000000000000000000..2619daca03187d58db5b3690734704c66fb70d06 Binary files /dev/null and b/en/application-dev/application-models/figures/context-inheritance.png differ diff --git a/en/application-dev/application-models/figures/fa-dataability-uri.png b/en/application-dev/application-models/figures/fa-dataability-uri.png new file mode 100644 index 0000000000000000000000000000000000000000..d89ada0ee9b2f9f655a6c3d8b0df17d6b1ca9326 Binary files /dev/null and b/en/application-dev/application-models/figures/fa-dataability-uri.png differ diff --git a/en/application-dev/application-models/figures/fa-pageAbility-lifecycle.png b/en/application-dev/application-models/figures/fa-pageAbility-lifecycle.png new file mode 100644 index 0000000000000000000000000000000000000000..59a06741053c85cab6ea90b41bd16a6f2e1ff508 Binary files /dev/null and b/en/application-dev/application-models/figures/fa-pageAbility-lifecycle.png differ diff --git a/en/application-dev/application-models/figures/form-extension.png b/en/application-dev/application-models/figures/form-extension.png new file mode 100644 index 0000000000000000000000000000000000000000..ce47308856c4d41baff5dbaefdcefe9561b383b7 Binary files /dev/null and b/en/application-dev/application-models/figures/form-extension.png differ diff --git a/en/application-dev/application-models/figures/form_extension.png b/en/application-dev/application-models/figures/form_extension.png new file mode 100644 index 0000000000000000000000000000000000000000..daf36c75dae010492fa57ac05c85eaed58fbe00c Binary files /dev/null and b/en/application-dev/application-models/figures/form_extension.png differ diff --git a/en/application-dev/application-models/figures/globalThis1.png b/en/application-dev/application-models/figures/globalThis1.png new file mode 100644 index 0000000000000000000000000000000000000000..128f79d3437304845ac822d32377dab4cf0c9e05 Binary files /dev/null and b/en/application-dev/application-models/figures/globalThis1.png differ diff --git a/en/application-dev/application-models/figures/globalThis2.png b/en/application-dev/application-models/figures/globalThis2.png new file mode 100644 index 0000000000000000000000000000000000000000..11e015286489df52d5b9cd3ed35a564223b7ab4c Binary files /dev/null and b/en/application-dev/application-models/figures/globalThis2.png differ diff --git a/en/application-dev/application-models/figures/hop-cross-device-migration.png b/en/application-dev/application-models/figures/hop-cross-device-migration.png new file mode 100644 index 0000000000000000000000000000000000000000..1623bc94af414539f6634aea6d583e205eccf409 Binary files /dev/null and b/en/application-dev/application-models/figures/hop-cross-device-migration.png differ diff --git a/en/application-dev/application-models/figures/hop-multi-device-collaboration.png b/en/application-dev/application-models/figures/hop-multi-device-collaboration.png new file mode 100644 index 0000000000000000000000000000000000000000..28fa0a6e269a4266236898e19ce7bca4e670027d Binary files /dev/null and b/en/application-dev/application-models/figures/hop-multi-device-collaboration.png differ diff --git a/en/application-dev/application-models/figures/hop-structure.png b/en/application-dev/application-models/figures/hop-structure.png new file mode 100644 index 0000000000000000000000000000000000000000..96b82de856fcbc7db6d7668791a668ec152141fc Binary files /dev/null and b/en/application-dev/application-models/figures/hop-structure.png differ diff --git a/en/application-dev/application-models/figures/mission-and-singleton.png b/en/application-dev/application-models/figures/mission-and-singleton.png new file mode 100644 index 0000000000000000000000000000000000000000..eee0a39644d7080e9f9f26f30b184d679a5bff3c Binary files /dev/null and b/en/application-dev/application-models/figures/mission-and-singleton.png differ diff --git a/en/application-dev/application-models/figures/mission-and-specified.png b/en/application-dev/application-models/figures/mission-and-specified.png new file mode 100644 index 0000000000000000000000000000000000000000..6af8c28d4277b3582fed2cfc313cc301086e6314 Binary files /dev/null and b/en/application-dev/application-models/figures/mission-and-specified.png differ diff --git a/en/application-dev/application-models/figures/mission-and-standard.png b/en/application-dev/application-models/figures/mission-and-standard.png new file mode 100644 index 0000000000000000000000000000000000000000..feeed48f41371bf22abbee8dbae4695b11ed2514 Binary files /dev/null and b/en/application-dev/application-models/figures/mission-and-standard.png differ diff --git a/en/application-dev/application-models/figures/mission-chain1.png b/en/application-dev/application-models/figures/mission-chain1.png new file mode 100644 index 0000000000000000000000000000000000000000..6b9ce7dd3c74b26e0dd8d1b12e00d6414e3cdadb Binary files /dev/null and b/en/application-dev/application-models/figures/mission-chain1.png differ diff --git a/en/application-dev/application-models/figures/mission-chain2.png b/en/application-dev/application-models/figures/mission-chain2.png new file mode 100644 index 0000000000000000000000000000000000000000..7ed2b6f0052a08445c53ec2882a7f474fa5a4763 Binary files /dev/null and b/en/application-dev/application-models/figures/mission-chain2.png differ diff --git a/en/application-dev/application-models/figures/mission-chain3.png b/en/application-dev/application-models/figures/mission-chain3.png new file mode 100644 index 0000000000000000000000000000000000000000..e02c135ad4a90f99bb65bdccd821d29990b9536e Binary files /dev/null and b/en/application-dev/application-models/figures/mission-chain3.png differ diff --git a/en/application-dev/application-models/figures/mission-list-manager.png b/en/application-dev/application-models/figures/mission-list-manager.png new file mode 100644 index 0000000000000000000000000000000000000000..792745f100e6ba3613c3a496421b00bbb5f6db8f Binary files /dev/null and b/en/application-dev/application-models/figures/mission-list-manager.png differ diff --git a/en/application-dev/application-models/figures/mission-record.png b/en/application-dev/application-models/figures/mission-record.png new file mode 100644 index 0000000000000000000000000000000000000000..77f9c156d83876524977a139308046a6acfed711 Binary files /dev/null and b/en/application-dev/application-models/figures/mission-record.png differ diff --git a/en/application-dev/application-models/figures/model-switch-overview1.png b/en/application-dev/application-models/figures/model-switch-overview1.png new file mode 100644 index 0000000000000000000000000000000000000000..e9d8a120dedcda4f27f5f92e52c826b900a105d9 Binary files /dev/null and b/en/application-dev/application-models/figures/model-switch-overview1.png differ diff --git a/en/application-dev/application-models/figures/model-switch-overview2.png b/en/application-dev/application-models/figures/model-switch-overview2.png new file mode 100644 index 0000000000000000000000000000000000000000..522656745c55d165208be94b23d264c334421722 Binary files /dev/null and b/en/application-dev/application-models/figures/model-switch-overview2.png differ diff --git a/en/application-dev/application-models/figures/model-switch-overview3.png b/en/application-dev/application-models/figures/model-switch-overview3.png new file mode 100644 index 0000000000000000000000000000000000000000..e7fe19489d38bf971619dbb41294c5287377b8dc Binary files /dev/null and b/en/application-dev/application-models/figures/model-switch-overview3.png differ diff --git a/en/application-dev/application-models/figures/model-switch-overview4.png b/en/application-dev/application-models/figures/model-switch-overview4.png new file mode 100644 index 0000000000000000000000000000000000000000..e455ae9333e73b0898d6dd1700e79cbe529b7163 Binary files /dev/null and b/en/application-dev/application-models/figures/model-switch-overview4.png differ diff --git a/en/application-dev/application-models/figures/model-switch-overview5.png b/en/application-dev/application-models/figures/model-switch-overview5.png new file mode 100644 index 0000000000000000000000000000000000000000..82d5dbc6fee5b3b393e0a1abd8f4e7fbbeb0c4ac Binary files /dev/null and b/en/application-dev/application-models/figures/model-switch-overview5.png differ diff --git a/en/application-dev/application-models/figures/model-switch-overview6.png b/en/application-dev/application-models/figures/model-switch-overview6.png new file mode 100644 index 0000000000000000000000000000000000000000..c17f5d3deb13d9c2d31d1b1d8b8569c7bc842676 Binary files /dev/null and b/en/application-dev/application-models/figures/model-switch-overview6.png differ diff --git a/en/application-dev/application-models/figures/multi-process.png b/en/application-dev/application-models/figures/multi-process.png new file mode 100644 index 0000000000000000000000000000000000000000..55ab9a514c3fd1136747efc1bbb80ec900891bce Binary files /dev/null and b/en/application-dev/application-models/figures/multi-process.png differ diff --git a/en/application-dev/application-models/figures/page-ability-lifecycle.png b/en/application-dev/application-models/figures/page-ability-lifecycle.png new file mode 100644 index 0000000000000000000000000000000000000000..b35954967bb9c733725da2f0700481932619ae45 Binary files /dev/null and b/en/application-dev/application-models/figures/page-ability-lifecycle.png differ diff --git a/en/application-dev/application-models/figures/pageability-switch.png b/en/application-dev/application-models/figures/pageability-switch.png new file mode 100644 index 0000000000000000000000000000000000000000..4b68d46e529715a7258eb295bef1648da0b8ebbd Binary files /dev/null and b/en/application-dev/application-models/figures/pageability-switch.png differ diff --git a/en/application-dev/application-models/figures/process-model-fa.png b/en/application-dev/application-models/figures/process-model-fa.png new file mode 100644 index 0000000000000000000000000000000000000000..2a71de2389970a63d0a9dc2ec7d3c5b44e58a9ca Binary files /dev/null and b/en/application-dev/application-models/figures/process-model-fa.png differ diff --git a/en/application-dev/application-models/figures/process-model.png b/en/application-dev/application-models/figures/process-model.png new file mode 100644 index 0000000000000000000000000000000000000000..f6f3b22381539ac73371b4c7f6025a5c3127838b Binary files /dev/null and b/en/application-dev/application-models/figures/process-model.png differ diff --git a/en/application-dev/application-models/figures/stage-concepts.png b/en/application-dev/application-models/figures/stage-concepts.png new file mode 100644 index 0000000000000000000000000000000000000000..42e99447a780b167adaf6ddd196bea4437dfa1a7 Binary files /dev/null and b/en/application-dev/application-models/figures/stage-concepts.png differ diff --git a/en/application-dev/application-models/figures/stage-want1.png b/en/application-dev/application-models/figures/stage-want1.png new file mode 100644 index 0000000000000000000000000000000000000000..09ebc69170dca547c7b965dbf62c1a4df978815f Binary files /dev/null and b/en/application-dev/application-models/figures/stage-want1.png differ diff --git a/en/application-dev/application-models/figures/stage-want2.png b/en/application-dev/application-models/figures/stage-want2.png new file mode 100644 index 0000000000000000000000000000000000000000..3c5358cb3d98f8b519369f8ecce1964fd02c3d58 Binary files /dev/null and b/en/application-dev/application-models/figures/stage-want2.png differ diff --git a/en/application-dev/application-models/figures/standard-mode.png b/en/application-dev/application-models/figures/standard-mode.png new file mode 100644 index 0000000000000000000000000000000000000000..fc903e6c1be80d3c00281d00d9ab0a1e334d7724 Binary files /dev/null and b/en/application-dev/application-models/figures/standard-mode.png differ diff --git a/en/application-dev/application-models/figures/startAbilityWtExplicitWant.PNG b/en/application-dev/application-models/figures/startAbilityWtExplicitWant.PNG new file mode 100644 index 0000000000000000000000000000000000000000..1d9e25f148d08a58a0ac45b703e08072f52fc300 Binary files /dev/null and b/en/application-dev/application-models/figures/startAbilityWtExplicitWant.PNG differ diff --git a/en/application-dev/application-models/figures/thread-model-stage.png b/en/application-dev/application-models/figures/thread-model-stage.png new file mode 100644 index 0000000000000000000000000000000000000000..eb407a10616ce3eb1584f81ad80c4f29a7e95c10 Binary files /dev/null and b/en/application-dev/application-models/figures/thread-model-stage.png differ diff --git a/en/application-dev/application-models/figures/uiability-intra-device-interaction.png b/en/application-dev/application-models/figures/uiability-intra-device-interaction.png new file mode 100644 index 0000000000000000000000000000000000000000..59a0110cfc0b36780adb0a936af34588fcfdeb1a Binary files /dev/null and b/en/application-dev/application-models/figures/uiability-intra-device-interaction.png differ diff --git a/en/application-dev/application-models/figures/uiability-launch-type1.png b/en/application-dev/application-models/figures/uiability-launch-type1.png new file mode 100644 index 0000000000000000000000000000000000000000..c4f5aa4b9a988d8e7148b504c4dcc163961cb103 Binary files /dev/null and b/en/application-dev/application-models/figures/uiability-launch-type1.png differ diff --git a/en/application-dev/application-models/figures/uiability-launch-type2.png b/en/application-dev/application-models/figures/uiability-launch-type2.png new file mode 100644 index 0000000000000000000000000000000000000000..6f0e43d24f745aee41601cc48f4bc138572fbeb5 Binary files /dev/null and b/en/application-dev/application-models/figures/uiability-launch-type2.png differ diff --git a/en/application-dev/application-models/figures/uiability_not_first_started.png b/en/application-dev/application-models/figures/uiability_not_first_started.png new file mode 100644 index 0000000000000000000000000000000000000000..5cff262167ce720b736d6ea554f2355efa0c928e Binary files /dev/null and b/en/application-dev/application-models/figures/uiability_not_first_started.png differ diff --git a/en/application-dev/application-models/figures/usage-of-want.png b/en/application-dev/application-models/figures/usage-of-want.png new file mode 100644 index 0000000000000000000000000000000000000000..86b41b256ee8358c0fa87899b18ae249d28668c7 Binary files /dev/null and b/en/application-dev/application-models/figures/usage-of-want.png differ diff --git a/en/application-dev/application-models/figures/want-action.png b/en/application-dev/application-models/figures/want-action.png new file mode 100644 index 0000000000000000000000000000000000000000..0d8e18ce5870bea777c26b832d3f29674c2fa261 Binary files /dev/null and b/en/application-dev/application-models/figures/want-action.png differ diff --git a/en/application-dev/application-models/figures/want-entities.png b/en/application-dev/application-models/figures/want-entities.png new file mode 100644 index 0000000000000000000000000000000000000000..bf1b85594f1d34c966c061574f6bf6c3cb75bf2f Binary files /dev/null and b/en/application-dev/application-models/figures/want-entities.png differ diff --git a/en/application-dev/application-models/figures/want-uri-type1.png b/en/application-dev/application-models/figures/want-uri-type1.png new file mode 100644 index 0000000000000000000000000000000000000000..e0fe40d1a3cd40b72379bd947aaf2e3977021b32 Binary files /dev/null and b/en/application-dev/application-models/figures/want-uri-type1.png differ diff --git a/en/application-dev/application-models/figures/want-uri-type2.png b/en/application-dev/application-models/figures/want-uri-type2.png new file mode 100644 index 0000000000000000000000000000000000000000..9a64d865066e381536a268023918975e783ddf5e Binary files /dev/null and b/en/application-dev/application-models/figures/want-uri-type2.png differ diff --git a/en/application-dev/application-models/figures/widget-development-fa.png b/en/application-dev/application-models/figures/widget-development-fa.png new file mode 100644 index 0000000000000000000000000000000000000000..795e96171e6d890e72a09382906302dd0fa45fab Binary files /dev/null and b/en/application-dev/application-models/figures/widget-development-fa.png differ diff --git a/en/application-dev/application-models/figures/widget-development-stage.png b/en/application-dev/application-models/figures/widget-development-stage.png new file mode 100644 index 0000000000000000000000000000000000000000..795e96171e6d890e72a09382906302dd0fa45fab Binary files /dev/null and b/en/application-dev/application-models/figures/widget-development-stage.png differ diff --git a/en/application-dev/application-models/figures/widget-switch1.png b/en/application-dev/application-models/figures/widget-switch1.png new file mode 100644 index 0000000000000000000000000000000000000000..71aaf2e41cdf012820c121e5bf538b8c5b8b0784 Binary files /dev/null and b/en/application-dev/application-models/figures/widget-switch1.png differ diff --git a/en/application-dev/application-models/figures/widget-switch2.png b/en/application-dev/application-models/figures/widget-switch2.png new file mode 100644 index 0000000000000000000000000000000000000000..230836fd2c992de1d434e506bf48ff7876f1a5e8 Binary files /dev/null and b/en/application-dev/application-models/figures/widget-switch2.png differ diff --git a/en/application-dev/application-models/figures/widget-switch3.png b/en/application-dev/application-models/figures/widget-switch3.png new file mode 100644 index 0000000000000000000000000000000000000000..1e62fb7ca3be5fa73fb11d809d929b319ce05666 Binary files /dev/null and b/en/application-dev/application-models/figures/widget-switch3.png differ diff --git a/en/application-dev/application-models/figures/widget-switch4.png b/en/application-dev/application-models/figures/widget-switch4.png new file mode 100644 index 0000000000000000000000000000000000000000..65a63969a29dbf9c108618a9ea02db201ec3307d Binary files /dev/null and b/en/application-dev/application-models/figures/widget-switch4.png differ diff --git a/en/application-dev/application-models/hop-cross-device-migration.md b/en/application-dev/application-models/hop-cross-device-migration.md new file mode 100644 index 0000000000000000000000000000000000000000..6d30435a819da49855cf9ae818bac419a1c0b614 --- /dev/null +++ b/en/application-dev/application-models/hop-cross-device-migration.md @@ -0,0 +1,151 @@ +# Cross-Device Migration + + +## When to Use + +Cross-device migration is available only for system applications. The main task is to migrate the current task (including the page control status) of an application to the target device so that the task can continue on it. Cross-device migration supports the following functionalities: + +- Storage and restoration of custom data + +- Storage and restoration of page routing information and page control status data + +- Application compatibility detection + + +## Cross-Device Migration Process + +The following figure shows the cross-device migration process. + +**Figure 1** Cross-device migration process +![hop-cross-device-migration](figures/hop-cross-device-migration.png) + + +## Constraints + +- Since cross-device migration task management is not available, you can only develop applications that support cross-device migration. Your application cannot initiate migration. + +- Cross-device migration can be performed between the same UIAbility component. In other words, the components must have the same **bundleName**, **abilityName**, and **signature**. + + +## Best Practices + +For better user experience, you are advised to use the **wantParam** parameter to transmit data smaller than 100 KB. + + +## Available APIs + +The table below describes the main APIs used for cross-device migration. For details, see [API Reference](../reference/apis/js-apis-app-ability-uiAbility.md). + +**Table 1** Cross-device migration APIs + +| **API**| Description| +| -------- | -------- | +| onContinue(wantParam : {[key: string]: any}): OnContinueResult | Called by the initiator to store the data required for migration and indicate whether the migration is accepted.
- **AGREE**: The migration is accepted.
- **REJECT**: The migration is rejected.
- **MISMATCH**: The version does not match.| +| onCreate(want: Want, param: AbilityConstant.LaunchParam): void; | Called by the target to restore the data and UI page in the multi-instance migration scenario.| +| onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void; | Called by the target to restore the data and UI page in the singleton migration scenario.| + + +## How to Develop + +1. Configure the data synchronization permission in the **module.json5** file. The sample code is as follows: + + ```json + { + "module": { + "requestPermissions":[ + { + "name" : "ohos.permission.DISTRIBUTED_DATASYNC", + } + ] + } + } + ``` + +2. Configure the fields related to cross-device migration in the configuration file. + - Configure the application to support migration. + + + Set the **continuable** field in the **module.json5** file to **true**. The default value is **false**. If this parameter is set to **false**, the application cannot be continued on the target device. + ```json + { + "module": { + // ... + "abilities": [ + { + // ... + "continuable": true, + } + ] + } + } + ``` + + - Configure the application launch type. For details, see [UIAbility Component Launch Type](uiability-launch-type.md). + +3. Request the data synchronization permission. The sample code for displaying a dialog box to request the permission is as follows: + + ```ts + requestPermission() { + let context = this.context + let permissions: Array = ['ohos.permission.DISTRIBUTED_DATASYNC'] + context.requestPermissionsFromUser(permissions).then((data) => { + console.info("Succeed to request permission from user with data: "+ JSON.stringify(data)) + }).catch((error) => { + console.info("Failed to request permission from user with error: "+ JSON.stringify(error)) + }) + } + ``` + +4. Implement [onContinue()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncontinue) in the UIAbility of the initiator. + + [onContinue()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncontinue) is called on the initiator. You can save the data in this method to implement application compatibility check and migration decision. + + - Saving migrated data: You can save the data to be migrated in key-value pairs in **wantParam**. + + - Checking application compatibility: You can obtain the version number of the target application from **wantParam** and check the compatibility between the target application and the current application. + + - Making a migration decision: You can determine whether to support the migration based on the return value of **onContinue()**. For details about the return value, see [Available APIs](#available-apis). + + The sample code is as follows: + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility'; + import AbilityConstant from '@ohos.app.ability.AbilityConstant'; + + onContinue(wantParam : {[key: string]: any}) { + console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`) + let workInput = AppStorage.Get('ContinueWork'); + // Set the user input data into wantParam. + wantParam["work"] = workInput // set user input data into want params + console.info(`onContinue input = ${wantParam["input"]}`); + return AbilityConstant.OnContinueResult.AGREE + } + ``` + +5. Implement **onCreate()** and **onNewWant()** in the UIAbility of the target application to implement data restoration. + - Implementation example of **onCreate** in the multi-instance scenario + - The target device determines whether the startup is **LaunchReason.CONTINUATION** based on **launchReason** in **onCreate()**. + - You can obtain the saved migration data from the **want** parameter. + - After data restoration is complete, call **restoreWindowStage()** to trigger page restoration. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility'; + import AbilityConstant from '@ohos.app.ability.AbilityConstant'; + import distributedObject from '@ohos.data.distributedDataObject'; + + export default class EntryAbility extends UIAbility { + storage : LocalStorage; + onCreate(want, launchParam) { + console.info(`EntryAbility onCreate ${AbilityConstant.LaunchReason.CONTINUATION}`) + if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) { + // Obtain the user data from the want parameter. + let workInput = want.parameters.work + console.info(`work input ${workInput}`) + AppStorage.SetOrCreate('ContinueWork', workInput) + this.storage = new LocalStorage(); + this.context.restoreWindowStage(this.storage); + } + } + } + ``` + - For a singleton ability, use **onNewWant()** to achieve the same implementation. diff --git a/en/application-dev/application-models/hop-multi-device-collaboration.md b/en/application-dev/application-models/hop-multi-device-collaboration.md new file mode 100644 index 0000000000000000000000000000000000000000..85d6403187331a40bb9ea6280a3129dfb0e84883 --- /dev/null +++ b/en/application-dev/application-models/hop-multi-device-collaboration.md @@ -0,0 +1,542 @@ +# Multi-device Collaboration + + +## When to Use + +Multi-device coordination is available only for system applications. It involves the following scenarios: + +- [Starting UIAbility and ServiceExtensionAbility Across Devices (No Data Returned)](#starting-uiability-and-serviceextensionability-across-devices-no-data-returned) + +- [Starting UIAbility Across Devices (Data Returned)](#starting-uiability-across-devices-data-returned) + +- [Connecting to ServiceExtensionAbility Across Devices](#connecting-to-serviceextensionability-across-devices) + +- [Using Cross-Device Ability Call](#using-cross-device-ability-call) + + +## Multi-Device Collaboration Process + +The figure below shows the multi-device collaboration process. + +**Figure 1** Multi-device collaboration process +![hop-multi-device-collaboration](figures/hop-multi-device-collaboration.png) + + +## Constraints + +- Since multi-device collaboration task management is not available, you can obtain the device list by developing system applications. Access to third-party applications is not supported. + +- Multi-device collaboration must comply with [Inter-Device Component Startup Rules](component-startup-rules.md#inter-device-component-startup-rules). + +- For better user experience, you are advised to use the **want** parameter to transmit data smaller than 100 KB. + + +## Starting UIAbility and ServiceExtensionAbility Across Devices (No Data Returned) + +On device A, touch the **Start** button provided by the initiator application to start a specified UIAbility on device B. + + +### Available APIs + +**Table 1** Cross-device startup APIs + +| **API**| **Description**| +| -------- | -------- | +| startAbility(want: Want, callback: AsyncCallback<void>): void; | Starts UIAbility and ServiceExtensionAbility. This API uses an asynchronous callback to return the result.| + + +### How to Develop + +1. Request the **ohos.permission.DISTRIBUTED_DATASYNC** permission. For details, see [Permission Application Guide](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file). + +2. Request the data synchronization permission. The sample code for displaying a dialog box to request the permission is as follows: + + ```ts + requestPermission() { + let context = this.context; + let permissions: Array = ['ohos.permission.DISTRIBUTED_DATASYNC']; + context.requestPermissionsFromUser(permissions).then((data) => { + console.info("Succeed to request permission from user with data: "+ JSON.stringify(data)); + }).catch((error) => { + console.info("Failed to request permission from user with error: "+ JSON.stringify(error)); + }) + } + ``` + +3. Obtain the device ID of the target device. + + ```ts + import deviceManager from '@ohos.distributedHardware.deviceManager'; + + let dmClass; + function initDmClass() { + // createDeviceManager is a system API. + deviceManager.createDeviceManager('ohos.samples.demo', (err, dm) => { + if (err) { + // ... + return + } + dmClass = dm + }) + } + function getRemoteDeviceId() { + if (typeof dmClass === 'object' && dmClass !== null) { + let list = dmClass.getTrustedDeviceListSync() + if (typeof (list) === 'undefined' || typeof (list.length) === 'undefined') { + console.info('EntryAbility onButtonClick getRemoteDeviceId err: list is null') + return; + } + return list[0].deviceId + } else { + console.info('EntryAbility onButtonClick getRemoteDeviceId err: dmClass is null') + } + } + ``` + +4. Set the target component parameters, and call **startAbility()** to start UIAbility or ServiceExtensionAbility. + + ```ts + let want = { + deviceId: getRemoteDeviceId(), + bundleName: 'com.example.myapplication', + abilityName: 'FuncAbility', + moduleName: 'module1', // moduleName is optional. + } + // context is the ability-level context of the initiator UIAbility. + this.context.startAbility(want).then(() => { + // ... + }).catch((err) => { + // ... + }) + ``` + + +## Starting UIAbility Across Devices (Data Returned) + +On device A, touch the **Start** button provided by the initiator application to start a specified UIAbility on device B. When the UIAbility on device B exits, a value is sent back to the initiator application. + + +### Available APIs + +**Table 2** APIs for starting an ability across devices and returning the result data + +| API| Description| +| -------- | -------- | +| startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void; | Starts a UIAbility. This API uses an asynchronous callback to return the result when the UIAbility is terminated.| +| terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void;| Terminates this UIAbility. This API uses an asynchronous callback to return the ability result information. It is used together with **startAbilityForResult**.| +| terminateSelfWithResult(parameter: AbilityResult): Promise<void>; | Terminates this UIAbility. This API uses a promise to return the ability result information. It is used together with **startAbilityForResult**.| + + +### How to Develop + +1. Request the **ohos.permission.DISTRIBUTED_DATASYNC** permission. For details, see [Permission Application Guide](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file). + +2. Request the data synchronization permission. The sample code for displaying a dialog box to request the permission is as follows: + + ```ts + requestPermission() { + let context = this.context; + let permissions: Array = ['ohos.permission.DISTRIBUTED_DATASYNC']; + context.requestPermissionsFromUser(permissions).then((data) => { + console.info("Succeed to request permission from user with data: "+ JSON.stringify(data)); + }).catch((error) => { + console.info("Failed to request permission from user with error: "+ JSON.stringify(error)); + }) + } + ``` + +3. Set the target component parameters on the initiator, and call **startAbilityForResult()** to start the target UIAbility. **data** in the asynchronous callback is used to receive the information returned by the target UIAbility to the initiator UIAbility after the target UIAbility terminates itself. For details about how to implement **getRemoteDeviceId()**, see [Starting UIAbility and ServiceExtensionAbility Across Devices (No Data Returned)](#starting-uiability-and-serviceextensionability-across-devices-no-data-returned). + + ```ts + let want = { + deviceId: getRemoteDeviceId(), + bundleName: 'com.example.myapplication', + abilityName: 'FuncAbility', + moduleName: 'module1', // moduleName is optional. + } + // context is the ability-level context of the initiator UIAbility. + this.context.startAbilityForResult(want).then((data) => { + // ... + }).catch((err) => { + // ... + }) + ``` + +4. After the UIAbility task at the target device is complete, call **terminateSelfWithResult()** to return the data to the initiator UIAbility. + + ```ts + const RESULT_CODE: number = 1001; + let abilityResult = { + resultCode: RESULT_CODE, + want: { + bundleName: 'com.example.myapplication', + abilityName: 'FuncAbility', + moduleName: 'module1', + }, + } + // context is the ability-level context of the target UIAbility. + this.context.terminateSelfWithResult(abilityResult, (err) => { + // ... + }); + ``` + +5. The initiator UIAbility receives the information returned by the target UIAbility and processes the information. + + ```ts + const RESULT_CODE: number = 1001; + + // ... + + // context is the ability-level context of the initiator UIAbility. + this.context.startAbilityForResult(want).then((data) => { + if (data?.resultCode === RESULT_CODE) { + // Parse the information returned by the target UIAbility. + let info = data.want?.parameters?.info + // ... + } + }).catch((err) => { + // ... + }) + ``` + + +## Connecting to ServiceExtensionAbility Across Devices + +A system application can connect to a service on another device by calling [connectServiceExtensionAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextconnectserviceextensionability). For example, in the distributed game scenario, a tablet is used as the remote control and a smart TV is used as the display. + + +### Available APIs + +**Table 3** APIs for cross-device connection + +| API| Description| +| -------- | -------- | +| connectServiceExtensionAbility(want: Want, options: ConnectOptions): number; | Connects to a ServiceExtensionAbility.| +| disconnectServiceExtensionAbility(connection: number, callback: AsyncCallback<void>): void; | Disconnects a connection. This API uses an asynchronous callback to return the result.| +| disconnectServiceExtensionAbility(connection: number): Promise<void>; | Disconnects a connection. This API uses a promise to return the result.| + + +### How to Develop + +1. Request the **ohos.permission.DISTRIBUTED_DATASYNC** permission. For details, see [Permission Application Guide](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file). + +2. Request the data synchronization permission. The sample code for displaying a dialog box to request the permission is as follows: + + ```ts + requestPermission() { + let context = this.context; + let permissions: Array = ['ohos.permission.DISTRIBUTED_DATASYNC']; + context.requestPermissionsFromUser(permissions).then((data) => { + console.info("Succeed to request permission from user with data: "+ JSON.stringify(data)); + }).catch((error) => { + console.info("Failed to request permission from user with error: "+ JSON.stringify(error)); + }) + } + ``` + +3. (Optional) [Implement a background service](serviceextensionability.md#implementing-a-background-service). Perform this operation only if no background service is available. + +4. Connect to the background service. + - Implement the **IAbilityConnection** class. **IAbilityConnection** provides the following callbacks that you should implement: **onConnect()**, **onDisconnect()**, and **onFailed()**. The **onConnect()** callback is invoked when a service is connected, **onDisconnect()** is invoked when a service is unexpectedly disconnected, and **onFailed()** is invoked when the connection to a service fails. + - Set the target component parameters, including the target device ID, bundle name, and ability name. + - Call **connectServiceExtensionAbility** to initiate a connection. + - Receive the service handle returned by the target device when the connection is successful. + - Perform cross-device invoking and obtain the result returned by the target service. + + ```ts + import rpc from '@ohos.rpc'; + + const REQUEST_CODE = 99; + let want = { + "deviceId": getRemoteDeviceId(), + "bundleName": "com.example.myapplication", + "abilityName": "ServiceExtAbility" + }; + let options = { + onConnect(elementName, remote) { + console.info('onConnect callback'); + if (remote === null) { + console.info(`onConnect remote is null`); + return; + } + let option = new rpc.MessageOption(); + let data = new rpc.MessageParcel(); + let reply = new rpc.MessageParcel(); + data.writeInt(1); + data.writeInt(99); // You can send data to the target application for corresponding operations. + + // @param code Indicates the service request code sent by the client. + // @param data Indicates the {@link MessageParcel} object sent by the client. + // @param reply Indicates the response message object sent by the remote service. + // @param options Specifies whether the operation is synchronous or asynchronous. + // + // @return Returns {@code true} if the operation is successful; returns {@code false} otherwise. + remote.sendRequest(REQUEST_CODE, data, reply, option).then((ret) => { + let msg = reply.readInt(); // Receive the information (100) returned by the target device if the connection is successful. + console.info(`sendRequest ret:${ret} msg:${msg}`); + }).catch((error) => { + console.info('sendRequest failed'); + }); + }, + onDisconnect(elementName) { + console.info('onDisconnect callback'); + }, + onFailed(code) { + console.info('onFailed callback'); + } + } + // The ID returned after the connection is set up must be saved. The ID will be passed for service disconnection. + let connectionId = this.context.connectServiceExtensionAbility(want, options); + ``` + + For details about how to implement **getRemoteDeviceId()**, see [Starting UIAbility and ServiceExtensionAbility Across Devices (No Data Returned)](#starting-uiability-and-serviceextensionability-across-devices-no-data-returned). + +5. Disconnect the connection. Use **disconnectServiceExtensionAbility()** to disconnect from the background service. + + ```ts + let connectionId = 1 // ID returned when the service is connected through connectServiceExtensionAbility. + this.context.disconnectServiceExtensionAbility(connectionId).then((data) => { + console.info('disconnectServiceExtensionAbility success'); + }).catch((error) => { + console.error('disconnectServiceExtensionAbility failed'); + }) + ``` + + +## Using Cross-Device Ability Call + +The basic principle of cross-device ability call is the same as that of intra-device ability call. For details, see [Using Ability Call to Implement UIAbility Interaction](uiability-intra-device-interaction.md#using-ability-call-to-implement-uiability-interaction). + +The following describes how to implement multi-device collaboration through cross-device ability call. + + +### Available APIs + +**Table 4** Ability call APIs + +| API| Description| +| -------- | -------- | +| startAbilityByCall(want: Want): Promise<Caller>; | Starts a UIAbility in the foreground or background and obtains the caller object for communicating with the UIAbility.| +| on(method: string, callback: CalleeCallBack): void | Callback invoked when the callee ability registers a method.| +| off(method: string): void | Callback invoked when the callee ability deregisters a method.| +| call(method: string, data: rpc.Sequenceable): Promise<void> | Sends agreed sequenceable data to the callee ability.| +| callWithResult(method: string, data: rpc.Sequenceable): Promise<rpc.MessageParcel> | Sends agreed sequenceable data to the callee ability and obtains the agreed sequenceable data returned by the callee ability.| +| release(): void | Releases the caller object.| +| on(type: "release", callback: OnReleaseCallback): void | Callback invoked when the caller object is released.| + + +### How to Develop + +1. Request the **ohos.permission.DISTRIBUTED_DATASYNC** permission. For details, see [Permission Application Guide](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file). + +2. Request the data synchronization permission. The sample code for displaying a dialog box to request the permission is as follows: + + ```ts + requestPermission() { + let context = this.context; + let permissions: Array = ['ohos.permission.DISTRIBUTED_DATASYNC']; + context.requestPermissionsFromUser(permissions).then((data) => { + console.info("Succeed to request permission from user with data: "+ JSON.stringify(data)); + }).catch((error) => { + console.info("Failed to request permission from user with error: "+ JSON.stringify(error)); + }) + } + ``` + +3. Create the callee ability. + + +For the callee ability, implement the callback to receive data and the methods to marshal and unmarshal data. When data needs to be received, use **on()** to register a listener. When data does not need to be received, use **off()** to deregister the listener. + + 1. Configure the launch type of the UIAbility. + + Set **launchType** of the callee ability to **singleton** in the **module.json5** file. + + | JSON Field| Description| + | -------- | -------- | + | "launchType"| Ability launch type. Set this parameter to **singleton**.| + + An example of the UIAbility configuration is as follows: + + +​ + ```json + "abilities":[{ + "name": ".CalleeAbility", + "srcEntrance": "./ets/CalleeAbility/CalleeAbility.ts", + "launchType": "singleton", + "description": "$string:CalleeAbility_desc", + "icon": "$media:icon", + "label": "$string:CalleeAbility_label", + "visible": true + }] + ``` + + 2. Import the **UIAbility** module. + + ```ts + import Ability from '@ohos.app.ability.UIAbility'; + ``` + + 3. Define the agreed sequenceable data. + + + The data formats sent and received by the caller and callee abilities must be consistent. In the following example, the data formats are number and string. + + + ```ts + export default class MySequenceable { + num: number = 0; + str: string = ""; + + constructor(num, string) { + this.num = num; + this.str = string; + } + + marshalling(messageParcel) { + messageParcel.writeInt(this.num); + messageParcel.writeString(this.str); + return true; + } + + unmarshalling(messageParcel) { + this.num = messageParcel.readInt(); + this.str = messageParcel.readString(); + return true; + } + } + ``` + + 4. Implement **Callee.on** and **Callee.off**. + + In the following example, the **MSG_SEND_METHOD** listener is registered in **onCreate()** of the ability and deregistered in **onDestroy()**. After receiving sequenceable data, the application processes the data and returns the data result. You need to implement processing based on service requirements. + + ```ts + const TAG: string = '[CalleeAbility]'; + const MSG_SEND_METHOD: string = 'CallSendMsg'; + + function sendMsgCallback(data) { + console.info('CalleeSortFunc called'); + + // Obtain the sequenceable data sent by the caller ability. + let receivedData = new MySequenceable(0, ''); + data.readSequenceable(receivedData); + console.info(`receiveData[${receivedData.num}, ${receivedData.str}]`); + + // Process the data. + // Return the sequenceable data result to the caller ability. + return new MySequenceable(receivedData.num + 1, `send ${receivedData.str} succeed`); + } + + export default class CalleeAbility extends Ability { + onCreate(want, launchParam) { + try { + this.callee.on(MSG_SEND_METHOD, sendMsgCallback); + } catch (error) { + console.info(`${MSG_SEND_METHOD} register failed with error ${JSON.stringify(error)}`); + } + } + + onDestroy() { + try { + this.callee.off(MSG_SEND_METHOD); + } catch (error) { + console.error(TAG, `${MSG_SEND_METHOD} unregister failed with error ${JSON.stringify(error)}`); + } + } + } + ``` + +4. Obtain the caller object and access the callee ability. + 1. Import the **UIAbility** module. + + ```ts + import Ability from '@ohos.app.ability.UIAbility'; + ``` + + 2. Obtain the caller object. + + + The **context** attribute of the ability implements **startAbilityByCall** to obtain the caller object for communication. The following example uses **this.context** to obtain the **context** attribute of the ability, uses **startAbilityByCall** to start the callee ability, obtain the caller object, and register the **onRelease** listener of the caller ability. You need to implement processing based on service requirements. + + + ```ts + async onButtonGetRemoteCaller() { + var caller = undefined; + var context = this.context; + + context.startAbilityByCall({ + deviceId: getRemoteDeviceId(), + bundleName: 'com.samples.CallApplication', + abilityName: 'CalleeAbility' + }).then((data) => { + if (data != null) { + caller = data; + console.info('get remote caller success'); + // Register the onRelease() listener of the caller ability. + caller.onRelease((msg) => { + console.info(`remote caller onRelease is called ${msg}`); + }) + console.info('remote caller register OnRelease succeed'); + } + }).catch((error) => { + console.error(`get remote caller failed with ${error}`); + }) + } + ``` + + For details about how to implement **getRemoteDeviceId()**, see [Starting UIAbility and ServiceExtensionAbility Across Devices (No Data Returned)](#starting-uiability-and-serviceextensionability-across-devices-no-data-returned). + ``` + +5. Sends agreed sequenceable data to the callee ability. + 1. The sequenceable data can be sent to the callee ability with or without a return value. The method and sequenceable data must be consistent with those of the callee ability. The following example describes how to send data to the callee ability. + + ```ts + const MSG_SEND_METHOD: string = 'CallSendMsg'; + async onButtonCall() { + try { + let msg = new MySequenceable(1, 'origin_Msg'); + await this.caller.call(MSG_SEND_METHOD, msg); + } catch (error) { + console.info(`caller call failed with ${error}`); + } + } + ``` + 2. In the following, **CallWithResult** is used to send data **originMsg** to the callee ability and assign the data processed by the **CallSendMsg** method to **backMsg**. + + ```ts + const MSG_SEND_METHOD: string = 'CallSendMsg'; + originMsg: string = ''; + backMsg: string = ''; + async onButtonCallWithResult(originMsg, backMsg) { + try { + let msg = new MySequenceable(1, originMsg); + const data = await this.caller.callWithResult(MSG_SEND_METHOD, msg); + console.info('caller callWithResult succeed'); + + let result = new MySequenceable(0, ''); + data.readSequenceable(result); + backMsg(result.str); + console.info(`caller result is [${result.num}, ${result.str}]`); + } catch (error) { + console.info(`caller callWithResult failed with ${error}`); + } + } + ``` + +6. Release the caller object. + + When the caller object is no longer required, use **release()** to release it. + + ```ts + releaseCall() { + try { + this.caller.release(); + this.caller = undefined + console.info('caller release succeed'); + } catch (error) { + console.info(`caller release failed with ${error}`); + } + } + ``` diff --git a/en/application-dev/application-models/inter-device-interaction-hop-overview.md b/en/application-dev/application-models/inter-device-interaction-hop-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..6b1fd28b489f0d6d891abd9dffa0bcaf0f1b9ead --- /dev/null +++ b/en/application-dev/application-models/inter-device-interaction-hop-overview.md @@ -0,0 +1,49 @@ +# Continuation Overview + + +## When to Use + +As the all-scenario, multi-device lifestyle becomes popular, users have an increasing number of devices. Each device provides users with what they need in a certain scenario. For example, watches allow users to view information in a timely manner, and smart TVs bring them an immersive watching experience. However, each device has its limitation, for example, typing text on a smart TV is frustrating as it is much more difficult than on a mobile device. If multiple devices can sense each other through a distributed OS and together form a super device, the strengths of each device can be fully exerted to provide a more natural and smoother distributed experience for users. + +In OpenHarmony, distributed operations across devices are called continuation (previously named hopping), which is further classified into [cross-device migration](hop-cross-device-migration.md) and [multi-device collaboration](hop-multi-device-collaboration.md). To implement continuation, cross-device interaction capabilities of application components are required. Currently, these capabilities are open only to system applications. + + +## Basic Concepts + +- **Continuation** + + Continuation refers to distributed operations across devices. It breaks device boundaries and makes applications modular. For example, a user can edit the same email, carry out fitness, or play a game across devices. Continuation provides broad application scenarios, innovative product perspectives, enhanced product advantages, and superior experience. + +- **Cross-device migration** + + When the environment changes, for example, when a user goes outdoors or when a more appropriate device is detected, the user can migrate an ongoing task to another device for better experience. The original device exits the task. A typical cross-device migration scenario is as follows: You migrate a video playback task from your tablet to a smart TV. The video application on the tablet exits. From the perspective of application development, cross-device migration migrates the UIAbility component running on device A to device B. After the migration is complete, the UIAbility component on device B continues the task, whereas that on device A exits. + +- **Multi-device collaboration** + + Multi-device collaboration enables collaboration between multiple devices, providing users with more efficient and immersive experience than with a single device. A typical multi-device collaboration scenario is as follows: Application A on the tablet is used as the answer board, and application B on the smart TV is used for live broadcast, delivering a better online class experience. From the perspective of application development, multi-device collaboration enables different UIAbility or ServiceExtensionAbility components to run simultaneously or alternately on multiple devices to provide a complete service, or enables the same UIAbility and ServiceExtensionAbility component to run simultaneously on multiple devices to provide a complete service. + + +## Continuation Architecture + +OpenHarmony provides a set of APIs for you to implement continuation in your applications. The continuation architecture has the following advantages: + +- Capabilities such as remote service invocation to facilitate service design + +- Simultaneous continuation of multiple applications + +- Different device forms supported, such as tablets, smart TVs, and watches + +The following figure shows the continuation architecture. + + **Figure 1** Continuation architecture +hop-structure + +- Cross-device migration task management: The initiator accepts a migration request from the user, provides a migration entry, and displays the migration result. (This capability is unavailable yet.) + +- Multi-device collaboration task management: The initiator accepts an application registration request and provides management capabilities such as starting or stopping collaboration and status display. (This capability is unavailable yet.) + +- Distributed component management: provides capabilities such as remote service startup, remote service connection, and remote migration, and enables cross-device migration or multi-device collaboration of applications based on a combination of these capabilities. + +- Distributed security authentication: provides an E2E encrypted channel for cross-device transmission between applications to ensure that the right person uses the right data through the right device. + +- DSoftBus: functions as a unified communication base for a wide range of devices such as tablets, wearables, and smart TVs, and enables unified distributed communication between these devices. diff --git a/en/application-dev/application-models/itc-fa-overview.md b/en/application-dev/application-models/itc-fa-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..112a89edd8ba8236fca714a65d6f93287dcbe41d --- /dev/null +++ b/en/application-dev/application-models/itc-fa-overview.md @@ -0,0 +1,4 @@ +# Inter-Thread Communication (FA Model) + + +For details, see [Inter-Thread Communication](thread-model-stage.md) in the stage model. diff --git a/en/application-dev/application-models/itc-with-emitter.md b/en/application-dev/application-models/itc-with-emitter.md new file mode 100644 index 0000000000000000000000000000000000000000..2966bd8eea41e04893814f20a3c5b2f9e4e456c9 --- /dev/null +++ b/en/application-dev/application-models/itc-with-emitter.md @@ -0,0 +1,49 @@ +# Using Emitter for Inter-Thread Communication + +[Emitter](../reference/apis/js-apis-emitter.md) provides APIs for sending and processing events between threads, including the APIs for processing events that are subscribed to in persistent or one-shot manner, unsubscribing from events, and emitting events to the event queue. + + +To develop the Emitter mode, perform the following steps: + + +1. Subscribe to an event. + + ```ts + import emitter from "@ohos.events.emitter"; + + // Define an event with eventId 1. + let event = { + eventId: 1 + }; + + // Trigger the callback after the event with eventId 1 is received. + let callback = (eventData) => { + console.info('event callback'); + }; + + // Subscribe to the event with eventId 1. + emitter.on(event, callback); + ``` + +2. Emit the event. + + ```ts + import emitter from "@ohos.events.emitter"; + + // Define an event with eventId 1 and priority Low. + let event = { + eventId: 1, + priority: emitter.EventPriority.LOW + }; + + let eventData = { + data: { + "content": "c", + "id": 1, + "isEmpty": false, + } + }; + + // Emit the event with eventId 1 and event content eventData. + emitter.emit(event, eventData); + ``` diff --git a/en/application-dev/application-models/itc-with-worker.md b/en/application-dev/application-models/itc-with-worker.md new file mode 100644 index 0000000000000000000000000000000000000000..8cbe53eeea067ae1875a8ff4b73bc4cde7bdd629 --- /dev/null +++ b/en/application-dev/application-models/itc-with-worker.md @@ -0,0 +1,79 @@ +# Using Worker for Inter-Thread Communication + +[Worker](../reference/apis/js-apis-worker.md) is an independent thread running in parallel with the main thread. The thread that creates the worker thread is referred to as the host thread. The script file passed in during worker creation is executed in the worker thread. Generally, time-consuming operations are processed in the worker thread. However, pages cannot be directly updated in the worker thread. + + +To develop the Worker mode, perform the following steps: + + +1. Configure the **buildOption** field in the [module-level build-profile.json5](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-building-configuration-0000001218440654#section6887184182020) file of the project. + + ```ts + "buildOption": { + "sourceOption": { + "workers": [ + "./src/main/ets/workers/worker.ts" + ] + } + } + ``` + +2. Create the **worker.js** file based on the configuration in **build-profile.json5**. + + ```ts + import worker from '@ohos.worker'; + + let parent = worker.workerPort; + + // Process messages from the main thread. + parent.onmessage = function(message) { + console.info("onmessage: " + message) + // Send a message to the main thread. + parent.postMessage("message from worker thread.") + } + ``` + +3. In the main thread, use the following method to initialize and use the worker thread. + - Stage model: + + ```ts + import worker from '@ohos.worker'; + + let wk = new worker.ThreadWorker("entry/ets/workers/worker.ts"); + + // Send a message to the worker thread. + wk.postMessage("message from main thread.") + + // Process messages from the worker thread. + wk.onmessage = function(message) { + console.info("message from worker: " + message) + + // Stop the worker thread based on service requirements. + wk.terminate() + } + ``` + + - FA model: + + ```ts + import worker from '@ohos.worker'; + + let wk = new worker.ThreadWorker("../workers/worker.js"); + + // Send a message to the worker thread. + wk.postMessage("message from main thread.") + + // Process messages from the worker thread. + wk.onmessage = function(message) { + console.info("message from worker: " + message) + + // Stop the worker thread based on service requirements. + wk.terminate() + } + ``` + +> **NOTE** +> +> - If the relative path of **worker.ts** configured in **build-profile.json5** is **./src/main/ets/workers/worker.ts**, pass in the path **entry/ets/workers/worker.ts** when creating a worker thread in the stage model, and pass in the path **../workers/worker.js** when creating a worker thread in the FA model. +> +> - For details about the data types supported between the main thread and worker thread, see [Sequenceable Data Types](../reference/apis/js-apis-worker.md#sequenceable-data-types). diff --git a/en/application-dev/application-models/lifecycleapp-switch.md b/en/application-dev/application-models/lifecycleapp-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..892a8915bfed9927c2707364bdaffa1547f71bf6 --- /dev/null +++ b/en/application-dev/application-models/lifecycleapp-switch.md @@ -0,0 +1,21 @@ +# LifecycleApp Switching + + + | API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API in the Stage Model| +| -------- | -------- | -------- | +| onShow?(): void; | \@ohos.window.d.ts | [on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void;](../reference/apis/js-apis-window.md#onwindowstageevent9)
Listens for the switching to the [foreground](../reference/apis/js-apis-window.md#windowstageeventtype9).| +| onHide?(): void; | \@ohos.window.d.ts | [on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void;](../reference/apis/js-apis-window.md#onwindowstageevent9)
Listens for the switching to the [background](../reference/apis/js-apis-window.md#windowstageeventtype9).| +| onDestroy?(): void; | \@ohos.app.ability.UIAbility.d.ts | [onDestroy(): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityondestroy) | +| onCreate?(): void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want: Want, param: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate) | +| onWindowDisplayModeChanged?(isShownInMultiWindow: boolean, newConfig: resourceManager.Configuration): void; | There is no corresponding API in the stage model.| No corresponding API is provided.| +| onStartContinuation?(): boolean; | There is no corresponding API in the stage model.| In the stage model, an application does not need to detect whether the continuation is successful (detected when the application initiates the continuation request). Therefore, the **onStartContinuation()** callback is deprecated.| +| onSaveData?(data: Object): boolean; | \@ohos.app.ability.UIAbility.d.ts | [onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncontinue) | +| onCompleteContinuation?(result: number): void; | application\ContinueCallback.d.ts | [onContinueDone(result: number): void;](../reference/apis/js-apis-distributedMissionManager.md#continuecallback) | +| onRestoreData?(data: Object): void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want: Want, param: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)
[onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant)
In standard or singleton mode, the target ability completes data restoration in the **onCreate()** callback. In the callback, **launchParam.launchReason** is used to determine whether it is a continuation-based launch scenario. If it is, the data saved before continuation can be obtained from the **want** parameter.| +| onRemoteTerminated?(): void; | application\ContinueCallback.d.ts | [onContinueDone(result: number): void;](../reference/apis/js-apis-distributedMissionManager.md#continuecallback) | +| onSaveAbilityState?(outState: PacMap): void; | \@ohos.app.ability.UIAbility.d.ts | [onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: any}): AbilityConstant.OnSaveResult;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonsavestate) | +| onRestoreAbilityState?(inState: PacMap): void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want: Want, param: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)
After the application is restarted, the **onCreate()** callback is triggered. In the callback, **launchParam.launchReason** is used to determine whether it is a self-recovery scenario. If it is, the data saved before the restart can be obtained from the **want** parameter.| +| onInactive?(): void; | \@ohos.app.ability.UIAbility.d.ts | [onBackground(): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonbackground) | +| onActive?(): void; | \@ohos.app.ability.UIAbility.d.ts | [onForeground(): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonforeground) | +| onNewWant?(want: Want): void; | \@ohos.app.ability.UIAbility.d.ts | [onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant) | +| onMemoryLevel?(level: number): void | \@ohos.app.ability.UIAbility.d.ts | [onMemoryLevel(level: AbilityConstant.MemoryLevel): void;](../reference/apis/js-apis-app-ability-ability.md#abilityonmemorylevel) | diff --git a/en/application-dev/application-models/lifecycledata-switch.md b/en/application-dev/application-models/lifecycledata-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..be96421a92161deeb26c9e99af9ec5de332d9e25 --- /dev/null +++ b/en/application-dev/application-models/lifecycledata-switch.md @@ -0,0 +1,18 @@ +# LifecycleData Switching + + + | API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API in the Stage Model| +| -------- | -------- | -------- | +| update?(uri: string, valueBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void; | \@ohos.application.DataShareExtensionAbility.d.ts | [update?(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueBucket: ValuesBucket, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-application-dataShareExtensionAbility.md#update) | +| query?(uri: string, columns: Array<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void; | \@ohos.application.DataShareExtensionAbility.d.ts | [query?(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>): void;](../reference/apis/js-apis-application-dataShareExtensionAbility.md#query) | +| delete?(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void; | \@ohos.application.DataShareExtensionAbility.d.ts | [delete?(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-application-dataShareExtensionAbility.md#delete) | +| normalizeUri?(uri: string, callback: AsyncCallback<string>): void; | \@ohos.application.DataShareExtensionAbility.d.ts | [normalizeUri?(uri: string, callback: AsyncCallback<string>): void;](../reference/apis/js-apis-application-dataShareExtensionAbility.md#normalizeuri) | +| batchInsert?(uri: string, valueBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback<number>): void; | \@ohos.application.DataShareExtensionAbility.d.ts | [batchInsert?(uri: string, valueBuckets: Array<ValuesBucket>, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-application-dataShareExtensionAbility.md#batchinsert) | +| denormalizeUri?(uri: string, callback: AsyncCallback<string>): void; | \@ohos.application.DataShareExtensionAbility.d.ts | [denormalizeUri?(uri: string, callback: AsyncCallback<string>): void;](../reference/apis/js-apis-application-dataShareExtensionAbility.md#denormalizeuri) | +| insert?(uri: string, valueBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void; | \@ohos.application.DataShareExtensionAbility.d.ts | [insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-application-dataShareExtensionAbility.md#insert) | +| openFile?(uri: string, mode: string, callback: AsyncCallback<number>): void; | There is no corresponding API in the stage model.| The stage model does not support cross-process URI access. You are advised to use [the want parameter to carry the file descriptor and file information](data-share-via-want.md) for cross-process file access.| +| getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>): void; | There is no corresponding API in the stage model.| The stage model does not support cross-process URI access. You are advised to use [the want parameter to carry the file descriptor and file information](data-share-via-want.md) for cross-process file access.| +| onInitialized?(info: AbilityInfo): void; | \@ohos.application.DataShareExtensionAbility.d.ts | [onCreate?(want: Want, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-application-dataShareExtensionAbility.md#oncreate) | +| getType?(uri: string, callback: AsyncCallback<string>): void; | There is no corresponding API in the stage model.| The stage model does not support cross-process URI access. You are advised to use [the want parameter to carry the file descriptor and file information](data-share-via-want.md) for cross-process file access.| +| executeBatch?(ops: Array<DataAbilityOperation>, callback: AsyncCallback<Array<DataAbilityResult>>): void; | There is no corresponding API in the stage model.| No corresponding API is provided.| +| call?(method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void; | There is no corresponding API in the stage model.| No corresponding API is provided.| diff --git a/en/application-dev/application-models/lifecycleform-switch.md b/en/application-dev/application-models/lifecycleform-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..80e577eeac759f589cb53c6b367ae17ba8b98e8c --- /dev/null +++ b/en/application-dev/application-models/lifecycleform-switch.md @@ -0,0 +1,13 @@ +# LifecycleForm Switching + + + | API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API in the Stage Model| +| -------- | -------- | -------- | +| onCreate?(want: Want): formBindingData.FormBindingData; | \@ohos.app.form.FormExtensionAbility.d.ts | [onAddForm(want: Want): formBindingData.FormBindingData;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onaddform) | +| onCastToNormal?(formId: string): void; | \@ohos.app.form.FormExtensionAbility.d.ts | [onCastToNormalForm(formId: string): void;](../reference/apis/js-apis-app-form-formExtensionAbility.md#oncasttonormalform) | +| onUpdate?(formId: string): void; | \@ohos.app.form.FormExtensionAbility.d.ts | [onUpdateForm(formId: string): void;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onupdateform) | +| onVisibilityChange?(newStatus: { [key: string]: number }): void; | \@ohos.app.form.FormExtensionAbility.d.ts | [onChangeFormVisibility(newStatus: { [key: string]: number }): void;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onchangeformvisibility) | +| onEvent?(formId: string, message: string): void; | \@ohos.app.form.FormExtensionAbility.d.ts | [onFormEvent(formId: string, message: string): void;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onformevent) | +| onDestroy?(formId: string): void; | \@ohos.app.form.FormExtensionAbility.d.ts | [onRemoveForm(formId: string): void;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onremoveform) | +| onAcquireFormState?(want: Want): formInfo.FormState; | \@ohos.app.form.FormExtensionAbility.d.ts | [onAcquireFormState?(want: Want): formInfo.FormState;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onacquireformstate) | +| onShare?(formId: string): {[key: string]: any}; | \@ohos.app.form.FormExtensionAbility.d.ts | [onShareForm?(formId: string): { [key: string]: any };](../reference/apis/js-apis-app-form-formExtensionAbility.md#onshareform) | diff --git a/en/application-dev/application-models/lifecycleservice-switch.md b/en/application-dev/application-models/lifecycleservice-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..d1fcdc7a30efb0114e092ac5a6233566270312fa --- /dev/null +++ b/en/application-dev/application-models/lifecycleservice-switch.md @@ -0,0 +1,11 @@ +# LifecycleService Switching + + + | API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API in the Stage Model| +| -------- | -------- | -------- | +| onStart?(): void; | \@ohos.app.ability.ServiceExtensionAbility.d.ts | [onCreate(want: Want): void;](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md#serviceextensionabilityoncreate) | +| onCommand?(want: Want, startId: number): void; | \@ohos.app.ability.ServiceExtensionAbility.d.ts | [onRequest(want: Want, startId: number): void;](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md#serviceextensionabilityonrequest) | | +| onStop?(): void; | \@ohos.app.ability.ServiceExtensionAbility.d.ts | [onDestroy(): void;](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md#serviceextensionabilityondestroy) | | +| onConnect?(want: Want): rpc.RemoteObject; | \@ohos.app.ability.ServiceExtensionAbility.d.ts | [onConnect(want: Want): rpc.RemoteObject;](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md#serviceextensionabilityonconnect) | | +| onDisconnect?(want: Want): void; | \@ohos.app.ability.ServiceExtensionAbility.d.ts | [onDisconnect(want: Want): void;](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md#serviceextensionabilityondisconnect) | | +| onReconnect?(want: Want): void; | \@ohos.app.ability.ServiceExtensionAbility.d.ts | [onReconnect(want: Want): void;](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md#serviceextensionabilityonreconnect) | | diff --git a/en/application-dev/application-models/medialibrary-switch.md b/en/application-dev/application-models/medialibrary-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..29e9b10964d2b9c967960f6c2ad802a942aa0ac3 --- /dev/null +++ b/en/application-dev/application-models/medialibrary-switch.md @@ -0,0 +1,6 @@ +# mediaLibrary Switching + + + | API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API in the Stage Model| +| -------- | -------- | -------- | +| [getMediaLibrary(): MediaLibrary;](../reference/apis/js-apis-medialibrary.md#medialibrarygetmedialibrary) | \@ohos.multimedia.mediaLibrary.d.ts | [getMediaLibrary(context: Context): MediaLibrary;](../reference/apis/js-apis-medialibrary.md#medialibrarygetmedialibrary8) | diff --git a/en/application-dev/application-models/mission-management-fa.md b/en/application-dev/application-models/mission-management-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..07641af7d736f298c99908805a5493cadadd4b00 --- /dev/null +++ b/en/application-dev/application-models/mission-management-fa.md @@ -0,0 +1,4 @@ +# Mission Management (FA Model) + + +For details, see [Mission Management](mission-management-overview.md) in the stage model. diff --git a/en/application-dev/application-models/mission-management-launch-type.md b/en/application-dev/application-models/mission-management-launch-type.md new file mode 100644 index 0000000000000000000000000000000000000000..7dbb3b5c8fa5a8dfab3f03ab0eb3b02ba4cb98d2 --- /dev/null +++ b/en/application-dev/application-models/mission-management-launch-type.md @@ -0,0 +1,34 @@ +# Mission Management and Launch Type + + +One UIAbility instance corresponds to one mission. The number of UIAbility instances is related to the UIAbility launch type, specified by **launchType**, which is configured in the **config.json** file in the FA model and the [module.json5](../quick-start/module-configuration-file.md) file in the stage model. + + +The following describes how the mission list manager manages the UIAbility instanced started in different modes. +- **singleton**: Only one UIAbility instance exists for an application. + + **Figure 1** Missions and singleton mode + ![mission-and-singleton](figures/mission-and-singleton.png) + +- **standard**: Each time **startAbility()** is called, a UIAbility instance is created in the application process. + + **Figure 2** Missions and standard mode + ![mission-and-standard](figures/mission-and-standard.png) + +- **specified**: The ([onAcceptWant](../reference/apis/js-apis-app-ability-abilityStage.md#abilitystageonacceptwant)) method of [AbilityStage](abilitystage.md) determines whether to create an instance. + + **Figure 3** Missions and specified mode + ![mission-and-specified](figures/mission-and-specified.png) + + +Each UIAbility instance corresponds to a mission displayed in **Recents**. + + +Every mission retains a snapshot of the UIAbility instance. After the UIAbility instance is destroyed, the mission information (including the ability information and mission snapshot) is retained until the mission is deleted. + + +> **NOTE** +> +> The **specified** mode is supported in the stage model only. + + \ No newline at end of file diff --git a/en/application-dev/application-models/mission-management-overview.md b/en/application-dev/application-models/mission-management-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..b6f6668f7ce56a9de0b5a3d0182b14ec189703c9 --- /dev/null +++ b/en/application-dev/application-models/mission-management-overview.md @@ -0,0 +1,129 @@ +# Mission Management Scenarios + + +Before getting started with the development of mission management, be familiar with the following concepts related to mission management: + + +- AbilityRecord: minimum unit for the system service to manage a UIAbility instance. It corresponds to a UIAbility component instance of an application. + +- MissionRecord: minimum unit for mission management. One MissionRecord has only one AbilityRecord. In other words, a UIAbility component instance corresponds to a mission. + +- MissionList: a list of missions started from the home screen. It records the startup relationship between missions. In a MissionList, an above mission is started by the mission under it, and the mission at the bottom is started by the home screen. + +- MissionListManager: system mission management module that maintains all the MissionLists and is consistent with the list in **Recents**. + + **Figure 1** Mission management + ![mission-list-manager](figures/mission-list-manager.png) + + +Missions are managed by system applications (such as home screen), rather than third-party applications. Users interact with missions through **Recents**. After creating a mission, users can perform the following operations on **Recents**: + + +- Delete a mission. + +- Lock or unlock a mission. (Locked missions are not cleared when users attempt to clear all missions in **Recents**.) + +- Clear all missions in **Recents**. + +- Switch a mission to the foreground. + + +A UIAbility instance corresponds to an independent mission. Therefore, when an application calls the **startAbility()** method to start a UIAbility, a mission is created. + + +To call [missionManager](../reference/apis/js-apis-application-missionManager.md) to manage missions, the home screen application must request the **ohos.permission.MANAGE_MISSIONS** permission. For details about the configuration, see [Permission Application Guide](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file). + + +You can use **missionManager** to manage missions, for example, listening for mission changes, obtaining mission information or snapshots, and clearing, locking, or unlocking missions. The sample code is as follows: + +```ts +import missionManager from '@ohos.app.ability.missionManager' + +let listener = { + // Listen for mission creation. + onMissionCreated: function (mission) { + console.info("--------onMissionCreated-------") + }, + // Listen for mission destruction. + onMissionDestroyed: function (mission) { + console.info("--------onMissionDestroyed-------") + }, + // Listen for mission snapshot changes. + onMissionSnapshotChanged: function (mission) { + console.info("--------onMissionSnapshotChanged-------") + }, + // Listen for switching the mission to the foreground. + onMissionMovedToFront: function (mission) { + console.info("--------onMissionMovedToFront-------") + }, + // Listen for mission icon changes. + onMissionIconUpdated: function (mission, icon) { + console.info("--------onMissionIconUpdated-------") + }, + // Listen for mission name changes. + onMissionLabelUpdated: function (mission) { + console.info("--------onMissionLabelUpdated-------") + }, + // Listen for mission closure events. + onMissionClosed: function (mission) { + console.info("--------onMissionClosed-------") + } +}; + +// 1. Register a mission change listener. +let listenerId = missionManager.on('mission', listener); + +// 2. Obtain the latest 20 missions in the system. +missionManager.getMissionInfos("", 20, (error, missions) => { + console.info("getMissionInfos is called, error.code = " + error.code); + console.info("size = " + missions.length); + console.info("missions = " + JSON.stringify(missions)); +}); + +// 3. Obtain the detailed information about a mission. +let missionId = 11; // The mission ID 11 is only an example. +let mission = missionManager.getMissionInfo("", missionId).catch(function (err) { + console.info(err); +}); + +// 4. Obtain the mission snapshot. +missionManager.getMissionSnapShot("", missionId, (error, snapshot) => { + console.info("getMissionSnapShot is called, error.code = " + error.code); + console.info("bundleName = " + snapshot.ability.bundleName); +}) + +// 5. Obtain the low-resolution mission snapshot. +missionManager.getLowResolutionMissionSnapShot("", missionId, (error, snapshot) => { + console.info("getLowResolutionMissionSnapShot is called, error.code = " + error.code); + console.info("bundleName = " + snapshot.ability.bundleName); +}) + +// 6. Lock or unlock the mission. +missionManager.lockMission(missionId).then(() => { + console.info("lockMission is called "); +}); + +missionManager.unlockMission(missionId).then(() => { + console.info("unlockMission is called "); +}); + +// 7. Switch the mission to the foreground. +missionManager.moveMissionToFront(missionId).then(() => { + console.info("moveMissionToFront is called "); +}); + +// 8. Clear a single mission. +missionManager.clearMission(missionId).then(() => { + console.info("clearMission is called "); +}); + +// 9. Clear all missions. +missionManager.clearAllMissions().catch(function (err) { + console.info(err); +}); + +// 10. Deregister the mission change listener. +missionManager.off('mission', listenerId, (error) => { + console.info("unregisterMissionListener"); +}) +``` diff --git a/en/application-dev/application-models/model-switch-overview.md b/en/application-dev/application-models/model-switch-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..e42882ca59b33c65fe6591510954d95e2c49453b --- /dev/null +++ b/en/application-dev/application-models/model-switch-overview.md @@ -0,0 +1,23 @@ +# Model Switching Overview + + +Perform the following operations to switch a declarative paradigm-based application developed based on the FA model to the stage model. + + +- Project switch: Create an application project of the stage model. + ![model-switch-overview1](figures/model-switch-overview1.png) + +- [Configuration file switch](configuration-file-diff.md): Switch **config.json** to **app.json5** and **module.json5**. + ![model-switch-overview2](figures/model-switch-overview2.png) + +- [Component switch](pageability-switch.md): Switch the PageAbility, ServiceAbility, and DataAbility components of the FA model to the UIAbility and ExtensionAbility components of the stage model. The figure below shows only the switching from PageAbility to UIAbility. The left part is the FA model, and **app.ets** is the PageAbility component. The right part is the stage model, and **EntryAbility.ts** is the UIAbility component. + +![model-switch-overview3](figures/model-switch-overview3.png) + +- [Widget switch](widget-switch.md): Switch the FormAbility component of the FA model to the FormExtensionAbility component of the stage model. In the figure below, **Service Widget** is FormAbility in the FA model and FormExtensionAbility in the stage model. + ![model-switch-overview4](figures/model-switch-overview4.png) + + ![model-switch-overview5](figures/model-switch-overview5.png) + +- [API switch](api-switch-overview.md): Switch the APIs with the **FAModelOnly** tag used in the FA model to the recommended APIs in the stage model. + ![model-switch-overview6](figures/model-switch-overview6.png) diff --git a/en/application-dev/application-models/module-switch.md b/en/application-dev/application-models/module-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..a6e532e94827198880cb772c174725b2a89c469b --- /dev/null +++ b/en/application-dev/application-models/module-switch.md @@ -0,0 +1,75 @@ +# Switching of module + + +When switching an application from the FA model to the stage model, you must migrate the configurations under the **module** tag in the **config.json** file to the **module** tag in the **module.json5** file. + +### **Table 1** module comparison + +| Field Name in the FA Model| Field Description| Field Name in the Stage Model| Difference| +| -------- | -------- | -------- | -------- | +| mainAbility | Ability displayed on the Service Center icon. When the resident process is started, the **mainAbility** is started.| mainElement | The field name is changed, and the stage mode does not use the period (.) in ability names.| +| package | Package name of the HAP file, which must be unique in the application.| / | The stage model uses **name** to ensure application uniqueness. To ensure a successful switching from the FA model to the stage model, **name** in the stage model must be the same as **package** in the FA model.| +| name | Class name of the HAP file.| / | This configuration is not enabled in the FA model, and the stage model does not have such a field.| +| supportedModes | Modes supported by the application. Currently, only the **drive** mode is defined.| / | This configuration is deprecated in the stage model.| +| moduleName in the distro object| Name of the current HAP file.
moduleName in the distro object.| name | The field name is changed.| +| moduleType in the distro object| Type of the HAP file. The value can be **entry** or **feature**. For the HAR type, set this field to **har**.| type | The field name is changed.| +| installationFree in the distro object| Whether the HAP file supports the installation-free feature.| installationFree | The field name is changed.| +| deliveryWithInstall in the distro object| Whether the HAP file is installed with the application.| deliveryWithInstall | The field name is changed.| +| metaData | Metadata of the HAP file.| metadata | See [Table 2](#table-2-metadata-comparison).| +| abilities | All abilities in the current module.| abilities | See [Table 5](#table-5-abilities-comparison).| +| js | A set of JS modules developed using ArkUI. Each element in the set represents the information about a JS module.| pages | The stage model retains **pages** under the **module** tag. The window configuration is the lower level of **pages**.| +| shortcuts | Shortcuts of the application.| shortcut_config.json| In the stage model, the **shortcut_config.json** file is defined in **resources/base/profile** in the development view.| +| reqPermissions | Permissions that the application requests from the system when it is running.| requestPermissions | The field name is changed.| +| colorMode | Color mode of the application.| / | This configuration is not supported in the stage model.| +| distroFilter | Distribution rules of the application.| distroFilter_config.json| In the stage model, the **distroFilter_config.json** file is defined in **resources/base/profile** in the development view.| +| reqCapabilities | Device capabilities required for running the application.| / | This configuration is not supported in the stage model.| +| commonEvents | Common events.| common_event_config.json| In the stage model, the **common_event_config.json** file is defined in **resources/base/profile** in the development view.| +| entryTheme | Keyword of an OpenHarmony internal theme.| / | This configuration is not supported in the stage model.| + + +### Table 2 metaData comparison + +| Field Name Under metaData in the FA Model| Field Description| Field Name Under metaData in the Stage Model| Difference| +| -------- | -------- | -------- | -------- | +| parameters | Metadata of the parameters to be passed for calling the ability.| / | This configuration is not supported in the stage model.| +| results | Metadata of the ability return value.| / | This configuration is not supported in the stage model.| +| customizeData | Custom metadata of the parent component. **parameters** and **results** cannot be configured in **application**.| metadata | See [Table 3](#table-3-comparison-between-customizedata-under-metadata-in-the-fa-model-and-metadata-in-the-stage-model).| + +### Table 3 Comparison between customizeData under metaData in the FA model and metadata in the stage model + +| Field Name Under customizeData in metaData in the FA Model| Field Description| Field Name Under metaData in the Stage Model| Difference| +| -------- | -------- | -------- | -------- | +| name | Key name that identifies a data item. The value is a string with a maximum of 255 bytes.| name | None.| +| value | Value of the data item. The value is a string with a maximum of 255 bytes.| value | None.| +| extra | Format of the current custom data. The value is the resource value of **extra**.| resource | The field name is changed. For details, see [Table 4](#table 4-metadata-examples).| + + +### Table 4 metaData examples + +| Example in the FA Model| Example in the Stage Model| +| -------- | -------- | +| "meteData": {
"customizeDate": [{
"name": "label",
"value": "string",
"extra": "$string:label",
}]
} | "meteData": [{
"name": "label",
"value": "string",
"resource": "$string:label",
}] | + + +### Table 5 abilities comparison + +| Field Name Under abilities in the FA Model| Field Description| Field Name Under abilities in the Stage Model| Difference| +| -------- | -------- | -------- | -------- | +| process | Name of the process running the application or ability.| / | The stage model does not support configuration of **process** under **abilities**. The configuration of **process** is available under the **module** tag.| +| uri | URI of the ability.| / | This configuration is not supported in the stage model.| +| deviceCapability | Device capabilities required to run the ability.| / | This configuration is not supported in the stage model.| +| metaData | Metadata of the ability.| metadata | See [Table 2](#table-2-metadata-comparison).| +| type | Ability type.| / | This configuration is not supported in the stage model.| +| grantPermission | Whether permissions can be granted for any data in the ability.| / | The stage model does not support such a configuration under **abilities**.| +| readPermission | Permission required for reading data in the ability. This field applies only to the ability using the Data template.| / | In the stage model, this configuration is available under **extensionAbilities**, but not **abilities**.| +| writePermission | Permission required for writing data to the ability.| / | In the stage model, this configuration is available under **extensionAbilities**, but not **abilities**.| +| configChanges | System configurations that the ability concerns.| / | This configuration is not supported in the stage model.| +| mission | Mission stack of the ability.| / | This configuration is not supported in the stage model.| +| targetAbility | Target ability that this ability alias points to.| / | This configuration is not supported in the stage model.| +| multiUserShared | Whether the ability supports data sharing among multiple users. This field applies only to the ability using the Data template.| / | This configuration is not supported in the stage model.| +| supportPipMode | Whether the ability allows the user to enter the Picture in Picture (PiP) mode. The PiP mode enables the user to watch a video in a small window that hovers on top of a full screen window (main window).| / | This configuration is not supported in the stage model.| +| formsEnabled | Whether the ability can provide widgets.| / | This configuration is not supported in the stage model.| +| forms | Information about the widgets used by the ability. This field is valid only when **formsEnabled** is set to **true**.| form_config.json| In the stage model, the **form_config.json** file is defined in **resources/base/profile** in the development view.| +| srcLanguage | Programming language used to develop the ability.| / | This configuration is not supported in the stage model.| +| srcPath | Path of the JS component code corresponding to the ability.| srcEntrance | Path of the JS code corresponding to the ability.| +| uriPermission | Application data that the ability can access.| / | This configuration is not supported in the stage model.| diff --git a/en/application-dev/application-models/page-mission-stack.md b/en/application-dev/application-models/page-mission-stack.md new file mode 100644 index 0000000000000000000000000000000000000000..702cb9ba928d5266ce6720d10538df6109b0cbeb --- /dev/null +++ b/en/application-dev/application-models/page-mission-stack.md @@ -0,0 +1,51 @@ +# Page Stack and MissionList + + +## Page Stack + +A single UIAbility component can implement multiple pages and redirection between these pages. The redirection relationship inside the UIAbility component is called page stack, which is managed by the ArkUI framework. For example, Page1 -> Page2 -> Page3 of UIAbility1 and PageA -> PageB -> PageC of UIAbility2 in the figure below are two page stacks. + + **Figure 1** Page stack +![mission-record](figures/mission-record.png) + +- A page stack is formed as follows (Steps 2, 3, 5, and 6 are page redirection and managed by ArkUI): + 1. Touch the icon on the home screen. The [startAbility](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartability) method is called to start UIAbility1, whose initial page is Page1. + + 2. Touch a button on Page1. The [Navigator](../reference/arkui-ts/ts-container-navigator.md) method is called to redirect you to Page2. + + 3. Touch a button on Page2. The [Navigator](../reference/arkui-ts/ts-container-navigator.md) method is called to redirect you to Page3. + + 4. Touch a button on Page3. The [startAbility](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartability) method is called to start UIAbility2, whose initial page is PageA. + + 5. Touch a button on PageA. The [Navigator](../reference/arkui-ts/ts-container-navigator.md) method is called to redirect you to PageB. + + 6. Touch a button on PageB. The [Navigator](../reference/arkui-ts/ts-container-navigator.md) method is called to redirect you to PageC. + +- The page stack return is as follows (Steps 1, 2, 4, and 5 are page redirection and managed by ArkUI): + 1. Touch the **Back** button on PageC of UIAbility2 to return to PageB. + + 2. Touch the **Back** button on PageB of UIAbility2 to return to PageA. + + 3. Touch the **Back** button on PageA of UIAbility2 to return to Page3 of UIAbility1. + + 4. Touch the **Back** button on Page3 of UIAbility1 to return to Page2. + + 5. Touch the **Back** button on Page2 of UIAbility1 to return to Page1 of UIAbility1. + + 6. Touch the **Back** button on Page1 of UIAbility1 to return to the home screen. + + +## MissionList + +As described above, you can keep touching the **Back** button on the page of Ability2 to return to a page of Ability1. The MissionList records the startup relationship between missions. If Ability1 starts Ability2 through **startAbility()**, a MissionList is formed: Ability1 -> Ability2. Therefore, when you touch the **Back** button on the initial page of Ability2, a page of Ability1 is displayed. + +The mission startup relationship recorded by the MissionList may be broken in the following cases: + +- A user moves a mission in the middle of the MissionList to the foreground. + ![mission-chain1](figures/mission-chain1.png) + +- A user deletes a mission in the MissionList. + ![mission-chain2](figures/mission-chain2.png) + +- A UIAbility singleton is repeatedly started by different missions. For example, AbilityB in the figure below is a singleton. + ![mission-chain3](figures/mission-chain3.png) diff --git a/en/application-dev/application-models/pageability-configuration.md b/en/application-dev/application-models/pageability-configuration.md new file mode 100644 index 0000000000000000000000000000000000000000..c11e7b17554844d21e024228bbec51e621d6383d --- /dev/null +++ b/en/application-dev/application-models/pageability-configuration.md @@ -0,0 +1,12 @@ +# PageAbility Component Configuration + + +The PageAbility is configured in **abilities** under **module** in the **config.json** file. The **icon** field indicates the index of the ability icon resource file, and the **label** field indicates the ability name presented to users, and the **skills** field indicates the type of Want that is acceptable to the ability. + +**Table 1** PageAbility configuration items + +| Name| Description| Data Type| Initial Value Allowed| +| -------- | -------- | -------- | -------- | +| icon | Index to the ability icon file. Example value: **$media:ability_icon**. In the **skills** attribute of the ability, if the **actions** value contains **action.system.home** and the **entities** value contains **entity.system.home**, the icon of the ability is also used as the icon of the application. If multiple abilities address this condition, the icon of the first candidate ability is used as the application icon.
Note: The **icon** and **label** values of an application are visible to users. Ensure that at least one of them is different from any existing icons or labels.| String| Yes (initial value: left empty)| +| label | Ability name visible to users. The value can be a name string or a resource index to names in multiple languages. In the **skills** attribute of the ability, if the **actions** value contains **action.system.home** and the **entities** value contains **entity.system.home**, the label of the ability is also used as the label of the application. If multiple abilities address this condition, the label of the first candidate ability is used as the application label.
Note: The **icon** and **label** values of an application are visible to users. Ensure that at least one of them is different from any existing icons or labels. The value can be a reference to a string defined in a resource file or a string enclosed in brackets ({}). The value can contain a maximum of 255 characters.| String| Yes (initial value: left empty)| +| skills | Types of the Want that can be accepted by the ability.| Object array| Yes (initial value: left empty)| diff --git a/en/application-dev/application-models/pageability-launch-type.md b/en/application-dev/application-models/pageability-launch-type.md new file mode 100644 index 0000000000000000000000000000000000000000..5241a7cabefbf3e68e6a3f413b8892ef5f6ff8d3 --- /dev/null +++ b/en/application-dev/application-models/pageability-launch-type.md @@ -0,0 +1,39 @@ +# PageAbility Launch Type + + +Depending on the launch type, the action performed when the PageAbility starts differs, as described in the table below. + +**Table 1** PageAbility launch types + +| Launch Type| Description| +| -------- | -------- | +| singleton | Each time **startAbility()** is called, if an ability instance of this type already exists in the application process, the instance is reused. There is only one ability instance of this type in **Recents**.
A typical scenario is as follows: When a user opens a video playback application and watches a video, returns to the home screen, and opens the video playback application again, the video that the user watched before returning to the home screen is still played.| +| standard | Default type. Each time **startAbility()** is called, a new ability instance is created in the application process. Multiple ability instances of this type are displayed in **Recents**.
A typical scenario is as follows: When a user opens a document application and touches **New**, a new document task is created. Multiple new document missions are displayed in **Recents**.| + + +You can set **launchType** in the **config.json** file to configure the launch type. The sample code is as follows: + +```json +{ + "module": { + // ... + "abilities": [ + { + // singleton mode. + // standard mode. + "launchType": "standard", + // ... + } + ] + } +} +``` + + +When the PageAbility is started for the first time (either in standard or singleton mode), the [PageAbility lifecycle callbacks](pageability-lifecycle.md#table13118194914476) are triggered. When it is not started for the first time in singleton mode, the **onNewWant()** callback (as described in the table below) is triggered, but the **onCreate()** callback is not. + +**Table 2** Callbacks specific to the singleton mode + +| API| Description| +| -------- | -------- | +| onNewWant(want: Want) | **onNewWant()** is triggered when the PageAbility is not started for the first time in singleton mode. You can obtain Want from this callback and perform further processing based on Want. For example, in the singleton PageAbility migration scenario, you can specify a page to start the PageAbility.| diff --git a/en/application-dev/application-models/pageability-lifecycle.md b/en/application-dev/application-models/pageability-lifecycle.md new file mode 100644 index 0000000000000000000000000000000000000000..3608346ec5403735a79fdf9a01478be9b86745d9 --- /dev/null +++ b/en/application-dev/application-models/pageability-lifecycle.md @@ -0,0 +1,45 @@ +# PageAbility Lifecycle + + +The PageAbility lifecycle defines all states of a PageAbility, such as **INACTIVE**, **ACTIVE**, and **BACKGROUND**. The figure below shows the lifecycle state transition. + +**Figure 1** PageAbility lifecycle + +![page-ability-lifecycle](figures/page-ability-lifecycle.png) + +**Table 1** PageAbility lifecycle states + +| State| Description| +| -------- | -------- | +| UNINITIALIZED | The PageAbility is not initialized. This is a temporary state, from which a PageAbility changes directly to the **INITIAL** state upon its creation.| +| INITIAL | The PageAbility is initialized but not running. The PageAbility enters the **INACTIVE** state after it is started.| +| INACTIVE | The PageAbility is visible but does not gain focus.| +| ACTIVE | The PageAbility runs in the foreground and has focus.| +| BACKGROUND | The PageAbility runs in the background. After being re-activated, the PageAbility enters the **ACTIVE** state. After being destroyed, it enters the **INITIAL** state.| + + +You can override the lifecycle callbacks (as described in the table below) in **app.js** or **app.ets**. + +**Table 2** PageAbility lifecycle callbacks + +| API| Description| +| -------- | -------- | +| onCreate() | Called when the ability is created for the first time. You can initialize the application in this callback.| +| onDestroy() | Called when the ability is destroyed. In this callback, you can make preparations for application exit, such as recycling resources and clearing the cache.| +| onActive() | Called when the ability is switched to the foreground and gains focus.| +| onInactive() | Called when the ability loses focus. An ability loses focus when it is about to enter the background state.| +| onShow() | Called when the ability is switched from the background to the foreground. In this case, the ability is visible to users.| +| onHide() | Called when the ability is switched from the foreground to the background. In this case, the ability is invisible to users.| + + +The following figure shows the relationship between lifecycle callbacks and lifecycle states of the PageAbility. + +Figure 2 Relationship between lifecycle callbacks and lifecycle states + +![fa-pageAbility-lifecycle](figures/fa-pageAbility-lifecycle.png) + + +> **NOTE** +> +> - The PageAbility lifecycle callbacks are synchronous. +> - The **app.js** file provides only the **onCreate** and **onDestroy** callbacks, and the **app.ets** file provides the full lifecycle callbacks. diff --git a/en/application-dev/application-models/pageability-overview.md b/en/application-dev/application-models/pageability-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..00370ca29056fcb8d23e93de54a38b2003bc6941 --- /dev/null +++ b/en/application-dev/application-models/pageability-overview.md @@ -0,0 +1,7 @@ +# PageAbility Component Overview + + +PageAbility is an application component that has the UI and supports user interaction. + + +When you create a PageAbility in DevEco Studio, DevEco Studio automatically creates template code. The capabilities related to the PageAbility are implemented through the **featureAbility** class, and the lifecycle callbacks are implemented through the callbacks in **app.js** or **app.ets**. diff --git a/en/application-dev/application-models/pageability-switch.md b/en/application-dev/application-models/pageability-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..1953c02c8067a38d1633ae9eb9f768dc60a87e0f --- /dev/null +++ b/en/application-dev/application-models/pageability-switch.md @@ -0,0 +1,56 @@ +# PageAbility Switching + + +The PageAbility component in the FA model corresponds to the UIAbility component in the stage model. To switch a PageAbility to a UIAbility, perform the following operations: + + +1. [Create a UIAbility](uiability-usage.md) in the stage model. + +2. Migrate the PageAbility code to the UIAbility. + +The PageAbility lifecycle is basically the same as the UIAbility lifecycle. The table below describes the details. + + | PageAbility| UIAbility| Mapping Description| + | -------- | -------- | -------- | + | onCreate(): void| onCreate(want: Want, param: AbilityConstant.LaunchParam): void | The two methods have the same meaning and invoking time. In the stage model, parameters are added to the callback so that you can obtain startup-related data during creation.| + | NA | onWindowStageCreate(windowStage: window.WindowStage): void| This method is available only in the stage model. The callback is invoked when a window is created.| + | onActive(): void | on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void;
WindowStageEventType.ACTIVE | The two methods have the same meaning and invoking time. In the stage model, this method is moved to the window object.| + | onShow(): void | onForeground(): void | The two methods have the same meaning, invoking time, and parameters.| + | onNewWant(want: Want): void| onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void| The two methods have the same meaning and invoking time. In the stage model, the **LaunchParam** parameter is added to notify the application of the startup cause.| + | onInactive(): void| on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void;
WindowStageEventType.INACTIVE | The two methods have the same meaning and invoking time. In the stage model, this method is moved to the window object.| + | onHide(): void | onBackground(): void | The two methods have the same meaning, invoking time, and parameters.| + | NA | onWindowStageDestroy(): void | This method is available only in the stage model. The callback is invoked when a window is destroyed.| +| onDestroy(): void | onDestroy(): void | The two methods have the same meaning, invoking time, and parameters.| + +![pageability-switch](figures/pageability-switch.png) + +3. Adjust the migrated code, since the methods of loading pages are different. + + - In the FA model, you can configure the page to be loaded by setting page information in **config.json**. + - In the stage model, you must call **windowStage.loadContent** in the **onWindowStageCreate** callback to load a page. + + For example, to load the **pages/Index** page after the ability is started, use the following code in the **config.json** file in the FA model: + + + ```json + "pages" : [ + "pages/Index" + ] + ``` + + In the stage model, implement the following method in **MainAbility**: + + + ```ts + import Window from '@ohos.window' + + onWindowStageCreate(windowStage: Window.WindowStage) { + // Main window is created. Set a main page for this ability. + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + console.error("loadContent failed") + return; + } + }); + } + ``` diff --git a/en/application-dev/application-models/particleability-switch.md b/en/application-dev/application-models/particleability-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..21ecd96c9a24f1328c20da14abf5cc8f8d079b95 --- /dev/null +++ b/en/application-dev/application-models/particleability-switch.md @@ -0,0 +1,12 @@ +# particleAbility Switching + + + | API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API in the Stage Model| +| -------- | -------- | -------- | +| [startAbility(parameter: StartAbilityParameter, callback: AsyncCallback<number>): void;](../reference/apis/js-apis-ability-particleAbility.md#particleabilitystartability)
[startAbility(parameter: StartAbilityParameter): Promise<number>;](../reference/apis/js-apis-ability-particleAbility.md#particleabilitystartability-1) | application\ServiceExtensionContext.d.ts | [startAbility(want: Want, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextstartability)
[startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextstartability-2)
[startAbility(want: Want, options?: StartOptions): Promise<void>;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextstartability-1)
[startServiceExtensionAbility(want: Want, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextstartserviceextensionability)
[startServiceExtensionAbility(want: Want): Promise<void>;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextstartserviceextensionability-1) | +| [terminateSelf(callback: AsyncCallback<void>): void;](../reference/apis/js-apis-ability-particleAbility.md#particleabilityterminateself)
[terminateSelf(): Promise<void>;](../reference/apis/js-apis-ability-particleAbility.md#particleabilityterminateself-1) | application\ServiceExtensionContext.d.ts | [terminateSelf(callback: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextterminateself)
[terminateSelf(): Promise<void>;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextterminateself-1) | +| [connectAbility(request: Want, options:ConnectOptions ): number;](../reference/apis/js-apis-ability-particleAbility.md#particleabilityconnectability) | application\ServiceExtensionContext.d.ts | [connectAbility(want: Want, options: ConnectOptions): number;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextconnectserviceextensionability)
[connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextconnectserviceextensionability) | +| [disconnectAbility(connection: number, callback:AsyncCallback<void>): void;](../reference/apis/js-apis-ability-particleAbility.md#particleabilitydisconnectability)
[disconnectAbility(connection: number): Promise<void>;](../reference/apis/js-apis-ability-particleAbility.md#particleabilitydisconnectability-1) | application\ServiceExtensionContext.d.ts | [disconnectAbility(connection: number, callback:AsyncCallback<void>): void; ](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextdisconnectserviceextensionability)
[disconnectAbility(connection: number): Promise<void>;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextdisconnectserviceextensionability-1)
[disconnectServiceExtensionAbility(connection: number, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextdisconnectserviceextensionability)
[disconnectServiceExtensionAbility(connection: number): Promise<void>;](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextdisconnectserviceextensionability-1) | +| [acquireDataAbilityHelper(uri: string): DataAbilityHelper;](../reference/apis/js-apis-ability-particleAbility.md#particleabilityacquiredataabilityhelper) | \@ohos.data.dataShare.d.ts
[\@ohos.data.fileAccess.d.ts | [createDataShareHelper(context: Context, uri: string, callback: AsyncCallback<DataShareHelper>): void;](../reference/apis/js-apis-data-dataShare.md#datasharecreatedatasharehelper)
[createDataShareHelper(context: Context, uri: string): Promise<DataShareHelper>;](../reference/apis/js-apis-data-dataShare.md#datasharecreatedatasharehelper-1)
[createFileAccessHelper(context: Context): FileAccessHelper;](../reference/apis/js-apis-fileAccess.md#fileaccesscreatefileaccesshelper-1)
[createFileAccessHelper(context: Context, wants: Array<Want>): FileAccessHelper;](../reference/apis/js-apis-fileAccess.md#fileaccesscreatefileaccesshelper) | +| [startBackgroundRunning(id: number, request: NotificationRequest, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-ability-particleAbility.md#particleabilitystartbackgroundrunning)
[startBackgroundRunning(id: number, request: NotificationRequest): Promise<void>;](../reference/apis/js-apis-ability-particleAbility.md#particleabilitystartbackgroundrunning-1) | \@ohos.resourceschedule.backgroundTaskManager.d.ts | [startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback): void;](../reference/apis/js-apis-resourceschedule-backgroundTaskManager.md#backgroundtaskmanagerstartbackgroundrunningcallback)
[startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise<void>;](../reference/apis/js-apis-resourceschedule-backgroundTaskManager.md#backgroundtaskmanagerstartbackgroundrunningpromise) | +| [cancelBackgroundRunning(callback: AsyncCallback<void>): void;](../reference/apis/js-apis-ability-particleAbility.md#particleabilitycancelbackgroundrunning)
[cancelBackgroundRunning(): Promise<void>;](../reference/apis/js-apis-ability-particleAbility.md#particleabilitycancelbackgroundrunning-1) | \@ohos.resourceschedule.backgroundTaskManager.d.ts | [stopBackgroundRunning(context: Context, callback: AsyncCallback): void;](../reference/apis/js-apis-resourceschedule-backgroundTaskManager.md#backgroundtaskmanagerstopbackgroundrunningcallback)
[stopBackgroundRunning(context: Context): Promise<void>;](../reference/apis/js-apis-resourceschedule-backgroundTaskManager.md#backgroundtaskmanagerstopbackgroundrunningpromise) | diff --git a/en/application-dev/application-models/process-model-fa.md b/en/application-dev/application-models/process-model-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..699643031121521fbf95d26a949df906fa175a18 --- /dev/null +++ b/en/application-dev/application-models/process-model-fa.md @@ -0,0 +1,22 @@ +# Process Model (FA Model) + + +The OpenHarmony process model is shown below. + + +- All PageAbility, ServiceAbility, DataAbility, and FormAbility components of an application (with the same bundle name) run in an independent process, which is **Main process** in green in the figure. + +- WebView has an independent rendering process, which is **Render process** in yellow in the figure. + + **Figure 1** Process model + + ![process-model-fa](figures/process-model-fa.png) + + +OpenHarmony provides two inter-process communication (IPC) mechanisms. + + +- [Common Events](common-event-fa.md): This mechanism is used in one-to-many communication scenarios. Multiple subscribers may receive events at the same time. + +- [Background Services](rpc.md): This mechanism is implemented through [ServiceAbility](serviceability-overview.md). + diff --git a/en/application-dev/application-models/process-model-stage.md b/en/application-dev/application-models/process-model-stage.md new file mode 100644 index 0000000000000000000000000000000000000000..bbfa0602aecb127c5e484f0ebbdcb166f81310f7 --- /dev/null +++ b/en/application-dev/application-models/process-model-stage.md @@ -0,0 +1,31 @@ +# Process Model (Stage Model) + + +The OpenHarmony process model is shown below. + + +- All UIAbility, ServiceExtensionAbility, and DataShareExtensionAbility components of an application (with the same bundle name) run in an independent process, which is **Main process** in green in the figure. + +- The ExtensionAbility components of the same type (except ServiceExtensionAbility and DataShareExtensionAbility) of an application (with the same bundle name) run in an independent process, which is **FormExtensionAbility process**, **InputMethodExtensionAbility process**, and other **ExtensionAbility process** in blue in the figure. + +- WebView has an independent rendering process, which is **Render process** in yellow in the figure. + + **Figure 1** Process model +![process-model](figures/process-model.png) + +> NOTE +> +> You can create ServiceExtensionAbility and DataShareExtensionAbility only for system applications. + +A system application can apply for multi-process permissions (as shown in the following figure) and configure a custom process for an HAP. UIAbility, DataShareExtensionAbility, and ServiceExtensionAbility in the HAP run in the custom process. Different HAPs run in different processes by configuring different process names. + +**Figure 2** Multi-process +![multi-process](figures/multi-process.png) + + +OpenHarmony provides two inter-process communication (IPC) mechanisms. + + +- [Common Events](common-event-overview.md): This mechanism is used in one-to-many communication scenarios. Multiple subscribers may receive events at the same time. + +- [Background Services](background-services.md): This mechanism is implemented through [ServiceExtensionAbility](serviceextensionability.md). diff --git a/en/application-dev/application-models/public_sys-resources/icon-caution.gif b/en/application-dev/application-models/public_sys-resources/icon-caution.gif new file mode 100644 index 0000000000000000000000000000000000000000..6e90d7cfc2193e39e10bb58c38d01a23f045d571 Binary files /dev/null and b/en/application-dev/application-models/public_sys-resources/icon-caution.gif differ diff --git a/en/application-dev/application-models/public_sys-resources/icon-danger.gif b/en/application-dev/application-models/public_sys-resources/icon-danger.gif new file mode 100644 index 0000000000000000000000000000000000000000..6e90d7cfc2193e39e10bb58c38d01a23f045d571 Binary files /dev/null and b/en/application-dev/application-models/public_sys-resources/icon-danger.gif differ diff --git a/en/application-dev/application-models/public_sys-resources/icon-note.gif b/en/application-dev/application-models/public_sys-resources/icon-note.gif new file mode 100644 index 0000000000000000000000000000000000000000..6314297e45c1de184204098efd4814d6dc8b1cda Binary files /dev/null and b/en/application-dev/application-models/public_sys-resources/icon-note.gif differ diff --git a/en/application-dev/application-models/public_sys-resources/icon-notice.gif b/en/application-dev/application-models/public_sys-resources/icon-notice.gif new file mode 100644 index 0000000000000000000000000000000000000000..86024f61b691400bea99e5b1f506d9d9aef36e27 Binary files /dev/null and b/en/application-dev/application-models/public_sys-resources/icon-notice.gif differ diff --git a/en/application-dev/application-models/public_sys-resources/icon-tip.gif b/en/application-dev/application-models/public_sys-resources/icon-tip.gif new file mode 100644 index 0000000000000000000000000000000000000000..93aa72053b510e456b149f36a0972703ea9999b7 Binary files /dev/null and b/en/application-dev/application-models/public_sys-resources/icon-tip.gif differ diff --git a/en/application-dev/application-models/public_sys-resources/icon-warning.gif b/en/application-dev/application-models/public_sys-resources/icon-warning.gif new file mode 100644 index 0000000000000000000000000000000000000000..6e90d7cfc2193e39e10bb58c38d01a23f045d571 Binary files /dev/null and b/en/application-dev/application-models/public_sys-resources/icon-warning.gif differ diff --git a/en/application-dev/application-models/redirection-rules.md b/en/application-dev/application-models/redirection-rules.md new file mode 100644 index 0000000000000000000000000000000000000000..c5c9987c261364f87dadc0333b310744fe12f971 --- /dev/null +++ b/en/application-dev/application-models/redirection-rules.md @@ -0,0 +1,36 @@ +# Redirection Rules + + +Generally, UI redirection within an application is triggered by users. However, an application can call **startAbility()** to implement UI redirection. + + +The PageAbility has a UI. It can use **startAbility()** to start an ability that has a UI and is visible to users. + + +The **visible** field under **abilities** in the **config.json** file specifies whether an ability can be started by other application components. + +**Table 1** Description of visible + +| Name| Description| Initial Value Allowed| +| -------- | -------- | -------- | +| visible | Whether the ability can be called by other applications.
**true**: The ability can be called by any application.
**false**: The ability can be called only by other components of the same application.| Yes (initial value: **false**)| + + +To enable an ability to be called by any application, configure the **config.json** file as follows: + +```ts +{ + "module": { + // ... + "abilities": [ + { + "visible": "true", + // ... + } + ] + } +} +``` + + +If the ability contains **skills**, you are advised to set **visible** to **true** so that the ability can be [implicitly started](explicit-implicit-want-mappings.md#interpretation-of-implicit-want-matching-rules) by other applications. If this attribute is set to **false**, the system returns **PERMISSION_DENIED** when other applications attempt to start the ability. In this case, a system application can request the [START_INVISIBLE_ABILITY](../security/permission-list.md) permission to start the ability. Example abilities with **visible** set to **false** are home screen, voice assistant, or search assistant. diff --git a/en/application-dev/application-models/request-permissions.md b/en/application-dev/application-models/request-permissions.md new file mode 100644 index 0000000000000000000000000000000000000000..670860d87dbb56adceb02f4ca350c24b61260d30 --- /dev/null +++ b/en/application-dev/application-models/request-permissions.md @@ -0,0 +1,45 @@ +# Requesting Permissions + + +If an application needs to obtain user privacy information or use system capabilities, for example, obtaining location information or using the camera to take photos or record videos, it must request the respective permission from users. + + +During application development, you must declare the required permission in the **config.json** file and call **requestPermissionsFromUser** to request the permission from users in the form of a dialog box. + + +To declare a permission in **config.json**, add **reqPermissions** under **module** and list the permission. + + +For example, to declare the permission to access the calendar, request the **ohos.permission.READ_CALENDAR** permission. For details, see [Permission Application Guide](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file). + + +The sample code in the **config.json** file is as follows: + +```json +{ + "module": { + // ... + "reqPermissions": [ + { + "name": "ohos.permission.READ_CALENDAR" + // ... + } + ] + } +} +``` + + +Request the permission from uses in the form of a dialog box: + +```ts +import featureAbility from '@ohos.ability.featureAbility'; + +let context = featureAbility.getContext(); +let permissions: Array = ['ohos.permission.READ_CALENDAR'] +context.requestPermissionsFromUser(permissions, 1).then((data) => { + console.info("Succeed to request permission from user with data: " + JSON.stringify(data)) +}).catch((error) => { + console.info("Failed to request permission from user with error: " + JSON.stringify(error)) +}) +``` diff --git a/en/application-dev/application-models/request-switch.md b/en/application-dev/application-models/request-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..5c9e2f49d48aaba203a6207de37992823ab5ae97 --- /dev/null +++ b/en/application-dev/application-models/request-switch.md @@ -0,0 +1,7 @@ +# request Switching + + + | API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API in the Stage Model| +| -------- | -------- | -------- | +| [download(config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;](../reference/apis//js-apis-request.md#requestdownload-1)
[download(config: DownloadConfig): Promise<DownloadTask>;](../reference/apis/js-apis-request.md#requestdownload) | \@ohos.request.d.ts | [downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;](../reference/apis/js-apis-request.md#requestdownloadfile9-1)
[downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>;](../reference/apis/js-apis-request.md#requestdownloadfile9) | +| [upload(config: UploadConfig, callback: AsyncCallback<UploadTask>): void;](../reference/apis/js-apis-request.md#requestupload-1)
[upload(config: UploadConfig): Promise<UploadTask>;](../reference/apis/js-apis-request.md#requestupload) | \@ohos.request.d.ts | [uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void;](../reference/apis/js-apis-request.md#requestuploadfile9-1)
[uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask>;](../reference/apis/js-apis-request.md#requestuploadfile9) | diff --git a/en/application-dev/application-models/resourcemanager-switch.md b/en/application-dev/application-models/resourcemanager-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..34eedb16597e30c76ccaed2c01a3b4c7206c0dfd --- /dev/null +++ b/en/application-dev/application-models/resourcemanager-switch.md @@ -0,0 +1,6 @@ +# resourceManager Switching + + + | API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding Field in the Stage Model| +| -------- | -------- | -------- | +| [getResourceManager(callback: AsyncCallback<ResourceManager>): void;](../reference/apis/js-apis-resource-manager.md#resourcemanagergetresourcemanager)
[getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void;](../reference/apis/js-apis-resource-manager.md#resourcemanagergetresourcemanager-1)
[getResourceManager(): Promise<ResourceManager>;](../reference/apis/js-apis-resource-manager.md#resourcemanagergetresourcemanager-2)
[getResourceManager(bundleName: string): Promise<ResourceManager>;](../reference/apis/js-apis-resource-manager.md#resourcemanagergetresourcemanager-3) | application\Context.d.ts | [resourceManager: resmgr.ResourceManager;](../reference/apis/js-apis-inner-application-context.md#attributes)| diff --git a/en/application-dev/application-models/rpc.md b/en/application-dev/application-models/rpc.md new file mode 100644 index 0000000000000000000000000000000000000000..69fd10c315c9f3ec007358dad86fef71c4363d53 --- /dev/null +++ b/en/application-dev/application-models/rpc.md @@ -0,0 +1,4 @@ +# Background Services (FA Model) + + +For details, see [Background Services](background-services.md) in the stage model. diff --git a/en/application-dev/application-models/serviceability-configuration.md b/en/application-dev/application-models/serviceability-configuration.md new file mode 100644 index 0000000000000000000000000000000000000000..a0bf139c2ec08382b73e1bce7bb87882a2306def --- /dev/null +++ b/en/application-dev/application-models/serviceability-configuration.md @@ -0,0 +1,17 @@ +# ServiceAbility Component Configuration + + +Similar to a PageAbility, a ServiceAbility is configured in **abilities** under **module** of the **config.json** file. The difference between a ServiceAbility and PageAbility lies in the **type** and **backgroundModes** fields. + + + **Table 1** ServiceAbility configuration items + +| Name| Description| Data Type| Initial Value Allowed| +| -------- | -------- | -------- | -------- | +| type | Type of the ability. The value **service** indicates that the ability is developed based on the Service template.| String| No| +| backgroundModes | Background service type of the ability. You can assign multiple background service types to a specific ability. This field applies only to the ability using the Service template. The value can be:
**dataTransfer**: service for downloading, backing up, sharing, or transferring data from the network or peer devices.
**audioPlayback**: audio playback service.
**audioRecording**: audio recording service.
**pictureInPicture**: picture in picture (PiP) and small-window video playback services.
**voip**: voice/video call and VoIP services.
**location**: location and navigation services.
**bluetoothInteraction**: Bluetooth scanning, connection, and transmission services.
**wifiInteraction**: WLAN scanning, connection, and transmission services.
**screenFetch**: screen recording and screenshot services.
**multiDeviceConnection**: multi-device interconnection service.| String array| Yes (initial value: left empty)| + + +For details about the configuration items, see [Internal Structure of module](../quick-start/module-structure.md). + + \ No newline at end of file diff --git a/en/application-dev/application-models/serviceability-lifecycle.md b/en/application-dev/application-models/serviceability-lifecycle.md new file mode 100644 index 0000000000000000000000000000000000000000..cc541c77ea0bec412eee09b7b7b3fe4e7e1008d0 --- /dev/null +++ b/en/application-dev/application-models/serviceability-lifecycle.md @@ -0,0 +1,15 @@ +# ServiceAbility Lifecycle + + +You can override lifecycle callbacks (described in the table below) for ServiceAbility based on service requirements. + + + **Table 1** ServiceAbility lifecycle callbacks + +| API| Description| +| -------- | -------- | +| onStart(): void | Called to initialize a ServiceAbility when the ServiceAbility is being created. This callback is invoked only once in the entire lifecycle of a ServiceAbility.| +| onCommand(want: Want, startId: number): void | Called every time a ServiceAbility is started on the client. You can collect calling statistics and perform initialization operations in this callback.| +| onConnect(want: Want): rpc.RemoteObject | Called when the ServiceAbility is connected.| +| onDisconnect(want: Want): void | Called when the connection to the ServiceAbility is disconnected.| +| onStop(): void | Called when the ServiceAbility is being destroyed. You should override this callback for your ServiceAbility to clear its resources, such as threads and registered listeners.| diff --git a/en/application-dev/application-models/serviceability-overview.md b/en/application-dev/application-models/serviceability-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..ba57633f7bd489dd75ddba4cf8d7e829fa97dae4 --- /dev/null +++ b/en/application-dev/application-models/serviceability-overview.md @@ -0,0 +1,4 @@ +# ServiceAbility Component Overview + + +An ability using the Service template (ServiceAbility for short) is used to run tasks in the background, such as playing music or downloading files. It does not provide a UI for user interaction. A ServiceAbility can be started by another application or a PageAbility. It remains to run in the background even after the user switches to another application. diff --git a/en/application-dev/application-models/serviceability-switch.md b/en/application-dev/application-models/serviceability-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..9752a4a11be4982ab65b4fc17262a39b6190b00b --- /dev/null +++ b/en/application-dev/application-models/serviceability-switch.md @@ -0,0 +1,35 @@ +# ServiceAbility Switching + + +The ServiceAbility component in the FA model corresponds to the ServiceExtensionAbility component in the stage model. The ServiceExtensionAbility class provides system APIs. Only system applications can create ServiceExtensionAbility instances. Therefore, ServiceAbility switching adopts different policies for system applications and third-party applications. + + +## Switching a ServiceAbility of a System Application + +The procedure for switching a ServiceAbility of a system application is similar to the procedure of PageAbility switching. + +1. [Create a ServiceExtensionAbility](serviceextensionability.md) in the stage model. + +2. Migrate the ServiceAbility code to the ServiceExtensionAbility. + +The table below describes the lifecycle comparison of the ServiceAbility and ServiceExtensionAbility. + + | ServiceAbility| ServiceExtensionAbility| Comparison Description| + | -------- | -------- | -------- | + | onStart(): void | onCreate(want: Want): void | The two methods have the same invoking time. In the stage model, the **want** parameter is added so that you can obtain parameters during creation.| + | onCommand(want: Want, startId: number): void | onRequest(want: Want, startId: number): void | The two methods have the same meaning, invoking time, and parameters.| + | onConnect(want: Want): rpc.RemoteObject | onConnect(want: Want): rpc.RemoteObject | The two methods have the same meaning, invoking time, and parameters.| + | onDisconnect(want: Want): void | onDisconnect(want: Want): void | The two methods have the same meaning, invoking time, and parameters.| + | onReconnect(want: Want): void| onReconnect(want: Want): void| The two methods have the same meaning, invoking time, and parameters.| + | onStop(): void | onDestroy(): void | The two methods have the same meaning, invoking time, and parameters.| + + +## Switching a ServiceAbility of a Third-Party Application + +In the stage model, third-party applications cannot provide services for other third-party applications. You can select a switching solution based on your service requirements. + +| Service Type| Switching Solution| +| -------- | -------- | +| Providing services for other third-party applications| Match a scenario-specific [ExtensionAbility](extensionability-overview.md).| +| In-application: providing public use when it is running in the foreground| Extract the component code as a common module for other components to use.| +| In-application: continuing running when it switches to the background| Switch the service to [a background service](serviceextensionability.md).| diff --git a/en/application-dev/application-models/serviceextensionability.md b/en/application-dev/application-models/serviceextensionability.md new file mode 100644 index 0000000000000000000000000000000000000000..6626bf66592f4fabb9abf890b163b9b392f04955 --- /dev/null +++ b/en/application-dev/application-models/serviceextensionability.md @@ -0,0 +1,296 @@ +# ServiceExtensionAbility + +[ServiceExtensionAbility](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md) is an ExtensionAbility component of the service type that provides extension capabilities related to background services. + + +ServiceExtensionAbility can be started or connected by other application components to process transactions in the background based on the request of the caller. System applications can call the [startServiceExtensionAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartserviceextensionability) method to start background services or call the [connectServiceExtensionAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextconnectserviceextensionability) method to connect to background services. Third-party applications can call only **connectServiceExtensionAbility()** to connect to background services. The differences between starting and connecting to background services are as follows: + + +- In the case that AbilityA starts ServiceB, they are weakly associated. After AbilityA exits, ServiceB can still exist. + +- In the case that AbilityA connects to ServiceB, they are strongly associated. After AbilityA exits, ServiceB also exits. + + +Each type of ExtensionAbility has its own context. ServiceExtensionAbility has [ServiceExtensionContext](../reference/apis/js-apis-inner-application-serviceExtensionContext.md). In this document, the started ServiceExtensionAbility component is called the server, and the component that starts ServiceExtensionAbility is called the client. + + +This topic describes how to use ServiceExtensionAbility in the following scenarios: + + +- [Implementing a Background Service](#implementing-a-background-service) + +- [Starting a Background Service](#starting-a-background-service) + +- [Connecting to a Background Service](#connecting-to-a-background-service) + + +> **NOTE** +> - OpenHarmony does not support third-party applications in implementing ServiceExtensionAbility. If you want to implement transaction processing in the background, use background tasks. For details, see [Background Task](../task-management/background-task-overview.md). +> +> - UIAbility of a third-party application can connect to ServiceExtensionAbility provided by the system through the context. +> +> - Third-party applications can connect to ServiceExtensionAbility provided by the system only when they gain focus in the foreground. + + +## Implementing a Background Service + +This feature applies only to system applications. [ServiceExtensionAbility](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md) provides the callbacks **onCreate()**, **onRequest()**, **onConnect()**, **onDisconnect()**, and **onDestory()**. Override them as required. The following figure shows the lifecycle of ServiceExtensionAbility. + + **Figure 1** ServiceExtensionAbility lifecycle +![ServiceExtensionAbility-lifecycle](figures/ServiceExtensionAbility-lifecycle.png) + +- **onCreate** + + +This callback is triggered when a service is created for the first time. You can perform initialization operations, for example, registering a common event listener. + + > **NOTE** +> + > If a service has been created, starting it again does not trigger the **onCreate()** callback. + +- **onRequest** + + +This callback is triggered when another component calls the **startServiceExtensionAbility()** method to start the service. After being started, the service runs in the background. + +- **onConnect** + + +This callback is triggered when another component calls the **connectServiceExtensionAbility()** method to connect to the service. In this method, a remote proxy object (IRemoteObject) is returned, through which the client communicates with the server by means of RPC. + +- **onDisconnect** + + +This callback is triggered when a component calls the **disconnectServiceExtensionAbility()** method to disconnect from the service. + +- **onDestroy** + + This callback is triggered when the service is no longer used and the instance is ready for destruction. You can clear resources in this callback, for example, deregister the listener. + + +## How to Develop + +To implement a background service, manually create a ServiceExtensionAbility component in DevEco Studio. The procedure is as follows: + +1. In the **ets** directory of the **Module** project, right-click and choose **New > Directory** to create a directory named **serviceextability**. + +2. In the **serviceextability** directory, right-click and choose **New > TypeScript File** to create a file named **ServiceExtAbility.ts**. + +3. Open the **ServiceExtAbility.ts** file, import the [RPC module](../reference/apis/js-apis-rpc.md), and reload the **onRemoteMessageRequest()** method to receive messages from the client and return the processing result to the client. **REQUEST_VALUE** is used to verify the service request code sent by the client. + + ```ts + import rpc from '@ohos.rpc'; + + const REQUEST_CODE = 99; + + class StubTest extends rpc.RemoteObject { + constructor(des) { + super(des); + } + + // Receive a message from the client and return the processing result to the client. + onRemoteMessageRequest(code, data, reply, option) { + if (code === REQUEST_CODE) { + // Receive data from the client. + // If the client calls data.writeInt() multiple times to write multiple pieces of data, the server can call data.readInt() multiple times to receive all the data. + let optFir = data.readInt(); + let optSec = data.readInt(); + // The server returns the data processing result to the client. + // In the example, the server receives two pieces of data and returns the sum of the two pieces of data to the client. + reply.writeInt(optFir + optSec); + } + return true; + } + + // Send messages to the client in synchronous or asynchronous mode. + sendRequest(code, data, reply, options) { + return null; + } + } + ``` + +4. In the **ServiceExtAbility.ts** file, add the dependency package for importing ServiceExtensionAbility. Customize a class that inherits from ServiceExtensionAbility and add the required lifecycle callbacks. + + ```ts + import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; + import rpc from '@ohos.rpc'; + + const TAG: string = "[Example].[Entry].[ServiceExtAbility]"; + const REQUEST_CODE = 99; + + class StubTest extends rpc.RemoteObject { + // ... + } + + 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}`); + } + + onConnect(want) { + console.info(TAG, `onConnect, want: ${want.abilityName}`); + return new StubTest("test"); + } + + onDisconnect(want) { + console.info(TAG, `onDisconnect, want: ${want.abilityName}`); + } + + onDestroy() { + console.info(TAG, `onDestroy`); + } + } + ``` + +5. Register ServiceExtensionAbility in the [module.json5 file](../quick-start/module-configuration-file.md) corresponding to the **Module** project. Set **type** to **"service"** and **srcEntrance** to the code path of the ExtensionAbility component. + + ```json + { + "module": { + // ... + "extensionAbilities": [ + { + "name": "ServiceExtAbility", + "icon": "$media:icon", + "description": "service", + "type": "service", + "visible": true, + "srcEntrance": "./ets/serviceextability/ServiceExtAbility.ts" + } + ] + } + } + ``` + + +## Starting a Background Service + +This feature applies only to system applications. A system application uses the [startServiceExtensionAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartserviceextensionability) method to start a background service. The [onRequest()](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md#serviceextensionabilityonrequest) callback is invoked, and the **Want** object passed by the caller is received through the callback. After the background service is started, its lifecycle is independent of that of the client. In other words, even if the client is destroyed, the background service can still run. Therefore, the background service must be stopped by calling [terminateSelf()](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextterminateself) when its work is complete. Alternatively, another component can call [stopServiceExtensionAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstopserviceextensionability) to stop the background service. + +> **NOTE** +> +> [startServiceExtensionAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartserviceextensionability), [stopServiceExtensionAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstopserviceextensionability), and [terminateSelf()](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextterminateself) of ServiceExtensionContext are system APIs and cannot be called by third-party applications. + +1. Start a new ServiceExtensionAbility in a system application. For details about how to obtain the context, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability). + + ```ts + let want = { + "deviceId": "", + "bundleName": "com.example.myapplication", + "abilityName": "ServiceExtAbility" + }; + this.context.startServiceExtensionAbility(want).then(() => { + console.info('startServiceExtensionAbility success'); + }).catch((error) => { + console.info('startServiceExtensionAbility failed'); + }) + ``` + +2. Stop ServiceExtensionAbility in the system application. + + ```ts + let want = { + "deviceId": "", + "bundleName": "com.example.myapplication", + "abilityName": "ServiceExtAbility" + }; + this.context.stopServiceExtensionAbility(want).then(() => { + console.info('stopServiceExtensionAbility success'); + }).catch((error) => { + console.info('stopServiceExtensionAbility failed'); + }) + ``` + +3. ServiceExtensionAbility stops itself. + + ```ts + // this is the current ServiceExtensionAbility component. + this.context.terminateSelf().then(() => { + console.info('terminateSelf success'); + }).catch((error) => { + console.info('terminateSelf failed'); + }) + ``` + + +> **NOTE** +> +> Background services can run in the background for a long time. To minimize resource usage, destroy it in time when a background service finishes the task of the requester. A background service can be stopped in either of the following ways: +> +> - The background service calls the [terminateSelf()](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextterminateself) method to automatically stop itself. +> +> - Another component calls the [stopServiceExtensionAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstopserviceextensionability) method to stop the background service. +> +> After either method is called, the system destroys the background service. + + +## Connecting to a Background Service + +Either a system application or a third-party application can connect to a service (service specified in the **Want** object) through [connectServiceExtensionAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextconnectserviceextensionability). The [onConnect()](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md#serviceextensionabilityonconnect) callback is invoked, and the **Want** object passed by the caller is received through the callback. In this way, a persistent connection is established. + +The ServiceExtensionAbility component returns an IRemoteObject in the **onConnect()** callback. Through this IRemoteObject, you can define communication interfaces for RPC interaction between the client and server. Multiple clients can connect to the same background service at the same time. After a client finishes the interaction, it must call [disconnectServiceExtensionAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextdisconnectserviceextensionability) to disconnect from the service. If all clients connected to a background service are disconnected, the system destroys the service. + +- Call **connectServiceExtensionAbility()** to establish a connection to a background service. For details about how to obtain the context, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability). + + ```ts + import rpc from '@ohos.rpc'; + + const REQUEST_CODE = 99; + let want = { + "deviceId": "", + "bundleName": "com.example.myapplication", + "abilityName": "ServiceExtAbility" + }; + let options = { + onConnect(elementName, remote) { + console.info('onConnect callback'); + if (remote === null) { + console.info(`onConnect remote is null`); + return; + } + let option = new rpc.MessageOption(); + let data = new rpc.MessageParcel(); + let reply = new rpc.MessageParcel(); + data.writeInt(100); + data.writeInt(200); + + // @param code Indicates the service request code sent by the client. + // @param data Indicates the {@link MessageParcel} object sent by the client. + // @param reply Indicates the response message object sent by the remote service. + // @param options Specifies whether the operation is synchronous or asynchronous. + // + // @return Returns {@code true} if the operation is successful; returns {@code false} otherwise. + remote.sendRequest(REQUEST_CODE, data, reply, option).then((ret) => { + let msg = reply.readInt(); + console.info(`sendRequest ret:${ret} msg:${msg}`); + }).catch((error) => { + console.info('sendRequest failed'); + }); + }, + onDisconnect(elementName) { + console.info('onDisconnect callback') + }, + onFailed(code) { + console.info('onFailed callback') + } + } + // The ID returned after the connection is set up must be saved. The ID will be passed for service disconnection. + let connectionId = this.context.connectServiceExtensionAbility(want, options); + ``` + +- Use **disconnectServiceExtensionAbility()** to disconnect from the background service. + + ```ts + let connectionId = 1 // ID returned when the service is connected through connectServiceExtensionAbility. + this.context.disconnectServiceExtensionAbility(connectionId).then((data) => { + console.info('disconnectServiceExtensionAbility success'); + }).catch((error) => { + console.error('disconnectServiceExtensionAbility failed'); + }) + ``` + + \ No newline at end of file diff --git a/en/application-dev/application-models/stage-model-development-overview.md b/en/application-dev/application-models/stage-model-development-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..139a27e2151cd3141bd7a0dd3a93c3c90929bf2a --- /dev/null +++ b/en/application-dev/application-models/stage-model-development-overview.md @@ -0,0 +1,43 @@ +# Stage Model Development Overview + + +## Basic Concepts + +The following figure shows the basic concepts used in the stage model. + +**Figure 1** Concepts used in the stage model +![stage-concepts](figures/stage-concepts.png) + +- [UIAbility component](uiability-overview.md) and [ExtensionAbility component](extensionability-overview.md) + + The stage model provides two types of application components: UIAbility and ExtensionAbility. Both have specific classes and support object-oriented development. They are the specific implementation of the abstract ability concept on the stage model. They are also units scheduled by the Ability Manager Service (AMS), which schedules their lifecycles as well. + + - UIAbility has the UI and is mainly used for user interaction. For example, with UIAbility, the Gallery application can display images in the liquid layout. After a user selects an image, it uses a new UI to display the image details. The user can touch the **Back** button to return to the liquid layout. The lifecycle of the UIAbility component contains the creation, destruction, foreground, and background states. Display-related states are exposed through WindowStage events. + + - ExtensionAbility is oriented to specific scenarios. You cannot derive directly from ExtensionAbility. Instead, use the derived classes of ExtensionAbility for your scenarios, such as FormExtensionAbility for widget scenarios, InputMethodExtensionAbility for input method scenarios, and WorkSchedulerExtensionAbility for Work Scheduled task scenarios. For example, to enable a user to create an application widget on the home screen, you must derive FormExtensionAbility, implement the callback functions, and configure the capability in the configuration file. The derived class instances are created by developers and their lifecycles are managed by the system. In the stage model, you must use the derived classes of ExtensionAbility to develop custom services based on your service scenarios. +- [WindowStage](../windowmanager/application-window-stage.md) + + Each UIAbility class instance is bound to a WindowStage class instance, which functions as the window manager in the application process. The WindowStage class instance contains a main window. That is, UIAbility holds a window through WindowStage, and this window provides an area for ArkUI to render. + +- [Context](application-context-stage.md) + + In the stage model, Context and its derived classes provide a variety of capabilities that can be called during the runtime. The UIAbility component and ExtensionAbility derived classes have different Context classes. These classes, which all inherit from the base class Context, provide different capabilities. + +- [AbilityStage](abilitystage.md) + + Each HAP of the Entry or Feature type has an AbilityStage class instance during the runtime. When the code in the HAP is loaded to the process for the first time, the system creates an AbilityStage class instance first. Each UIAbility class defined in the HAP is associated with this class instance after instantiation. Through this class instance, you can obtain the runtime information of the UIAbility instances in the HAP. + + +## How to Develop + +During application development based on the stage model, the following tasks are involved in the application model. + + **Table 1** Stage model development process + +| Task| Introduction| Guide| +| -------- | -------- | -------- | +| Application component development| Use the UIAbility and ExtensionAbility components of the stage model to develop applications.| - [Application- or Component-Level Configuration](application-component-configuration-stage.md)
- [UIAbility Component](uiability-overview.md)
- [ExtensionAbility Component](extensionability-overview.md)
- [AbilityStage Container Component](abilitystage.md)
- [Context](application-context-stage.md)
- [Component Startup Rules](component-startup-rules.md) | +| Inter-process communication (IPC)| Learn the process model and common IPC modes of the stage model.| - [Common Events](common-event-overview.md)
- [Background Services](background-services.md)| +| Inter-thread communication| Learn the thread model and common inter-thread communication modes of the stage model.| - [Emitter](itc-with-emitter.md)
- [Worker](itc-with-worker.md)| +| Mission management| Learn the basic concepts and typical scenarios of mission management in the stage model.| - [Mission Management Scenarios](mission-management-overview.md)
- [Mission Management and Launch Type](mission-management-launch-type.md)
- [Page Stack and MissionList](page-mission-stack.md) | +| Application configuration file| Learn the requirements for developing application configuration files in the stage model.| [Application Configuration File](config-file-stage.md) | diff --git a/en/application-dev/application-models/start-dataability.md b/en/application-dev/application-models/start-dataability.md new file mode 100644 index 0000000000000000000000000000000000000000..786a14f91007672e395ed5b754fbaeccb55b3770 --- /dev/null +++ b/en/application-dev/application-models/start-dataability.md @@ -0,0 +1,12 @@ +# Starting a DataAbility + + +When a DataAbility is started, a **DataAbilityHelper** object is obtained. The sample code for starting a DataAbility is as follows: + +```ts +// Different from the URI defined in the config.json file, the URI passed in the parameter has an extra slash (/), three slashes in total. +import featureAbility from '@ohos.ability.featureAbility' + +let urivar = "dataability:///com.ix.DataAbility" +let DAHelper = featureAbility.acquireDataAbilityHelper(urivar); +``` diff --git a/en/application-dev/application-models/start-local-pageability.md b/en/application-dev/application-models/start-local-pageability.md new file mode 100644 index 0000000000000000000000000000000000000000..d8344820078bcdd52c2d92b1b406dfabf9253a35 --- /dev/null +++ b/en/application-dev/application-models/start-local-pageability.md @@ -0,0 +1,35 @@ +# Starting a Local PageAbility + + +The capabilities related to the PageAbility are provided through the **featureAbility** class. For example, **startAbility()** in **featureAbility** is used to the PageAbility. + +**Table 1** featureAbility APIs + +| API| Description| +| -------- | -------- | +| startAbility(parameter: StartAbilityParameter) | Starts an ability.| +| startAbilityForResult(parameter: StartAbilityParameter) | Starts an ability and returns the execution result when the ability is terminated.| + + +The following code snippet shows how to explicitly start a PageAbility through **startAbility()**. The parameters passed in for starting an ability include **want**. For details about the **want** parameter as well as implicit startup and explicit startup, see [Want](want-fa.md). + +```ts +import featureAbility from '@ohos.ability.featureAbility' +(async () => { + try { + console.info('Begin to start ability') + let param = { + want: { + bundleName: "com.example.myapplication", + moduleName: "entry", + abilityName: "com.example.myapplication.MainAbility" + } + } + await featureAbility.startAbility(param) + console.info(`Start ability succeed`) + } + catch (error) { + console.error('Start ability failed with ' + error) + } +})() +``` diff --git a/en/application-dev/application-models/start-page.md b/en/application-dev/application-models/start-page.md new file mode 100644 index 0000000000000000000000000000000000000000..adf814355974157f579b809be6583d9b7a713d70 --- /dev/null +++ b/en/application-dev/application-models/start-page.md @@ -0,0 +1,142 @@ +# Starting a Specified Page + + +When the launch type of a PageAbility is set to **singleton** (default), the **onNewWant()** callback is triggered if the PageAbility is not started for the first time. For details about the launch type, see [PageAbility Launch Type](pageability-launch-type.md). In this case, you can use the **want** parameter to transfer startup information. For example, if you want to start a PageAbility with a specified page, pass the pages information in **parameters** of **want**. + + +In **app.ets** or **page** of the caller PageAbility, use **startAbility()** to start the PageAbility again, with the page information passed in the **uri** parameter in **want**. + +```ts +import featureAbility from '@ohos.ability.featureAbility'; + +async function restartAbility() { + let wantInfo = { + bundleName: "com.sample.MyApplication", + abilityName: "MainAbility", + parameters: { + page: "pages/second" + } + }; + featureAbility.startAbility({ + want: wantInfo + }).then((data) => { + console.info('restartAbility success.'); + }); +} +``` + + +Obtain the **want** parameter that contains the page information from the **onNewWant()** callback of the target PageAbility. + +```ts +export default { + onNewWant(want) { + globalThis.newWant = want + } +} +``` + + +Obtain the **want** parameter that contains the page information from the custom component of the target PageAbility and process the route based on the URI. + +```ts +import router from '@ohos.router' +@Entry +@Component +struct Index { + @State message: string = 'Router Page' + newWant = undefined + onPageShow() { + console.info('Index onPageShow') + let newWant = globalThis.newWant + if (newWant.hasOwnProperty("page")) { + router.push({ url: newWant.page }); + globalThis.newWant = undefined + } + } + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} +``` + + +When the launch type of a PageAbility is set to **standard** or when the PageAbility with the launch type set to **singleton** is started for the first time, you can use the **parameters** parameter in **want** to transfer the pages information and use the **startAbility()** method to start the PageAbility. For details about the launch type, see [PageAbility Launch Type](pageability-launch-type.md). The target PageAbility can use the **featureAbility.getWant()** method in **onCreate** to obtain the **want** parameter, and then call **router.push** to start a specified page. + + +When a user touches the button on the page of the caller PageAbility, the **startAbility()** method is called to start the target PageAbility. The **want** parameter in **startAbility()** carries the specified page information. + +```ts +import featureAbility from '@ohos.ability.featureAbility' +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + // ... + Button("startAbility") + .onClick(() => { + featureAbility.startAbility({ + want: { + bundleName: "com.exm.myapplication", + abilityName: "com.exm.myapplication.MainAbility", + parameters: { page: "pages/page1" } + } + }).then((data) => { + console.info("startAbility finish"); + }).catch((err) => { + console.info("startAbility failed errcode:" + err.code) + }) + }) + // ... + Button("page2") + .onClick(() => { + featureAbility.startAbility({ + want: { + bundleName: "com.exm.myapplication", + abilityName: "com.exm.myapplication.MainAbility", + parameters: { page: "pages/page2" } + } + }).then((data) => { + console.info("startAbility finish"); + }).catch((err) => { + console.info("startAbility failed errcode:" + err.code) + }) + }) + // ... + } +} +``` + + +In the **onCreate()** callback of the target PageAbility, use the **featureAbility.getWant()** method to obtain the **want** parameter, parse the parameter, and start the specified page. + +```ts +import featureAbility from '@ohos.ability.featureAbility'; +import router from '@ohos.router'; + +export default { + onCreate() { + featureAbility.getWant().then((want) => { + if (want.parameters.page) { + router.push({ + url: want.parameters.page + }) + } + }) + }, + onDestroy() { + // ... + }, +} +``` diff --git a/en/application-dev/application-models/start-pageability-from-stage.md b/en/application-dev/application-models/start-pageability-from-stage.md new file mode 100644 index 0000000000000000000000000000000000000000..f3a09f4af4613e2ad963b8e0aba1596ba6903c67 --- /dev/null +++ b/en/application-dev/application-models/start-pageability-from-stage.md @@ -0,0 +1,122 @@ +# Starting a PageAbility from the Stage Model + + +This topic describes how the two application components of the stage model start the PageAbility component of the FA model. + + +## UIAbility Starting a PageAbility + +A UIAbility starts a PageAbility in the same way as it starts another UIAbility. + +```ts +import UIAbility from '@ohos.app.ability.UIAbility' + +export default class MainAbility extends UIAbility { + onCreate(want, launchParam) { + console.info("MainAbility onCreate") + } + onDestroy() { + console.info("MainAbility onDestroy") + } + onWindowStageCreate(windowStage) { + console.info("MainAbility onWindowStageCreate") + windowStage.loadContent('pages/Index', (err, data) => { + // ... + }); + let want = { + bundleName: "com.ohos.fa", + abilityName: "MainAbility", + }; + this.context.startAbility(want).then(() => { + console.info('Start Ability successfully.'); + }).catch((error) => { + console.error("Ability failed: " + JSON.stringify(error)); + }); + } + onWindowStageDestroy() { + console.info("MainAbility onWindowStageDestroy") + } + onForeground() { + console.info("MainAbility onForeground") + } + onBackground() { + console.info("MainAbility onBackground") + } +} +``` + + +## UIAbility Accessing a PageAbility (startAbilityForResult) + +Different from **startAbility()**, **startAbilityForResult()** obtains the execution result when the PageAbility is destroyed. + +A UIAbility starts a PageAbility through **startAbilityForResult()** in the same way as it starts another UIAbility through **startAbilityForResult()**. + + +```ts +import UIAbility from '@ohos.app.ability.UIAbility' + +export default class MainAbility extends UIAbility { + onCreate(want, launchParam) { + console.info("MainAbility onCreate") + } + onDestroy() { + console.info("MainAbility onDestroy") + } + onWindowStageCreate(windowStage) { + console.info("MainAbility onWindowStageCreate") + windowStage.loadContent('pages/Index', (err, data) => { + // ... + }); + let want = { + bundleName: "com.ohos.fa", + abilityName: "MainAbility", + }; + this.context.startAbilityForResult(want).then((result) => { + console.info('Ability verify result: ' + JSON.stringify(result)); + }).catch((error) => { + console.error("Ability failed: " + JSON.stringify(error)); + }); + } + onWindowStageDestroy() { + console.info("MainAbility onWindowStageDestroy") + } + onForeground() { + console.info("MainAbility onForeground") + } + onBackground() { + console.info("MainAbility onBackground") + } +} +``` + + +## ExtensionAbility Starting a PageAbility + +The following uses the ServiceExtensionAbility component as an example to describe how an ExtensionAbility starts a PageAbility. A ServiceExtensionAbility starts a PageAbility in the same way as it starts a UIAbility. + + +```ts +import Extension from '@ohos.app.ability.ServiceExtensionAbility' + +export default class ServiceExtension extends Extension { + onCreate(want) { + console.info("ServiceExtension onCreate") + } + onDestroy() { + console.info("ServiceExtension onDestroy") + } + onRequest(want, startId) { + console.info("ServiceExtension onRequest") + let wantFA = { + bundleName: "com.ohos.fa", + abilityName: "MainAbility", + }; + this.context.startAbility(wantFA).then(() => { + console.info('Start Ability successfully.'); + }).catch((error) => { + console.error("Ability failed: " + JSON.stringify(error)); + }); + } +} +``` diff --git a/en/application-dev/application-models/start-remote-pageability.md b/en/application-dev/application-models/start-remote-pageability.md new file mode 100644 index 0000000000000000000000000000000000000000..54f370aa454019d3568c6048649d5fca4003d777 --- /dev/null +++ b/en/application-dev/application-models/start-remote-pageability.md @@ -0,0 +1,136 @@ +# Starting a Remote PageAbility + + +This feature applies only to system applications. The **startAbility()** method in the **featureAbility** class is used to start a remote PageAbility. + + +In addition to **'\@ohos.ability.featureAbility'**, you must import **'\@ohos.distributedHardware.deviceManager'**, which provides account-independent distributed device networking capabilities. Then you can use **getTrustedDeviceListSync** of the **DeviceManager** module to obtain the remote device ID and pass the remote device ID in the **want** parameter for starting the remote PageAbility. + + +The **getTrustedDeviceListSync** method is available only for system applications. Therefore, non-system applications cannot obtain remote device information or start a remote ability. + +**Table 1** featureAbility APIs + +| API| Description| +| -------- | -------- | +| startAbility(parameter: StartAbilityParameter)| Starts an ability.| +| startAbilityForResult(parameter: StartAbilityParameter)| Starts an ability and returns the execution result when the ability is terminated.| + +**Table 2** deviceManager APIs + +| API| Description| +| -------- | -------- | +| getTrustedDeviceListSync(): Array<DeviceInfo> | Obtains all trusted devices synchronously.| + + +In the cross-device scenario, before starting a remote PageAbility, you must request the data synchronization permission. The related APIs are described in the table below. + +**Table 3** AtManager APIs + +| API| Description| +| -------- | -------- | +| checkAccessToken(tokenID: number, permissionName: string): Promise<GrantStatus> | Verifies whether a permission is granted to an application. This API uses a promise to return the result **GrantStatus**. You are advised to use **checkAccessToken** instead of **verifyAccessToken**, which is deprecated since API version 9.| + +**Table 4** context APIs + +| API| Description| +| -------- | -------- | +| requestPermissionsFromUser(permissions: Array<string>, requestCode: number, resultCallback: AsyncCallback< PermissionRequestResult>): void | Requests permissions from the system. This API uses an asynchronous callback to return the result. For details, see [API Reference](../reference/apis/js-apis-inner-app-context.md#contextrequestpermissionsfromuser7-1).| + + +The following sample code shows how to request the data synchronization permission from users: + +```ts +import abilityAccessCtrl from "@ohos.abilityAccessCtrl"; +import featureAbility from '@ohos.ability.featureAbility'; +import bundle from '@ohos.bundle.bundleManager'; +async function RequestPermission() { + console.info('RequestPermission begin'); + let array: Array = ["ohos.permission.DISTRIBUTED_DATASYNC"]; + let bundleFlag = 0; + let tokenID = undefined; + let userID = 100; + let appInfo = await bundle.getApplicationInfo('ohos.samples.etsDemo', bundleFlag, userID); + tokenID = appInfo.accessTokenId; + let atManager = abilityAccessCtrl.createAtManager(); + let requestPermissions: Array = []; + for (let i = 0;i < array.length; i++) { + let result = await atManager.verifyAccessToken(tokenID, array[i]); + console.info("checkAccessToken result:" + JSON.stringify(result)); + if (result != abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { + requestPermissions.push(array[i]); + } + } + console.info("requestPermissions:" + JSON.stringify(requestPermissions)); + if (requestPermissions.length == 0 || requestPermissions == []) { + return; + } + let context = featureAbility.getContext(); + context.requestPermissionsFromUser(requestPermissions, 1, (error, data)=>{ + console.info("data:" + JSON.stringify(data)); + console.info("data requestCode:" + data.requestCode); + console.info("data permissions:" + data.permissions); + console.info("data authResults:" + data.authResults); + }); + console.info('RequestPermission end'); +} +``` + + +After obtaining the data synchronization permission, obtain the trusted device list for device selection. + + +The following sample code shows how to use **getTrustedDeviceListSync()** to obtain the trusted device list. + +```ts +import deviceManager from '@ohos.distributedHardware.deviceManager'; +let dmClass; +function getDeviceManager() { + deviceManager.createDeviceManager('ohos.example.distributedService', (error, dm) => { + if (error) { + console.info('create device manager failed with ' + error) + } + dmClass = dm; + }) +} +function getRemoteDeviceId() { + if (typeof dmClass === 'object' && dmClass != null) { + let list = dmClass.getTrustedDeviceListSync(); + if (typeof (list) == 'undefined' || typeof (list.length) == 'undefined') { + console.info("MainAbility onButtonClick getRemoteDeviceId err: list is null"); + return; + } + console.info("MainAbility onButtonClick getRemoteDeviceId success:" + list[0].deviceId); + return list[0].deviceId; + } else { + console.info("MainAbility onButtonClick getRemoteDeviceId err: dmClass is null"); + } +} +``` + + +After a device is selected, call **startAbility()** to explicitly start the remote PageAbility. + + +The following sample code shows how to explicitly start a remote PageAbility through **startAbility()**. + +```ts +import featureAbility from '@ohos.ability.featureAbility'; +function onStartRemoteAbility() { + console.info('onStartRemoteAbility begin'); + let params; + let wantValue = { + bundleName: 'ohos.samples.etsDemo', + abilityName: 'ohos.samples.etsDemo.RemoteAbility', + deviceId: getRemoteDeviceId(), // getRemoteDeviceId is defined in the preceding sample code. + parameters: params + }; + console.info('onStartRemoteAbility want=' + JSON.stringify(wantValue)); + featureAbility.startAbility({ + want: wantValue + }).then((data) => { + console.info('onStartRemoteAbility finished, ' + JSON.stringify(data)); + }); + console.info('onStartRemoteAbility end'); +} +``` diff --git a/en/application-dev/application-models/start-serviceability.md b/en/application-dev/application-models/start-serviceability.md new file mode 100644 index 0000000000000000000000000000000000000000..f3b0f6aeabc8a3ea35c1f6c390ec53239730443c --- /dev/null +++ b/en/application-dev/application-models/start-serviceability.md @@ -0,0 +1,35 @@ +# Starting a ServiceAbility + + +A ServiceAbility is started in the same way other abilities. You can start a ServiceAbility by calling **featureAbility.startAbility()** in the PageAbility or calling **particleAbility.startAbility()** in another ServiceAbility. For details about the startup rules, see [Component Startup Rules](component-startup-rules.md). + + +The following example shows how to use **startAbility()** to start the ServiceAbility whose **bundleName** is **com.example.myapplication** and **abilityName** is **ServiceAbility** in a PageAbility. When starting the ServiceAbility, concatenate the **bundleName** string before **abilityName**. + +```ts +import featureAbility from '@ohos.ability.featureAbility' + +async function startServiceAbility() { + try { + console.info('Begin to start ability') + let param = { + want: { + bundleName: "com.example.myapplication", + abilityName: "com.example.myapplication.ServiceAbility" + } + } + await featureAbility.startAbility(param) + console.info(`Start ability succeed`) + } catch (error) { + console.error('Start ability failed with ' + error) + } +} +``` + + +In the preceding code, **startAbility()** is used to start the ServiceAbility. + + +- If the ServiceAbility is not running, the system calls **onStart()** to initialize the ServiceAbility, and then calls **onCommand()** on the ServiceAbility. + +- If the ServiceAbility is running, the system directly calls **onCommand()** on the ServiceAbility. diff --git a/en/application-dev/application-models/start-uiability-from-fa.md b/en/application-dev/application-models/start-uiability-from-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..fd2328f6471e045171312ea3909e652f68831c24 --- /dev/null +++ b/en/application-dev/application-models/start-uiability-from-fa.md @@ -0,0 +1,71 @@ +# Starting a UIAbility from the FA Model + + +This topic describes how the three application components of the FA model start the UIAbility component of the stage model. + + +## PageAbility Starting a UIAbility + +A PageAbility starts a UIAbility in the same way as it starts another PageAbility. + +```ts +import featureAbility from '@ohos.ability.featureAbility'; + +let parameter = { + "want": { + bundleName: "com.ohos.stage", + abilityName: "com.ohos.stage.MainAbility" + } +}; +featureAbility.startAbility(parameter).then((code) => { + console.info('Ability verify code: ' + JSON.stringify(code)); +}).catch((error) => { + console.error("Ability failed: " + JSON.stringify(error)); +}); +``` + + +## PageAbility Accessing a UIAbility (startAbilityForResult) + +Different from **startAbility()**, **startAbilityForResult()** obtains the execution result when the UIAbility is destroyed. + +A PageAbility starts a UIAbility through **startAbilityForResult()** in the same way as it starts another PageAbility through **startAbilityForResult()**. + + +```ts +import featureAbility from '@ohos.ability.featureAbility'; + +let parameter = { + "want": { + bundleName: "com.ohos.stage", + abilityName: "com.ohos.stage.MainAbility" + } +}; +featureAbility.startAbilityForResult(parameter).then((result) => { + console.info('Ability verify result: ' + JSON.stringify(result)); +}).catch((error) => { + console.error("Ability failed: " + JSON.stringify(error)); +}); +``` + + +## ServiceAbility or DataAbility Starting a UIAbility + +A ServiceAbility or DataAbility starts a UIAbility in the same way as it starts a PageAbility. + + +```ts +import particleAbility from '@ohos.ability.particleAbility'; + +let parameter = { + "want": { + bundleName: "com.ohos.stage", + abilityName: "com.ohos.stage.MainAbility" + } +}; +particleAbility.startAbility(parameter).then(() => { + console.info('Start Ability successfully.'); +}).catch((error) => { + console.error("Ability failed: " + JSON.stringify(error)); +}); +``` diff --git a/en/application-dev/application-models/stop-pageability.md b/en/application-dev/application-models/stop-pageability.md new file mode 100644 index 0000000000000000000000000000000000000000..7258a6b9e1311bcac602209c31710136a90dfb17 --- /dev/null +++ b/en/application-dev/application-models/stop-pageability.md @@ -0,0 +1,29 @@ +# Stopping a PageAbility + + +The **terminateSelf()** method in the **featureAbility** class is used to stop a PageAbility. + +**Table 1** featureAbility APIs + +| API| Description| +| -------- | -------- | +| terminateSelf() | Terminates this ability.| +| terminateSelfWithResult(parameter: AbilityResult) | Terminates this ability and returns the execution result.| + + +The following code snippet shows how to stop an ability. + +```ts +import featureAbility from '@ohos.ability.featureAbility' + +(async () => { + try { + console.info('Begin to terminateSelf') + await featureAbility.terminateSelf() + console.info('terminateSelf succeed') + } + catch (error) { + console.error('terminateSelf failed with ' + error) + } +})() +``` diff --git a/en/application-dev/application-models/storage-switch.md b/en/application-dev/application-models/storage-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..63486fe56fdf3605121711bee423066d9ac6e116 --- /dev/null +++ b/en/application-dev/application-models/storage-switch.md @@ -0,0 +1,13 @@ +# Storage Switching + + + | API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API in the Stage Model| +| -------- | -------- | -------- | +| GetStorageOptions | There is no corresponding API in the stage model.| The stage model uses **Prefereces** to replace **Storage** and has redesigned the input parameters.| +| SetStorageOptions | There is no corresponding API in the stage model.| The stage model uses **Prefereces** to replace **Storage** and has redesigned the input parameters.| +| ClearStorageOptions | There is no corresponding API in the stage model.| The stage model uses **Prefereces** to replace **Storage** and has redesigned the input parameters.| +| DeleteStorageOptions | There is no corresponding API in the stage model.| The stage model uses **Prefereces** to replace **Storage** and has redesigned the input parameters.| +| [static get(options: GetStorageOptions): void;](../reference/apis/js-apis-system-storage.md#storageget) | \@ohos.data.preferences.d.ts | [get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>): void;](../reference/apis/js-apis-data-preferences.md#get)
[get(key: string, defValue: ValueType): Promise<ValueType>;](../reference/apis/js-apis-data-preferences.md#get-1) | +| [static set(options: SetStorageOptions): void;](../reference/apis/js-apis-system-storage.md#storageset) | \@ohos.data.preferences.d.ts | [put(key: string, value: ValueType, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-data-preferences.md#put)
[put(key: string, value: ValueType): Promise<void>;](../reference/apis/js-apis-data-preferences.md#put-1) | +| [static clear(options?: ClearStorageOptions): void;](../reference/apis/js-apis-system-storage.md#storageclear) | \@ohos.data.preferences.d.ts | [clear(callback: AsyncCallback<void>): void;](../reference/apis/js-apis-data-preferences.md#clear)
[clear(): Promise<void>;](../reference/apis/js-apis-data-preferences.md#clear-1) | +| [static delete(options: DeleteStorageOptions): void;](../reference/apis/js-apis-system-storage.md#storagedelete) | \@ohos.data.preferences.d.ts | [delete(key: string, callback: AsyncCallback<void>): void;](../reference/apis/js-apis-data-preferences.md#delete)
[delete(key: string): Promise<void>;](../reference/apis/js-apis-data-preferences.md#delete-1) | diff --git a/en/application-dev/application-models/thread-model-fa.md b/en/application-dev/application-models/thread-model-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..75401be69cba994ac631b6da997fb6ce2ea35a2f --- /dev/null +++ b/en/application-dev/application-models/thread-model-fa.md @@ -0,0 +1,28 @@ +# Thread Model (FA Model) + + +There are three types of threads in the FA model: + + +- Main thread + +Manages other threads. + +- Ability thread + - One ability thread for each ability. + - Distributes input events. + - Draws the UI. + - Invokes application code callbacks (event processing and lifecycle callbacks). + - Receives messages sent by the worker thread. + +- Worker thread + + Performs time-consuming operations + + +Based on the OpenHarmony thread model, different services run on different threads. Service interaction requires inter-thread communication. Threads can communicate with each other in Emitter or Worker mode. Emitter is mainly used for event synchronization between threads, and Worker is mainly used to execute time-consuming tasks. + + +> **NOTE** +> +> The FA model provides an independent thread for each ability. Emitter is mainly used for event synchronization within the ability thread, between a pair of ability threads, or between the ability thread and worker thread. diff --git a/en/application-dev/application-models/thread-model-stage.md b/en/application-dev/application-models/thread-model-stage.md new file mode 100644 index 0000000000000000000000000000000000000000..deaab60b7bd7549dcb96bc00d7896d5c67e5c5d2 --- /dev/null +++ b/en/application-dev/application-models/thread-model-stage.md @@ -0,0 +1,25 @@ +# Thread Model (Stage Model) + +For an OpenHarmony application, each process has a main thread to provide the following functionalities: + +- Manage other threads. + +- Enable multiple UIAbility components of the same application to share the same main thread. + +- Distribute input events. + +- Draw the UI. + +- Invoke application code callbacks (event processing and lifecycle callbacks). + +- Receive messages sent by the worker thread. + +In addition to the main thread, there is an independent thread, named worker. The worker thread is mainly used to perform time-consuming operations. It cannot directly operate the UI. The worker thread is created in the main thread and is independent of the main thread. A maximum of seven worker threads can be created. + +![thread-model-stage](figures/thread-model-stage.png) + +Based on the OpenHarmony thread model, different services run on different threads. Service interaction requires inter-thread communication. In the same process, threads can communicate with each other in Emitter or Worker mode. Emitter is mainly used for event synchronization between threads, and Worker is mainly used to execute time-consuming tasks. + +> **NOTE** +> +> The stage model provides only the main thread and worker thread. Emitter is mainly used for event synchronization within the main thread or between the main thread and worker thread. diff --git a/en/application-dev/application-models/uiability-data-sync-with-ui.md b/en/application-dev/application-models/uiability-data-sync-with-ui.md new file mode 100644 index 0000000000000000000000000000000000000000..981a9212892a8bc1a920ac929608685c3eafeb00 --- /dev/null +++ b/en/application-dev/application-models/uiability-data-sync-with-ui.md @@ -0,0 +1,320 @@ +# Data Synchronization Between UIAbility and UI + + +Based on the OpenHarmony application model, you can use any of the following ways to implement data synchronization between the UIAbility component and UI: + +- EventHub: The [base class Context](application-context-stage.md) provides the EventHub capability. It is implemented based on the publish/subscribe (pub/sub) pattern. Your application subscribes to an event and when the event occurs, receives a notification. + +- globalThis: It is a global object accessible in the ArkTS engine instance. +- LocalStorage/AppStorage: See [State Management of Application-Level Variables](../quick-start/arkts-state-mgmt-application-level.md). + + +## Using EventHub for Data Synchronization + +[EventHub](../reference/apis/js-apis-inner-application-eventHub.md) provides an event mechanism at the UIAbility or ExtensionAbility component level. Centered on the UIAbility or ExtensionAbility component, EventHub provides data communication capabilities for subscribing to, unsubscribing from, and triggering events. + +Before using EventHub, you must obtain an EventHub object, which is provided by the [base class Context](application-context-stage.md). This section uses EventHub as an example to describe how to implement data synchronization between the UIAbility component and the UI. + +1. Call [eventHub.on()](../reference/apis/js-apis-inner-application-eventHub.md#eventhubon) in the UIAbility in either of the following ways to register a custom event **event1**. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility'; + + const TAG: string = '[Example].[Entry].[EntryAbility]'; + + export default class EntryAbility extends UIAbility { + func1(...data) { + // Trigger the event to complete the service operation. + console.info(TAG, '1. ' + JSON.stringify(data)); + } + + onCreate(want, launch) { + // Obtain an eventHub object. + let eventhub = this.context.eventHub; + // Subscribe to the event. + eventhub.on('event1', this.func1); + eventhub.on('event1', (...data) => { + // Trigger the event to complete the service operation. + console.info(TAG, '2. ' + JSON.stringify(data)); + }); + } + } + ``` + +2. Call [eventHub.emit()](../reference/apis/js-apis-inner-application-eventHub.md#eventhubemit) on the UI to trigger the event, and pass the parameters as required. + + ```ts + import common from '@ohos.app.ability.common'; + + @Entry + @Component + struct Index { + private context = getContext(this) as common.UIAbilityContext; + + eventHubFunc() { + // Trigger the event without parameters. + this.context.eventHub.emit('event1'); + // Trigger the event with one parameter. + this.context.eventHub.emit('event1', 1); + // Trigger the event with two parameters. + this.context.eventHub.emit('event1', 2, 'test'); + // You can design the parameters based on your service requirements. + } + + // Page display. + build() { + // ... + } + } + ``` + +3. Obtain the event trigger result from the subscription callback of UIAbility. The run log result is as follows: + + ```ts + [] + + [1] + + [2,'test'] + ``` + +4. After **event1** is used, you can call [eventHub.off()](../reference/apis/js-apis-inner-application-eventHub.md#eventhuboff) to unsubscribe from the event. + + ```ts + // context is the ability context of the UIAbility instance. + this.context.eventHub.off('event1'); + ``` + + +## Using globalThis for Data Synchronization + + +**globalThis** is a global object inside the [ArkTS engine instance](thread-model-stage.md) and can be used by UIAbility, ExtensionAbility, and Page inside the engine. Therefore, you can use **globalThis** for data synchronization. + + **Figure 1** Using globalThis for data synchronization +globalThis1 + + +The following describes how to use **globalThis** in three scenarios. Precautions are provided as well. + +- [Using globalThis Between UIAbility and Page](#using-globalthis-between-uiability-and-page) +- [Using globalThis Between UIAbility and UIAbility](##using-globalthis-between-uiability-and-uiability) +- [Use globalThis Between UIAbility and ExtensionAbility](#using-globalthis-between-uiability-and-extensionability) +- [Precautions for Using globalThis](#precautions-for-using-globalthis) + +### Using globalThis Between UIAbility and Page + +You can use **globalThis** to bind attributes or methods to implement data synchronization between the UIAbility component and UI. For example, if you bind the **want** parameter in the UIAbility component, you can use the **want** parameter information on the UI corresponding to the UIAbility component. + +1. When **startAbility()** is called to start a UIAbility instance, the **onCreate()** callback is invoked, and the **want** parameter can be passed in the callback. Therefore, you can bind the **want** parameter to **globalThis**. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility' + + export default class EntryAbility extends UIAbility { + onCreate(want, launch) { + globalThis.entryAbilityWant = want; + // ... + } + + // ... + } + ``` + +2. Use **globalThis** on the UI to obtain the **want** parameter information. + + ```ts + let entryAbilityWant; + + @Entry + @Component + struct Index { + aboutToAppear() { + entryAbilityWant = globalThis.entryAbilityWant; + } + + // Page display. + build() { + // ... + } + } + ``` + + +### Using globalThis Between UIAbility and UIAbility + +To implement data synchronization between two UIAbility components in the same application, you can bind data to **globalThis**. For example, you can save data in **globalThis** in AbilityA and obtain the data from AbilityB. + +1. AbilityA stores a string and binds it to globalThis. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility' + + export default class AbilityA extends UIAbility { + onCreate(want, launch) { + globalThis.entryAbilityStr = 'AbilityA'; // AbilityA stores the string "AbilityA" to globalThis. + // ... + } + } + ``` + +2. Obtain the data from AbilityB. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility' + + export default class AbilityB extends UIAbility { + onCreate(want, launch) { + // AbilityB reads the name from globalThis and outputs it. + console.info('name from entryAbilityStr: ' + globalThis.entryAbilityStr); + // ... + } + } + ``` + + +### Using globalThis Between UIAbility and ExtensionAbility + +To implement data synchronization between the UIAbility and ExtensionAbility components in the same application, you can bind data to **globalThis**. For example, you can save data in **globalThis** in AbilityA and obtain the data from ServiceExtensionAbility. + +1. AbilityA stores a string and binds it to globalThis. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility' + + export default class AbilityA extends UIAbility { + onCreate(want, launch) { + // AbilityA stores the string "AbilityA" to globalThis. + globalThis.entryAbilityStr = 'AbilityA'; + // ... + } + } + ``` + +2. Obtain the data from ExtensionAbility. + + ```ts + import Extension from '@ohos.app.ability.ServiceExtensionAbility' + + export default class ServiceExtAbility extends Extension { + onCreate(want) { + / / ServiceExtAbility reads name from globalThis and outputs it. + console.info('name from entryAbilityStr: ' + globalThis.entryAbilityStr); + // ... + } + } + ``` + + +### Precautions for Using globalThis + + **Figure 2** Precautions for globalThis +![globalThis2](figures/globalThis2.png) + +- In the stage model, all the UIAbility components in a process share one ArkTS engine instance. When using **globalThis**, do not store objects with the same name. For example, if AbilityA and AbilityB use **globalThis** to store two objects with the same name, the object stored earlier will be overwritten. + +- This problem does not occur in the FA model because each UIAbility component uses an independent engine. + +- The lifecycle of an object bound to **globalThis** is the same as that of the ArkTS engine instance. You are advised to assign the value **null** after using the object to minimize memory usage. + +The following provides an example to describe the object overwritten problem in the stage model. + +1. In the AbilityA file, [UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md) is stored in **globalThis**. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility' + + export default class AbilityA extends UIAbility { + onCreate(want, launch) { + globalThis.context = this.context; // AbilityA stores the context in globalThis. + // ... + } + } + ``` + +2. Obtain and use [UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md) on the page of Ability A. After the AbilityA instance is used, switch it to the background. + + ```ts + @Entry + @Component + struct Index { + onPageShow() { + let ctx = globalThis.context; // Obtain the context from globalThis and use it. + let permissions = ['com.example.permission'] + ctx.requestPermissionsFromUser(permissions,(result) => { + // ... + }); + } + // Page display. + build() { + // ... + } + } + ``` + +3. In the AbilityB file, [UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md) is stored in **globalThis** and has the same name as that in the AbilityA file. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility' + + export default class AbilityB extends UIAbility { + onCreate(want, launch) { + // AbilityB overwrites the context stored by AbilityA in globalThis. + globalThis.context = this.context; + // ... + } + } + ``` + +4. Obtain and use [UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md) on the page of Ability B. The obtained **globalThis.context** is the value of [UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md) in AbilityB. + + ```ts + @Entry + @Component + struct Index { + onPageShow() { + let ctx = globalThis.context; // Obtain the context from globalThis and use it. + let permissions = ['com.example.permission'] + ctx.requestPermissionsFromUser(permissions,(result) => { + console.info('requestPermissionsFromUser result:' + JSON.stringify(result)); + }); + } + // Page display. + build() { + // ... + } + } + ``` + +5. Switch the AbilityB instance to the background and switch the AbilityA instance to the foreground. In this case, AbilityA will not enter the **onCreate()** lifecycle again. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility' + + export default class AbilityA extends UIAbility { + onCreate(want, launch) { // AbilityA will not enter this lifecycle. + globalThis.context = this.context; + // ... + } + } + ``` + +6. When the page of AbilityA is displayed, the obtained **globalThis.context** is [UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md) of AbilityB instead of AbilityA. An error occurs. + + ```ts + @Entry + @Component + struct Index { + onPageShow() { + let ctx = globalThis.context; // The context in globalThis is the context of AbilityB. + let permissions=['com.example.permission']; + ctx.requestPermissionsFromUser(permissions,(result) => { // Using this object causes a process breakdown. + console.info('requestPermissionsFromUser result:' + JSON.stringify(result)); + }); + } + // Page display. + build() { + // ... + } + } + ``` diff --git a/en/application-dev/application-models/uiability-intra-device-interaction.md b/en/application-dev/application-models/uiability-intra-device-interaction.md new file mode 100644 index 0000000000000000000000000000000000000000..db85dfdffb0a7d9e60e78151d6654fcdd4a973aa --- /dev/null +++ b/en/application-dev/application-models/uiability-intra-device-interaction.md @@ -0,0 +1,630 @@ +# Interaction Intra-Device Between UIAbility Components + + +UIAbility is the minimum unit that can be scheduled by the system. Jumping between functional modules in a device involves starting of specific UIAbility components, which belong to the same or a different application (for example, starting UIAbility of a third-party payment application). + + +This topic describes the UIAbility interaction modes in the following scenarios. For details about cross-device application component interaction, see [Inter-Device Application Component Interaction (Continuation)](inter-device-interaction-hop-overview.md). + + +- [Starting UIAbility in the Same Application](#starting-uiability-in-the-same-application) + +- [Starting UIAbility in the Same Application and Obtaining the Return Result](#starting-uiability-in-the-same-application-and-obtaining-the-return-result) + +- [Starting UIAbility of Another Application](#starting-uiability-of-another-application) + +- [Starting UIAbility of Another Application and Obtaining the Return Result](#starting-uiability-of-another-application-and-obtaining-the-return-result) + +- [Starting a Specified Page of UIAbility](#starting-a-specified-page-of-uiability) + +- [Using Ability Call to Implement UIAbility Interaction](#using-ability-call-to-implement-uiability-interaction) + + +## Starting UIAbility in the Same Application + +This scenario is possible when an application contains multiple UIAbility components. For example, in a payment application, you may need to start the payment UIAbility from the entry UIAbility. + +Assume that your application has two UIAbility components: EntryAbility and FuncAbility, either in the same module or different modules. You are required to start FuncAbility from EntryAbility. + +1. In EntryAbility, call **startAbility()** to start UIAbility. The [want](../reference/apis/js-apis-app-ability-want.md) parameter is the entry parameter for starting the UIAbility instance. In the **want** parameter, **bundleName** indicates the bundle name of the application to start; **abilityName** indicates the name of the UIAbility to start; **moduleName** is required only when the target UIAbility belongs to a different module; **parameters** is used to carry custom information. For details about how to obtain the context, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability). + + ```ts + let wantInfo = { + deviceId: '', // An empty deviceId indicates the local device. + bundleName: 'com.example.myapplication', + abilityName: 'FuncAbility', + moduleName: 'module1', // moduleName is optional. + parameters: {// Custom information. + info: 'From the Index page of EntryAbility', + }, + } + // context is the ability-level context of the initiator UIAbility. + this.context.startAbility(wantInfo).then(() => { + // ... + }).catch((err) => { + // ... + }) + ``` + +2. Use the FuncAbility lifecycle callback to receive the parameters passed from EntryAbility. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility'; + import Window from '@ohos.window'; + + export default class FuncAbility extends UIAbility { + onCreate(want, launchParam) { + // Receive the parameters passed by the caller UIAbility. + let funcAbilityWant = want; + let info = funcAbilityWant?.parameters?.info; + // ... + } + } + ``` + +3. To stop the **UIAbility** instance after the FuncAbility service is complete, call **terminateSelf()** in FuncAbility. + + ```ts + // context is the ability context of the UIAbility instance to stop. + this.context.terminateSelf((err) => { + // ... + }); + ``` + + +## Starting UIAbility in the Same Application and Obtaining the Return Result + +When starting FuncAbility from EntryAbility, you want the result to be returned after the FuncAbility service is finished. For example, your application uses two independent UIAbility components to carry the entry and sign-in functionalities. After the sign-in operation is finished in the sign-in UIAbility, the sign-in result needs to be returned to the entry UIAbility. + +1. In EntryAbility, call **startAbilityForResult()** to start FuncAbility. Use **data** in the asynchronous callback to receive information returned after FuncAbility stops itself. For details about how to obtain the context, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability). + + ```ts + let wantInfo = { + deviceId: '', // An empty deviceId indicates the local device. + bundleName: 'com.example.myapplication', + abilityName: 'FuncAbility', + moduleName: 'module1', // moduleName is optional. + parameters: {// Custom information. + info: 'From the Index page of EntryAbility', + }, + } + // context is the ability-level context of the initiator UIAbility. + this.context.startAbilityForResult(wantInfo).then((data) => { + // ... + }).catch((err) => { + // ... + }) + ``` + +2. Call **terminateSelfWithResult()** to stop FuncAbility. Use the input parameter **abilityResult** to carry the information that FuncAbility needs to return to EntryAbility. + + ```ts + const RESULT_CODE: number = 1001; + let abilityResult = { + resultCode: RESULT_CODE, + want: { + bundleName: 'com.example.myapplication', + abilityName: 'FuncAbility', + moduleName: 'module1', + parameters: { + info: 'From the Index page of FuncAbility', + }, + }, + } + // context is the ability context of the callee UIAbility. + this.context.terminateSelfWithResult(abilityResult, (err) => { + // ... + }); + ``` + +3. After FuncAbility stops itself, EntryAbility uses the **startAbilityForResult()** method to receive the information returned by FuncAbility. The value of **RESULT_CODE** must be the same as the preceding value. + + ```ts + const RESULT_CODE: number = 1001; + + // ... + + // context is the ability-level context of the initiator UIAbility. + this.context.startAbilityForResult(want).then((data) => { + if (data?.resultCode === RESULT_CODE) { + // Parse the information returned by the callee UIAbility. + let info = data.want?.parameters?.info; + // ... + } + }).catch((err) => { + // ... + }) + ``` + + +## Starting UIAbility of Another Application + +Generally, the user only needs to do a common operation (for example, selecting a document application to view the document content) to start the UIAbility of another application. The [implicit Want launch mode](want-overview.md#types-of-want) is recommended. The system identifies a matched UIAbility and starts it based on the **want** parameter of the caller. + +There are two ways to start **UIAbility**: [explicit and implicit](want-overview.md). + +- Explicit Want launch: This mode is used to start a determined UIAbility component of an application. You need to set **bundleName** and **abilityName** of the target application in the **want** parameter. + +- Implicit Want launch: The user selects a UIAbility to start based on the matching conditions. That is, the UIAbility to start is not determined (the **abilityName** parameter is not specified). When the **startAbility()** method is called, the **want** parameter specifies a series of parameters such as [entities](../reference/apis/js-apis-ability-wantConstant.md#wantconstantentity) and [actions](../reference/apis/js-apis-ability-wantConstant.md#wantconstantaction). **entities** provides additional type information of the target UIAbility, such as the browser or video player. **actions** specifies the common operations to perform, such as viewing, sharing, and application details. Then the system analyzes the **want** parameter to find the right UIAbility to start. You usually do not know whether the target application is installed and what **bundleName** and **abilityName** of the target application are. Therefore, implicit Want launch is usually used to start the UIAbility of another application. + +This section describes how to start the UIAbility of another application through implicit Want. + +1. Install multiple document applications on your device. In the **module.json5** file of each UIAbility component, configure [entities](../reference/apis/js-apis-ability-wantConstant.md#wantconstantentity) and [actions](../reference/apis/js-apis-ability-wantConstant.md#wantconstantaction) under **skills**. + + ```json + { + "module": { + "abilities": [ + { + // ... + "skills": [ + { + "entities": [ + // ... + "entity.system.default" + ], + "actions": [ + // ... + "ohos.want.action.viewData" + ] + } + ] + } + ] + } + } + ``` + +2. Include **entities** and **actions** of the caller's **want** parameter into **entities** and **actions** under **skills** of the target UIAbility. After the system matches the UIAbility that meets the **entities** and **actions** information, a dialog box is displayed, showing the list of matched UIAbility instances for users to select. For details about how to obtain the context, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability). + + ```ts + let wantInfo = { + deviceId: '', // An empty deviceId indicates the local device. + // Uncomment the line below if you want to implicitly query data only in the specific bundle. + // bundleName: 'com.example.myapplication', + action: 'ohos.want.action.viewData', + // entities can be omitted. + entities: ['entity.system.default'], + } + + // context is the ability-level context of the initiator UIAbility. + this.context.startAbility(wantInfo).then(() => { + // ... + }).catch((err) => { + // ... + }) + ``` + + The following figure shows the effect. When you click **Open PDF**, a dialog box is displayed for you to select. + uiability-intra-device-interaction + +3. To stop the **UIAbility** instance after the document application is used, call **terminateSelf()**. + + ```ts + // context is the ability context of the UIAbility instance to stop. + this.context.terminateSelf((err) => { + // ... + }); + ``` + + +## Starting UIAbility of Another Application and Obtaining the Return Result + +If you want to obtain the return result when using implicit Want to start the UIAbility of another application, use the **startAbilityForResult()** method. An example scenario is that the main application needs to start a third-party payment application and obtain the payment result. + +1. In the **module.json5** file of the UIAbility corresponding to the payment application, set [entities](../reference/apis/js-apis-ability-wantConstant.md#wantconstantentity) and [actions](../reference/apis/js-apis-ability-wantConstant.md#wantconstantaction) under **skills**. + + ```json + { + "module": { + "abilities": [ + { + // ... + "skills": [ + { + "entities": [ + // ... + "entity.system.default" + ], + "actions": [ + // ... + "ohos.want.action.editData" + ] + } + ] + } + ] + } + } + ``` + +2. Call the **startAbilityForResult()** method to start the UIAbility of the payment application. Include **entities** and **actions** of the caller's **want** parameter into **entities** and **actions** under **skills** of the target UIAbility. Use **data** in the asynchronous callback to receive the information returned to the caller after the payment UIAbility stops itself. After the system matches the UIAbility that meets the **entities** and **actions** information, a dialog box is displayed, showing the list of matched UIAbility instances for users to select. + + ```ts + let wantInfo = { + deviceId: '', // An empty deviceId indicates the local device. + // Uncomment the line below if you want to implicitly query data only in the specific bundle. + // bundleName: 'com.example.myapplication', + action: 'ohos.want.action.editData', + // entities can be omitted. + entities: ['entity.system.default'], + } + + // context is the ability-level context of the initiator UIAbility. + this.context.startAbilityForResult(wantInfo).then((data) => { + // ... + }).catch((err) => { + // ... + }) + ``` + +3. After the payment is finished, call the **terminateSelfWithResult()** method to stop the payment UIAbility and return the **abilityResult** parameter. + + ```ts + const RESULT_CODE: number = 1001; + let abilityResult = { + resultCode: RESULT_CODE, + want: { + bundleName: 'com.example.myapplication', + abilityName: 'EntryAbility', + moduleName: 'entry', + parameters: { + payResult: 'OKay', + }, + }, + } + // context is the ability context of the callee UIAbility. + this.context.terminateSelfWithResult(abilityResult, (err) => { + // ... + }); + ``` + +4. Receive the information returned by the payment application in the callback of the **startAbilityForResult()** method. The value of **RESULT_CODE** must be the same as that returned by **terminateSelfWithResult()**. + + ```ts + const RESULT_CODE: number = 1001; + + let want = { + // Want parameter information. + }; + + // context is the ability-level context of the initiator UIAbility. + this.context.startAbilityForResult(want).then((data) => { + if (data?.resultCode === RESULT_CODE) { + // Parse the information returned by the callee UIAbility. + let payResult = data.want?.parameters?.payResult; + // ... + } + }).catch((err) => { + // ... + }) + ``` + + +## Starting a Specified Page of UIAbility + +A UIAbility component can have multiple pages. When it is started in different scenarios, different pages can be displayed. For example, when a user jumps from a page of a UIAbility component to another UIAbility, you want to start a specified page of the target UIAbility. This section describes how to specify a startup page and start the specified page when the target UIAbility is started for the first time or when the target UIAbility is not started for the first time. + + +### Specifying a Startup Page + +When the caller UIAbility starts another UIAbility, it usually needs to redirect to a specified page. For example, FuncAbility contains two pages: Index (corresponding to the home page) and Second (corresponding to function A page). You can configure the specified page URL in the **want** parameter by adding a custom parameter to **parameters** in **want**. For details about how to obtain the context, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability). + + +```ts +let wantInfo = { + deviceId: '', // An empty deviceId indicates the local device. + bundleName: 'com.example.myapplication', + abilityName: 'FuncAbility', + moduleName: 'module1', // moduleName is optional. + parameters: {// Custom parameter used to pass the page information. + router: 'funcA', + }, +} +// context is the ability-level context of the initiator UIAbility. +this.context.startAbility(wantInfo).then(() => { + // ... +}).catch((err) => { + // ... +}) +``` + + +### Starting a Page When the Target UIAbility Is Started for the First Time + +When the target UIAbility is started for the first time, in the **onWindowStageCreate()** callback of the target UIAbility, parse the **want** parameter passed by EntryAbility to obtain the URL of the page to be loaded, and pass the URL to the **windowStage.loadContent()** method. + + +```ts +import UIAbility from '@ohos.app.ability.UIAbility' +import Window from '@ohos.window' + +export default class FuncAbility extends UIAbility { + funcAbilityWant; + + onCreate(want, launchParam) { + // Receive the parameters passed by the caller UIAbility. + this.funcAbilityWant = want; + } + + onWindowStageCreate(windowStage: Window.WindowStage) { + // Main window is created. Set a main page for this ability. + let url = 'pages/Index'; + if (this.funcAbilityWant?.parameters?.router) { + if (this.funcAbilityWant.parameters.router === 'funA') { + url = 'pages/Second'; + } + } + windowStage.loadContent(url, (err, data) => { + // ... + }); + } +} +``` + + +### Starting a Page When the Target UIAbility Is Not Started for the First Time + +You start application A, and its home page is displayed. Then you return to the home screen and start application B. Now you need to start application A again from application B and have a specified page of application A displayed. An example scenario is as follows: When you open the home page of the SMS application and return to the home screen, the SMS application is in the opened state and its home page is displayed. Then you open the home page of the Contacts application, access user A's details page, and touch the SMS icon to send an SMS message to user A. The SMS application is started again and the sending page is displayed. + +![uiability_not_first_started](figures/uiability_not_first_started.png) + +In summary, when a UIAbility instance of application A has been created and the main page of the UIAbility instance is displayed, you need to start the UIAbility of application A from application B and have a different page displayed. + +1. In the target UIAbility, the **Index** page is loaded by default. The UIAbility instance has been created, and the **onNewWant()** callback rather than **onCreate()** and **onWindowStageCreate()** will be invoked. In the **onNewWant()** callback, parse the **want** parameter and bind it to the global variable **globalThis**. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility' + + export default class FuncAbility extends UIAbility { + onNewWant(want, launchParam) { + // Receive the parameters passed by the caller UIAbility. + globalThis.funcAbilityWant = want; + // ... + } + } + ``` + +2. In FuncAbility, use the router module to implement redirection to the specified page on the **Index** page. Because the **Index** page of FuncAbility is active, the variable will not be declared again and the **aboutToAppear()** callback will not be triggered. Therefore, the page routing functionality can be implemented in the **onPageShow()** callback of the **Index** page. + + ```ts + import router from '@ohos.router'; + + @Entry + @Component + struct Index { + onPageShow() { + let funcAbilityWant = globalThis.funcAbilityWant; + let url2 = funcAbilityWant?.parameters?.router; + if (url2 && url2 === 'funcA') { + router.replaceUrl({ + url: 'pages/Second', + }) + } + } + + // Page display. + build() { + // ... + } + } + ``` + +> **NOTE** +> +> When the [launch type of the callee UIAbility](uiability-launch-type.md) is set to **standard**, a new instance is created each time the callee UIAbility is started. In this case, the [onNewWant()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant) callback will not be invoked. + + +## Using Ability Call to Implement UIAbility Interaction + +This feature applies only to system applications. Ability call is an extension of the UIAbility capability. It enables the UIAbility to be invoked by and communicate with external systems. The UIAbility invoked can be either started in the foreground or created and run in the background. You can use the ability call to implement data sharing between two UIAbility instances (caller ability and callee ability) through IPC. + +The core API used for the ability call is **startAbilityByCall**, which differs from **startAbility** in the following ways: + +- **startAbilityByCall** supports ability launch in the foreground and background, whereas **startAbility** supports ability launch in the foreground only. + +- The caller ability can use the caller object returned by **startAbilityByCall** to communicate with the callee ability, but **startAbility** does not provide the communication capability. + +Ability call is usually used in the following scenarios: + +- Communicating with the callee ability + +- Starting the callee ability in the background + +**Table 1** Terms used in the ability call + +| **Term**| Description| +| -------- | -------- | +| CallerAbility | UIAbility that triggers the ability call.| +| CalleeAbility | UIAbility invoked by the ability call.| +| Caller | Object returned by **startAbilityByCall** and used by the caller ability to communicate with the callee ability.| +| Callee | Object held by the callee ability to communicate with the caller ability.| + +The following figure shows the ability call process. + +Figure 1 Ability call process +call + +- The caller ability uses **startAbilityByCall** to obtain a caller object and uses **call()** of the caller object to send data to the callee ability. + +- The callee ability, which holds a **Callee** object, uses **on()** of the **Callee** object to register a callback. This callback is invoked when the callee ability receives data from the caller ability. + +> **NOTE** +> 1. Currently, only system applications can use the ability call. +> +> 2. The launch type of the callee ability must be **singleton**. +> +> 3. Both local (intra-device) and cross-device ability calls are supported. The following describes how to initiate a local call. For details about how to initiate a cross-device ability call, see [Using Cross-Device Ability Call](hop-multi-device-collaboration.md#using-cross-device-ability-call). + + +### Available APIs + +The following table describes the main APIs used for the ability call. For details, see [AbilityContext](../reference/apis/js-apis-app-ability-uiAbility.md#caller). + + **Table 2** Ability call APIs + +| API| Description| +| -------- | -------- | +| startAbilityByCall(want: Want): Promise<Caller> | Starts a UIAbility in the foreground (through the **want** configuration) or background (default) and obtains the caller object for communication with the UIAbility. For details, see [AbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartabilitybycall) or [ServiceExtensionContext](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextstartabilitybycall).| +| on(method: string, callback: CalleeCallBack): void | Callback invoked when the callee ability registers a method.| +| off(method: string): void | Callback invoked when the callee ability deregisters a method.| +| call(method: string, data: rpc.Sequenceable): Promise<void> | Sends agreed sequenceable data to the callee ability.| +| callWithResult(method: string, data: rpc.Sequenceable): Promise<rpc.MessageParcel> | Sends agreed sequenceable data to the callee ability and obtains the agreed sequenceable data returned by the callee ability.| +| release(): void | Releases the caller object.| +| on(type: "release", callback: OnReleaseCallback): void | Callback invoked when the caller object is released.| + +The implementation of using the ability call for UIAbility interaction involves two parts. + +- [Creating a Callee Ability](#creating-a-callee-ability) + +- [Accessing the Callee Ability](#accessing-the-callee-ability) + + +### Creating a Callee Ability + +For the callee ability, implement the callback to receive data and the methods to marshal and unmarshal data. When data needs to be received, use **on()** to register a listener. When data does not need to be received, use **off()** to deregister the listener. + +1. Configure the ability launch type. + + +Set **launchType** of the callee ability to **singleton** in the **module.json5** file. + +| JSON Field| Description| +| -------- | -------- | +| "launchType" | Ability launch type. Set this parameter to **singleton**.| + +An example of the ability configuration is as follows: + + + ```json + "abilities":[{ + "name": ".CalleeAbility", + "srcEntrance": "./ets/CalleeAbility/CalleeAbility.ts", + "launchType": "singleton", + "description": "$string:CalleeAbility_desc", + "icon": "$media:icon", + "label": "$string:CalleeAbility_label", + "visible": true + }] + ``` + +2. Import the **UIAbility** module. + + ```ts + import Ability from '@ohos.app.ability.UIAbility'; + ``` + +3. Define the agreed sequenceable data. + + The data formats sent and received by the caller and callee abilities must be consistent. In the following example, the data formats are number and string. + + + ```ts + export default class MySequenceable { + num: number = 0 + str: string = "" + + constructor(num, string) { + this.num = num + this.str = string + } + + marshalling(messageParcel) { + messageParcel.writeInt(this.num) + messageParcel.writeString(this.str) + return true + } + + unmarshalling(messageParcel) { + this.num = messageParcel.readInt() + this.str = messageParcel.readString() + return true + } + } + ``` + +4. Implement **Callee.on** and **Callee.off**. + + The time to register a listener for the callee ability depends on your application. The data sent and received before the listener is registered and that after the listener is deregistered are not processed. In the following example, the **MSG_SEND_METHOD** listener is registered in **onCreate** of the ability and deregistered in **onDestroy**. After receiving sequenceable data, the application processes the data and returns the data result. You need to implement processing based on service requirements. The sample code is as follows: + + + ```ts + const TAG: string = '[CalleeAbility]'; + const MSG_SEND_METHOD: string = 'CallSendMsg'; + + function sendMsgCallback(data) { + console.info('CalleeSortFunc called'); + + // Obtain the sequenceable data sent by the caller ability. + let receivedData = new MySequenceable(0, ''); + data.readSequenceable(receivedData); + console.info(`receiveData[${receivedData.num}, ${receivedData.str}]`); + + // Process the data. + // Return the sequenceable data result to the caller ability. + return new MySequenceable(receivedData.num + 1, `send ${receivedData.str} succeed`); + } + + export default class CalleeAbility extends Ability { + onCreate(want, launchParam) { + try { + this.callee.on(MSG_SEND_METHOD, sendMsgCallback); + } catch (error) { + console.info(`${MSG_SEND_METHOD} register failed with error ${JSON.stringify(error)}`); + } + } + + onDestroy() { + try { + this.callee.off(MSG_SEND_METHOD); + } catch (error) { + console.error(TAG, `${MSG_SEND_METHOD} unregister failed with error ${JSON.stringify(error)}`); + } + } + } + ``` + + +### Accessing the Callee Ability + +1. Import the **UIAbility** module. + + ```ts + import Ability from '@ohos.app.ability.UIAbility'; + ``` + +2. Obtain the caller interface. + + + The **context** attribute of the ability implements **startAbilityByCall** to obtain the caller object for communication. The following example uses **this.context** to obtain the **context** attribute of the ability, uses **startAbilityByCall** to start the callee ability, obtain the caller object, and register the **onRelease** listener of the caller ability. You need to implement processing based on service requirements. + + ```ts + // Register the onRelease() listener of the caller ability. + private regOnRelease(caller) { + try { + caller.on("release", (msg) => { + console.info(`caller onRelease is called ${msg}`); + }) + console.info('caller register OnRelease succeed'); + } catch (error) { + console.info(`caller register OnRelease failed with ${error}`); + } + } + + async onButtonGetCaller() { + try { + this.caller = await context.startAbilityByCall({ + bundleName: 'com.samples.CallApplication', + abilityName: 'CalleeAbility' + }) + if (this.caller === undefined) { + console.info('get caller failed') + return + } + console.info('get caller success') + this.regOnRelease(this.caller) + } catch (error) { + console.info(`get caller failed with ${error}`) + } + } + ``` diff --git a/en/application-dev/application-models/uiability-launch-type.md b/en/application-dev/application-models/uiability-launch-type.md new file mode 100644 index 0000000000000000000000000000000000000000..c64d7fb3ffc0e3fa31741924439998118449068a --- /dev/null +++ b/en/application-dev/application-models/uiability-launch-type.md @@ -0,0 +1,158 @@ +# UIAbility Component Launch Type + + +The launch type of the UIAbility component refers to the state of the UIAbility instance at startup. The system provides three launch types: + + +- [Singleton](#singleton) + +- [Standard](#standard) + +- [Specified](#specified) + + +## Singleton + +**singleton** is the default launch type. + +Each time [startAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) is called, if a UIAbility instance of this type already exists in the application process, the instance is reused. Therefore, only one UIAbility instance of this type exists in the system, that is, displayed in **Recents**. + +**Figure 1** Demonstration effect in singleton mode +uiability-launch-type1 + +> **NOTE** +> +> Assume that the application already has a UIAbility instance created, and the launch type of the UIAbility instance is set to **singleton**. If [startAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) is called again to start the UIAbility instance, the original UIAbility instance is started, and no new UIAbility instance is created. In this case, the [onNewWant()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant) callback is invoked, but the [onCreate()](../reference/apis/js-apis-app-ability-uiAbility.md#uiabilityoncreate) and [onWindowStageCreate()](../reference/apis/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate) callbacks are not. + +To use the singleton mode, set **launchType** in the [module.json5 configuration file](../quick-start/module-configuration-file.md) to **singleton**. + + +```json +{ + "module": { + // ... + "abilities": [ + { + "launchType": "singleton", + // ... + } + ] + } +} +``` + + +## Standard + +In standard mode, each time [startAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) is called, a new UIAbility instance of this type is created in the application process. Multiple UIAbility instances of this type are displayed in **Recents**. + +**Figure 2** Demonstration effect in standard mode +standard-mode + +To use the standard mode, set **launchType** in the [module.json5 configuration file](../quick-start/module-configuration-file.md) to **standard**. + + +```json +{ + "module": { + // ... + "abilities": [ + { + "launchType": "standard", + // ... + } + ] + } +} +``` + + +## Specified + +The **specified** mode is used in some special scenarios. For example, in a document application, you want a document instance to be created each time you create a document, but you want to use the same document instance when you repeatedly open an existing document. + +**Figure 3** Demonstration effect in specified mode +uiability-launch-type2 + +For example, there are EntryAbility and SpecifiedAbility, and the launch type of SpecifiedAbility is set to **specified**. You are required to start SpecifiedAbility from EntryAbility. + +1. In SpecifiedAbility, set the **launchType** field in the [module.json5 configuration file](../quick-start/module-configuration-file.md) to **specified**. + + ```json + { + "module": { + // ... + "abilities": [ + { + "launchType": "specified", + // ... + } + ] + } + } + ``` + +2. Before a UIAbility instance is created, you can create a unique string key for the instance. The key is bound to the UIAbility instance when it is created. Each time [startAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) is called, the application is asked which UIAbility instance is used to respond to the [startAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) request. + In EntryAbility, add a custom parameter, for example, **instanceKey**, to the **want** parameter in [startAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) to distinguish the UIAbility instances. + + ```ts + // Configure an independent key for each UIAbility instance. + // For example, in the document usage scenario, use the document path as the key. + function getInstance() { + // ... + } + + let want = { + deviceId: '', // An empty deviceId indicates the local device. + bundleName: 'com.example.myapplication', + abilityName: 'SpecifiedAbility', + moduleName: 'module1', // moduleName is optional. + parameters: {// Custom information. + instanceKey: getInstance(), + }, + } + // context is the ability-level context of the initiator UIAbility. + this.context.startAbility(want).then(() => { + // ... + }).catch((err) => { + // ... + }) + ``` + +3. During running, the internal service of UIAbility determines whether to create multiple instances. If the key is matched, the UIAbility instance bound to the key is started. Otherwise, a new UIAbility instance is created. + The launch type of SpecifiedAbility is set to **specified**. Before SpecifiedAbility is started, the [onAcceptWant()](../reference/apis/js-apis-app-ability-abilityStage.md#abilitystageonacceptwant) callback of the corresponding AbilityStage instance is invoked to parse the input **want** parameter and obtain the custom parameter **instanceKey**. A string key identifier is returned through the [onAcceptWant()](../reference/apis/js-apis-app-ability-abilityStage.md#abilitystageonacceptwant) callback of the AbilityStage instance. [If the returned key corresponds to a started UIAbility instance](mission-management-launch-type.md#fig14520125175314), that UIAbility instance is switched to the foreground and gains focus again. Otherwise, a new instance is created and started. + + ```ts + import AbilityStage from '@ohos.app.ability.AbilityStage'; + + export default class MyAbilityStage extends AbilityStage { + onAcceptWant(want): string { + // In the AbilityStage instance of the callee, a key value corresponding to a UIAbility instance is returned for UIAbility whose launch type is specified. + // In this example, SpecifiedAbility of module1 is returned. + if (want.abilityName === 'SpecifiedAbility') { + // The returned string key is a custom string. + return `SpecifiedAbilityInstance_${want.parameters.instanceKey}`; + } + + return ''; + } + } + ``` + + > **NOTE** + > + > 1. Assume that the application already has a UIAbility instance created, and the launch type of the UIAbility instance is set to **specified**. If [startAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) is called again to start the UIAbility instance, and the [onAcceptWant()](../reference/apis/js-apis-app-ability-abilityStage.md#abilitystageonacceptwant) callback of [AbilityStage](../reference/apis/js-apis-app-ability-abilityStage.md) matches a created UIAbility instance, the original UIAbility instance is started, and no new UIAbility instance is created. In this case, the [onNewWant()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant) callback is invoked, but the [onCreate()](../reference/apis/js-apis-app-ability-uiAbility.md#uiabilityoncreate) and [onWindowStageCreate()](../reference/apis/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate) callbacks are not. + > 2. AbilityStage is not automatically generated in the default project of DevEco Studio. For details about how to create an AbilityStage file, see [AbilityStage Component Container](abilitystage.md). + + For example, in the document application, different key values are bound to different document instances. Each time a document is created, a new key value (for example, file path) is passed, and a new UIAbility instance is created when UIAbility is started in AbilityStage. However, when you open an existing document, the same UIAbility instance is started again in AbilityStage. + + The following steps are used as an example. + 1. Open file A. A UIAbility instance, for example, UIAbility instance 1, is started. + + 2. Close the process of file A in **Recents**. UIAbility instance 1 is destroyed. Return to the home screen and open file A again. A new UIAbility instance is started, for example, UIAbility instance 2. + + 3. Return to the home screen and open file B. A new UIAbility instance is started, for example, UIAbility instance 3. + + 4. Return to the home screen and open file A again. UIAbility instance 2 is started. + + \ No newline at end of file diff --git a/en/application-dev/application-models/uiability-lifecycle.md b/en/application-dev/application-models/uiability-lifecycle.md new file mode 100644 index 0000000000000000000000000000000000000000..b530a7bda5c4f3c4fe0dd2eb96d53991083a5ff4 --- /dev/null +++ b/en/application-dev/application-models/uiability-lifecycle.md @@ -0,0 +1,147 @@ +# UIAbility Component Lifecycle + + +## Overview + +When a user opens, switches, and returns to an application, the UIAbility instances in the application transit in their different states. The UIAbility class provides a series of callbacks. Through these callbacks, you can know the state changes of the UIAbility instance, for example, being created or destroyed, or running in the foreground or background. + +The lifecycle of UIAbility has four states: **Create**, **Foreground**, **Background**, and **Destroy**, as shown in the figure below. + + **Figure 1** UIAbility lifecycle states +Ability-Life-Cycle + + +## Description of Lifecycle States + + +### Create + +The **Create** state is triggered when the UIAbility instance is created during application loading. The system invokes the **onCreate()** callback. In this callback, you can perform application initialization operations, for example, defining variables or loading resources. + + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; +import Window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + // Initialize the application. + } + // ... +} +``` + + +### WindowStageCreate and WindowStageDestory + +After the UIAbility instance is created but before it enters the **Foreground** state, the system creates a WindowStage instance and triggers the **onWindowStageCreate()** callback. You can set UI loading and WindowStage event subscription in the callback. + + **Figure 2** WindowStageCreate and WindowStageDestory +Ability-Life-Cycle-WindowStage + +In the **onWindowStageCreate()** callback, use [loadContent()](../reference/apis/js-apis-window.md#loadcontent9-2) to set the page to be loaded, and call [on('windowStageEvent')](../reference/apis/js-apis-window.md#onwindowstageevent9) to subscribe to [WindowStage events](../reference/apis/js-apis-window.md#windowstageeventtype9), for example, having or losing focus, or becoming visible or invisible. + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; +import Window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + // ... + + onWindowStageCreate(windowStage: Window.WindowStage) { + // Subscribe to the WindowStage events (having or losing focus, or becoming visible or invisible). + try { + windowStage.on('windowStageEvent', (data) => { + console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + + JSON.stringify(data)); + }); + } catch (exception) { + console.error('Failed to enable the listener for window stage event changes. Cause:' + + JSON.stringify(exception)); + }; + + // Set the UI loading. + windowStage.loadContent('pages/Index', (err, data) => { + // ... + }); + } +} +``` + +> **NOTE** +> +> For details about how to use WindowStage, see [Window Development](../windowmanager/application-window-stage.md). + +Before the UIAbility instance is destroyed, the **onWindowStageDestroy()** callback is invoked to release UI resources. In this callback, you can unsubscribe from the WindowStage events. + + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; +import Window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + // ... + + onWindowStageDestroy() { + // Release UI resources. + // Unsubscribe from the WindowStage events such as having or losing focus in the onWindowStageDestroy() callback. + try { + windowStage.off('windowStageEvent'); + } catch (exception) { + console.error('Failed to disable the listener for window stage event changes. Cause:' + + JSON.stringify(exception)); + }; + } +} +``` + + +### Foreground and Background + +The **Foreground** and **Background** states are triggered when the UIAbility instance is switched to the foreground and background respectively. They correspond to the **onForeground()** and **onBackground()** callbacks. + +The **onForeground()** callback is triggered before the UI of the UIAbility instance becomes visible, for example, when the UIAbility instance is switched to the foreground. In this callback, you can apply for resources required by the system or re-apply for resources that have been released in the **onBackground()** callback. + +The **onBackground()** callback is triggered after the UI of the UIAbility component is completely invisible, for example, when the UIAbility instance is switched to the background. In this callback, you can release useless resources or perform time-consuming operations such as saving the status. + +For example, an application needs to use positioning, and the application has requested the positioning permission from the user. Before the UI is displayed, you can enable positioning in the **onForeground()** callback to obtain the location information. + +When the application is switched to the background, you can disable positioning in the **onBackground()** callback to reduce system resource consumption. + + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; + +export default class EntryAbility extends UIAbility { + // ... + + onForeground() { + // Apply for the resources required by the system or re-apply for the resources released in onBackground(). + } + + onBackground() { + // Release useless resources when the UI is invisible, or perform time-consuming operations in this callback, + // for example, saving the status. + } +} +``` + + +### Destroy + +The **Destroy** state is triggered when the UIAbility instance is destroyed. You can perform operations such as releasing system resources and saving data in the **onDestroy()** callback. + +The UIAbility instance is destroyed when **terminateSelf()** is called or the user closes the instance in **Recents**. + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; +import Window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + // ... + + onDestroy() { + // Release system resources and save data. + } +} +``` diff --git a/en/application-dev/application-models/uiability-overview.md b/en/application-dev/application-models/uiability-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..ec26d2ca9b360259d7f7c00c37cba53bd5db8756 --- /dev/null +++ b/en/application-dev/application-models/uiability-overview.md @@ -0,0 +1,40 @@ +# UIAbility Component Overview + + +## Overview + +UIAbility has the UI and is mainly used for user interaction. + +UIAbility is the basic unit scheduled by the system and provides a window for applications to draw UIs. A UIAbility component can implement a functional module through multiple pages. Each UIAbility component instance corresponds to a mission in **Recents**. + + +## Privacy Statement Configuration + +To enable an application to properly use a UIAbility component, declare the UIAbility name, entry, and tags under [abilities](../quick-start/module-configuration-file.md#abilities) in the [module.json5 configuration file](../quick-start/module-configuration-file.md). + + +```json +{ + "module": { + // ... + "abilities": [ + { + "name": "EntryAbility", // Name of the UIAbility component. + "srcEntrance": "./ets/entryability/EntryAbility.ts", // Code path of the UIAbility component. + "description": "$string:EntryAbility_desc", // Description of the UIAbility component. + "icon": "$media:icon", // Icon of the UIAbility component. + "label": "$string:EntryAbility_label", // Label of the UIAbility component. + "startWindowIcon": "$media:icon", // Index of the icon resource file. + "startWindowBackground": "$color:start_window_background", // Index of the background color resource file. + // ... + } + ] + } +} +``` + +> **NOTE** +> +> For the ability composition, see [Adding an Ability to a Module](https://developer.harmonyos.com/en/docs/documentation/doc-guides-V3/ohos-adding-ability-0000001218280664-V3). + + \ No newline at end of file diff --git a/en/application-dev/application-models/uiability-usage.md b/en/application-dev/application-models/uiability-usage.md new file mode 100644 index 0000000000000000000000000000000000000000..ccd80625f460ea704f689f9b7dfa83f6b42fa47f --- /dev/null +++ b/en/application-dev/application-models/uiability-usage.md @@ -0,0 +1,99 @@ +# UIAbility Component Usage + + +When using the UIAbility component, you must specify a startup page and obtain the context, [UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md). + + +## Specifying the Startup Page of UIAbility + +If no startup page is specified, a white screen occurs after the application is started. You can use **loadContent()** of [WindowStage](../reference/apis/js-apis-window.md#windowstage9) to set the startup page in the **onWindowStageCreate()** callback of the UIAbility instance. + + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; +import Window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage: Window.WindowStage) { + // Main window is created. Set a main page for this ability. + windowStage.loadContent('pages/Index', (err, data) => { + // ... + }); + } + + // ... +} +``` + +> **NOTE** +> +> When you create UIAbility in DevEco Studio, the UIAbility instance loads the **Index** page by default. Therefore, you only need to replace the **Index** page path with the required startup page path. + + +## Obtaining the Context of UIAbility + +The UIAbility class has its own context, which is an instance of the [UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md) class. The UIAbilityContext class has attributes such as **abilityInfo** and **currentHapModuleInfo**. UIAbilityContext can be used to obtain the UIAbility configuration information, such as the bundle code path, bundle name, ability name, and environment status required by the application. It can also be used to obtain methods to operate the UIAbility instance, such as **startAbility()**, **connectServiceExtensionAbility()**, and **terminateSelf()**. + +- You can use **this.context** to obtain the context of a UIAbility instance. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility'; + + export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + // Obtain the context of the UIAbility instance. + let context = this.context; + + // ... + } + } + ``` + +- Import the context module and define the **context** variable in the component. + + ```ts + import common from '@ohos.app.ability.common'; + + @Entry + @Component + struct Index { + private context = getContext(this) as common.UIAbilityContext; + + startAbilityTest() { + let want = { + // Want parameter information. + }; + this.context.startAbility(want); + } + + // Page display. + build() { + // ... + } + } + ``` + + You can also define variables after importing the context module but before using [UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md). + + + ```ts + import common from '@ohos.app.ability.common'; + + @Entry + @Component + struct Index { + + startAbilityTest() { + let context = getContext(this) as common.UIAbilityContext; + let want = { + // Want parameter information. + }; + context.startAbility(want); + } + + // Page display. + build() { + // ... + } + } + ``` diff --git a/en/application-dev/application-models/want-fa.md b/en/application-dev/application-models/want-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..5ef82daf1f6ac353200131fd8195cbea35725e3c --- /dev/null +++ b/en/application-dev/application-models/want-fa.md @@ -0,0 +1,4 @@ +# Want (FA Model) + + +For details, see "[Want](want-overview.md)" in the stage model. diff --git a/en/application-dev/application-models/want-overview.md b/en/application-dev/application-models/want-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..784f190ad6b23a85c60995c44babdc8dd34d576d --- /dev/null +++ b/en/application-dev/application-models/want-overview.md @@ -0,0 +1,51 @@ +# Want Overview + + +## Definition and Usage of Want + +[Want](../reference/apis/js-apis-app-ability-want.md) is used as the carrier to transfer information between application components. It is used as a parameter of **startAbility()** to specify the startup target and information that needs to be carried during startup, for example, **bundleName** and **abilityName**, which respectively indicate the bundle name of the target ability and the ability name in the bundle. For example, when UIAbilityA starts UIAbilityB and needs to transfer some data to UIAbilityB, it can use Want to transfer the data. + +**Figure 1** Want usage +usage-of-want + + +## Types of Want + +- **Explicit Want**: A type of Want with **abilityName** and **bundleName** specified when starting an ability. + When there is an explicit object to process the request, the target ability can be started by specifying the bundle name and ability name in Want. Explicit Want is usually used to start a known ability. + + ```ts + let wantInfo = { + deviceId: '', // An empty deviceId indicates the local device. + bundleName: 'com.example.myapplication', + abilityName: 'FuncAbility', + } + ``` + +- **Implicit Want**: A type of Want with **abilityName** unspecified when starting the ability. + Implicit Want can be used when the object used to process the request is unclear and the current application wants to use a capability (defined by the [skills tag](../quick-start/module-configuration-file.md#skills-tag)) provided by another application. For example, you can use implicit Want to describe a request for opening a link, since you do not care which application is used to open the link. The system matches all applications that support the request. + + + ```ts + let wantInfo = { + // Uncomment the line below if you want to implicitly query data only in the specific bundle. + // bundleName: 'com.example.myapplication', + action: 'ohos.want.action.search', + // entities can be omitted. + entities: [ 'entity.system.browsable' ], + uri: 'https://www.test.com:8080/query/student', + type: 'text/plain', + }; + ``` + + > **NOTE** + > - Depending on the ability matching result, the following cases may be possible when you attempt to use implicit Want to start the ability. + > - No ability is matched. The startup fails. + > - An ability that meets the conditions is matched. That ability is started. + > - Multiple abilities that meet the conditions are matched. A dialog box is displayed for users to select one of them. + > + > - If the **want** parameter passed does not contain **abilityName** or **bundleName**, the ServiceExtensionAbility components of all applications cannot be started through implicit Want. + > + > - If the **want** parameter passed contains **bundleName**, the **startServiceExtensionAbility()** method can be used to implicitly start ServiceExtensionAbility. By default, ServiceExtensionAbility with the highest priority is returned. If all the matching ServiceExtensionAbility components have the same priority, the first ServiceExtensionAbility is returned. + + \ No newline at end of file diff --git a/en/application-dev/application-models/widget-development-fa.md b/en/application-dev/application-models/widget-development-fa.md new file mode 100644 index 0000000000000000000000000000000000000000..c170f134932af44c4e8b55888e216926ef51186e --- /dev/null +++ b/en/application-dev/application-models/widget-development-fa.md @@ -0,0 +1,546 @@ +# Widget Development + + +## Widget Overview + +A service widget (also called widget) is a set of UI components that display important information or operations specific to an application. It provides users with direct access to a desired application service, without the need to open the application first. + +A widget usually appears as a part of the UI of another application (which currently can only be a system application) and provides basic interactive features such as opening a UI page or sending a message. + +Before you get started, it would be helpful if you have a basic understanding of the following concepts: + +- Widget host: an application that displays the widget content and controls the widget location. + +- Widget Manager: a resident agent that provides widget management features such as periodic widget updates. + +- Widget provider: an atomic service that provides the widget content to display and controls how widget components are laid out and how they interact with users. + + +## Working Principles + +Figure 1 shows the working principles of the widget framework. + +**Figure 1** Widget framework working principles in the FA model +![form-extension](figures/form-extension.png) + +The widget host consists of the following modules: + +- Widget usage: provides operations such as creating, deleting, or updating a widget. + +- Communication adapter: provided by the OpenHarmony SDK for communication with the Widget Manager. It sends widget-related operations to the Widget Manager. + +The Widget Manager consists of the following modules: + +- Periodic updater: starts a scheduled task based on the update policy to periodically update a widget after it is added to the Widget Manager. + +- Cache manager: caches view information of a widget after it is added to the Widget Manager to directly return the cached data when the widget is obtained next time. This reduces the latency greatly. + +- Lifecycle manager: suspends update when a widget is switched to the background or is blocked, and updates and/or clears widget data during upgrade and deletion. + +- Object manager: manages RPC objects of the widget host. It is used to verify requests from the widget host and process callbacks after the widget update. + +- Communication adapter: communicates with the widget host and provider through RPCs. + +The widget provider consists of the following modules: + +- Widget service: implemented by the widget provider developer to process requests on widget creation, update, and deletion, and to provide corresponding widget services. + +- Instance manager: implemented by the widget provider developer for persistent management of widget instances allocated by the Widget Manager. + +- Communication adapter: provided by the OpenHarmony SDK for communication with the Widget Manager. It pushes update data to the Widget Manager. + +> **NOTE** +> +> You only need to develop the widget provider. The system automatically handles the work of the widget host and Widget Manager. + + +## Available APIs + +The **FormAbility** has the following APIs. + +| API| Description| +| -------- | -------- | +| onCreate(want: Want): formBindingData.FormBindingData | Called to notify the widget provider that a widget has been created.| +| onCastToNormal(formId: string): void | Called to notify the widget provider that a temporary widget has been converted to a normal one.| +| onUpdate(formId: string): void | Called to notify the widget provider that a widget has been updated.| +| onVisibilityChange(newStatus: { [key: string]: number }): void | Called to notify the widget provider of the change in widget visibility.| +| onEvent(formId: string, message: string): void | Called to instruct the widget provider to receive and process a widget event.| +| onDestroy(formId: string): void | Called to notify the widget provider that a widget has been destroyed.| +| onAcquireFormState?(want: Want): formInfo.FormState | Called to instruct the widget provider to receive the status query result of a widget.| +| onShare?(formId: string): {[key: string]: any} | Called by the widget provider to receive shared widget data.| + +The **FormProvider** class has the following APIs. For details, see [FormProvider](../reference/apis/js-apis-app-form-formProvider.md). + + +| API| Description| +| -------- | -------- | +| setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback<void>): void;| Sets the next refresh time for a widget. This API uses an asynchronous callback to return the result.| +| setFormNextRefreshTime(formId: string, minute: number): Promise<void>;| Sets the next refresh time for a widget. This API uses a promise to return the result.| +| updateForm(formId: string, formBindingData: FormBindingData, callback: AsyncCallback<void>): void; | Updates a widget. This API uses an asynchronous callback to return the result.| +| updateForm(formId: string, formBindingData: FormBindingData): Promise<void>; | Updates a widget. This API uses a promise to return the result.| + + +The **FormBindingData** class has the following APIs. For details, see [FormBindingData](../reference/apis/js-apis-app-form-formBindingData.md). + + +| API| Description| +| -------- | -------- | +| createFormBindingData(obj?: Object \ string): FormBindingData| | Creates a **FormBindingData** object.| + + +## How to Develop + +The widget provider development based on the [FA model](fa-model-development-overview.md) involves the following key steps: + +- [Implementing Widget Lifecycle Callbacks](#implementing-widget-lifecycle-callbacks): Develop the **FormAbility** lifecycle callback functions. + +- [Configuring the Widget Configuration File](#configuring-the-widget-configuration-file): Configure the application configuration file **config.json**. + +- [Persistently Storing Widget Data](#persistently-storing-widget-data): Perform persistent management on widget information. + +- [Updating Widget Data](#updating-widget-data): Call **updateForm()** to update the information displayed on a widget. + +- [Developing the Widget UI Page](#developing-the-widget-ui-page): Use HML+CSS+JSON to develop a JS widget UI page. + +- [Developing Widget Events](#developing-widget-events): Add the router and message events for a widget. + + +### Implementing Widget Lifecycle Callbacks + +To create a widget in the FA model, implement the widget lifecycle callbacks. Generate a widget template by referring to [Developing a Service Widget](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-development-service-widget-0000001263280425). + +1. Import related modules to **form.ts**. + + ```ts + import formBindingData from '@ohos.app.form.formBindingData'; + import formInfo from '@ohos.app.form.formInfo'; + import formProvider from '@ohos.app.form.formProvider'; + import dataStorage from '@ohos.data.storage'; + ``` + +2. Implement the widget lifecycle callbacks in **form.ts**. + + ```ts + export default { + onCreate(want) { + console.info('FormAbility onCreate'); + // Called when the widget is created. The widget provider should return the widget data binding class. + let obj = { + "title": "titleOnCreate", + "detail": "detailOnCreate" + }; + let formData = formBindingData.createFormBindingData(obj); + return formData; + }, + onCastToNormal(formId) { + // Called when the widget host converts the temporary widget into a normal one. The widget provider should do something to respond to the conversion. + console.info('FormAbility onCastToNormal'); + }, + onUpdate(formId) { + // Override this method to support scheduled updates, periodic updates, or updates requested by the widget host. + console.info('FormAbility onUpdate'); + let obj = { + "title": "titleOnUpdate", + "detail": "detailOnUpdate" + }; + let formData = formBindingData.createFormBindingData(obj); + formProvider.updateForm(formId, formData).catch((error) => { + console.info('FormAbility updateForm, error:' + JSON.stringify(error)); + }); + }, + onVisibilityChange(newStatus) { + // Called when the widget host initiates an event about visibility changes. The widget provider should do something to respond to the notification. This callback takes effect only for system applications. + console.info('FormAbility onVisibilityChange'); + }, + onEvent(formId, message) { + // If the widget supports event triggering, override this method and implement the trigger. + console.info('FormAbility onEvent'); + }, + onDestroy(formId) { + // Delete widget data. + console.info('FormAbility onDestroy'); + }, + onAcquireFormState(want) { + console.info('FormAbility onAcquireFormState'); + return formInfo.FormState.READY; + }, + } + ``` + +> **NOTE** +> +> FormAbility cannot reside in the background. Therefore, continuous tasks cannot be processed in the widget lifecycle callbacks. + +### Configuring the Widget Configuration File + +The widget configuration file is named **config.json**. Find the **config.json** file for the widget and edit the file depending on your need. + +- The **js** module in the **config.json** file provides JavaScript resources of the widget. The internal structure is described as follows: + | Name| Description| Data Type| Initial Value Allowed| + | -------- | -------- | -------- | -------- | + | name | Name of a JavaScript component. The default value is **default**.| String| No| + | pages | Route information about all pages in the JavaScript component, including the page path and page name. The value is an array, in which each element represents a page. The first element in the array represents the home page of the JavaScript FA.| Array| No| + | window | Window-related configurations.| Object| Yes| + | type | Type of the JavaScript component. The value can be:
**normal**: indicates an application instance.
**form**: indicates a widget instance.| String| Yes (initial value: **normal**)| + | mode | Development mode of the JavaScript component.| Object| Yes (initial value: left empty)| + + A configuration example is as follows: + + + ```json + "js": [{ + "name": "widget", + "pages": ["pages/index/index"], + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "type": "form" + }] + ``` + +- The **abilities** module in the **config.json** file corresponds to **FormAbility** of the widget. The internal structure is described as follows: + | Name| Description| Data Type| Initial Value Allowed| + | -------- | -------- | -------- | -------- | + | name | Class name of a widget. The value is a string with a maximum of 127 bytes.| String| No| + | description | Description of the widget. The value can be a string or a resource index to descriptions in multiple languages. The value is a string with a maximum of 255 bytes.| String| Yes (initial value: left empty)| + | isDefault | Whether the widget is a default one. Each ability has only one default widget.
**true**: The widget is the default one.
**false**: The widget is not the default one.| Boolean| No| + | type | Type of the widget. The value can be:
**JS**: indicates a JavaScript-programmed widget.| String| No| + | colorMode | Color mode of the widget.
**auto**: The widget adopts the auto-adaptive color mode.
**dark**: The widget adopts the dark color mode.
**light**: The widget adopts the light color mode.| String| Yes (initial value: **auto**)| + | supportDimensions | Grid styles supported by the widget.
**1 * 2**: indicates a grid with one row and two columns.
**2 * 2**: indicates a grid with two rows and two columns.
**2 * 4**: indicates a grid with two rows and four columns.
**4 * 4**: indicates a grid with four rows and four columns.| String array| No| + | defaultDimension | Default grid style of the widget. The value must be available in the **supportDimensions** array of the widget.| String| No| + | updateEnabled | Whether the widget can be updated periodically.
**true**: The widget can be updated at a specified interval (**updateDuration**) or at the scheduled time (**scheduledUpdateTime**). **updateDuration** takes precedence over **scheduledUpdateTime**.
**false**: The widget cannot be updated periodically.| Boolean| No| + | scheduledUpdateTime | Scheduled time to update the widget. The value is in 24-hour format and accurate to minute.
**updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used.| String| Yes (initial value: **0:0**)| + | updateDuration | Interval to update the widget. The value is a natural number, in the unit of 30 minutes.
If the value is **0**, this attribute does not take effect.
If the value is a positive integer *N*, the interval is calculated by multiplying *N* and 30 minutes.
**updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used.| Number| Yes (initial value: **0**)| + | formConfigAbility | Link to a specific page of the application. The value is a URI.| String| Yes (initial value: left empty)| + | formVisibleNotify | Whether the widget is allowed to use the widget visibility notification.| String| Yes (initial value: left empty)| + | jsComponentName | Component name of the widget. The value is a string with a maximum of 127 bytes.| String| No| + | metaData | Metadata of the widget. This attribute contains the array of the **customizeData** attribute.| Object| Yes (initial value: left empty)| + | customizeData | Custom information about the widget.| Object array| Yes (initial value: left empty)| + + A configuration example is as follows: + + + ```json + "abilities": [{ + "name": "FormAbility", + "description": "This is a FormAbility", + "formsEnabled": true, + "icon": "$media:icon", + "label": "$string:form_FormAbility_label", + "srcPath": "FormAbility", + "type": "service", + "srcLanguage": "ets", + "formsEnabled": true, + "formConfigAbility": "ability://com.example.entry.MainAbility", + "forms": [{ + "colorMode": "auto", + "defaultDimension": "2*2", + "description": "This is a service widget.", + "formVisibleNotify": true, + "isDefault": true, + "jsComponentName": "widget", + "name": "widget", + "scheduledUpdateTime": "10:30", + "supportDimensions": ["2*2"], + "type": "JS", + "updateEnabled": true + }] + }] + ``` + + +### Persistently Storing Widget Data + +A widget provider is usually started when it is needed to provide information about a widget. The Widget Manager supports multi-instance management and uses the widget ID to identify an instance. If the widget provider supports widget data modification, it must persistently store the data based on the widget ID, so that it can access the data of the target widget when obtaining, updating, or starting a widget. + + +```ts +const DATA_STORAGE_PATH = "/data/storage/el2/base/haps/form_store"; +async function storeFormInfo(formId: string, formName: string, tempFlag: boolean) { + // Only the widget ID (formId), widget name (formName), and whether the widget is a temporary one (tempFlag) are persistently stored. + let formInfo = { + "formName": formName, + "tempFlag": tempFlag, + "updateCount": 0 + }; + try { + const storage = await dataStorage.getStorage(DATA_STORAGE_PATH); + // Put the widget information. + await storage.put(formId, JSON.stringify(formInfo)); + console.info(`storeFormInfo, put form info successfully, formId: ${formId}`); + await storage.flush(); + } catch (err) { + console.error(`failed to storeFormInfo, err: ${JSON.stringify(err)}`); + } +} + +// ... + onCreate(want) { + console.info('FormAbility onCreate'); + + let formId = want.parameters["ohos.extra.param.key.form_identity"]; + let formName = want.parameters["ohos.extra.param.key.form_name"]; + let tempFlag = want.parameters["ohos.extra.param.key.form_temporary"]; + // Persistently store widget information for subsequent use, such as instance acquisition and update. + // Implement this API based on project requirements. + storeFormInfo(formId, formName, tempFlag); + + let obj = { + "title": "titleOnCreate", + "detail": "detailOnCreate" + }; + let formData = formBindingData.createFormBindingData(obj); + return formData; + } +// ... +``` + +You should override **onDestroy** to implement widget data deletion. + + +```ts +const DATA_STORAGE_PATH = "/data/storage/el2/base/haps/form_store"; +async function deleteFormInfo(formId: string) { + try { + const storage = await dataStorage.getStorage(DATA_STORAGE_PATH); + // Delete the widget information. + await storage.delete(formId); + console.info(`deleteFormInfo, del form info successfully, formId: ${formId}`); + await storage.flush(); + } catch (err) { + console.error(`failed to deleteFormInfo, err: ${JSON.stringify(err)}`); + } +} + +// ... + onDestroy(formId) { + console.info('FormAbility onDestroy'); + // Delete the persistent widget instance data. + // Implement this API based on project requirements. + deleteFormInfo(formId); + } +// ... +``` + +For details about how to implement persistent data storage, see [Lightweight Data Store Development](../database/database-preference-guidelines.md). + +The **Want** object passed by the widget host to the widget provider contains a flag that specifies whether the requested widget is normal or temporary. + +- Normal widget: a widget persistently used by the widget host + +- Temporary widget: a widget temporarily used by the widget host + +Data of a temporary widget will be deleted on the Widget Manager if the widget framework is killed and restarted. The widget provider, however, is not notified of the deletion and still keeps the data. Therefore, the widget provider needs to clear the data of temporary widgets proactively if the data has been kept for a long period of time. If the widget host has converted a temporary widget into a normal one, the widget provider should change the widget data from temporary storage to persistent storage. Otherwise, the widget data may be deleted by mistake. + + +### Updating Widget Data + +When an application initiates a scheduled or periodic update, the application obtains the latest data and calls **updateForm()** to update the widget. + + +```ts +onUpdate(formId) { + // Override this method to support scheduled updates, periodic updates, or updates requested by the widget host. + console.info('FormAbility onUpdate'); + let obj = { + "title": "titleOnUpdate", + "detail": "detailOnUpdate" + }; + let formData = formBindingData.createFormBindingData(obj); + // Call the updateForm() method to update the widget. Only the data passed through the input parameter is updated. Other information remains unchanged. + formProvider.updateForm(formId, formData).catch((error) => { + console.info('FormAbility updateForm, error:' + JSON.stringify(error)); + }); +} +``` + + +### Developing the Widget UI Page + +You can use the web-like paradigm (HML+CSS+JSON) to develop JS widget pages. This section describes how to develop a page shown below. + +![widget-development-fa](figures/widget-development-fa.png) + +> **NOTE** +> +> Only the JavaScript-based web-like development paradigm is supported when developing the widget UI. + +- HML: uses web-like paradigm components to describe the widget page information. + + ```html +
+ +
+ +
+
+ {{title}} + {{detail}} +
+
+
+ ``` + +- CSS: defines style information about the web-like paradigm components in HML. + + ```css + .container { + flex-direction: column; + justify-content: center; + align-items: center; + } + + .bg-img { + flex-shrink: 0; + height: 100%; + } + + .container-inner { + flex-direction: column; + justify-content: flex-end; + align-items: flex-start; + height: 100%; + width: 100%; + padding: 12px; + } + + .title { + font-size: 19px; + font-weight: bold; + color: white; + text-overflow: ellipsis; + max-lines: 1; + } + + .detail_text { + font-size: 16px; + color: white; + opacity: 0.66; + text-overflow: ellipsis; + max-lines: 1; + margin-top: 6px; + } + ``` + +- JSON: defines data and event interaction on the widget UI page. + + ```json + { + "data": { + "title": "TitleDefault", + "detail": "TextDefault" + }, + "actions": { + "routerEvent": { + "action": "router", + "abilityName": "com.example.entry.MainAbility", + "params": { + "message": "add detail" + } + } + } + } + ``` + + +### Developing Widget Events + +You can set router and message events for components on a widget. The router event applies to ability redirection, and the message event applies to custom click events. The key steps are as follows: + +1. Set the **onclick** field in the HML file to **routerEvent** or **messageEvent**, depending on the **actions** settings in the JSON file. + +2. Set the router event. + - **action**: **router**, which indicates a router event. + - **abilityName**: name of the ability to redirect to (PageAbility component in the FA model and UIAbility component in the stage model). For example, the default MainAbility name of the FA model created by DevEco Studio is com.example.entry.MainAbility. + - **params**: custom parameters passed to the target ability. Set them as required. The value can be obtained from **parameters** in **want** used for starting the target ability. For example, in the lifecycle function **onCreate** of the main ability in the FA model, **featureAbility.getWant()** can be used to obtain **want** and its **parameters** field. + +3. Set the message event. + - **action**: **message**, which indicates a message event. + - **params**: custom parameters of the message event. Set them as required. The value can be obtained from **message** in the widget lifecycle function **onEvent**. + +The following is an example: + +- HML file: + + ```html +
+ +
+ +
+
+ {{title}} + {{detail}} +
+
+
+ ``` + +- CSS file: + + ```css + .container { + flex-direction: column; + justify-content: center; + align-items: center; + } + + .bg-img { + flex-shrink: 0; + height: 100%; + } + + .container-inner { + flex-direction: column; + justify-content: flex-end; + align-items: flex-start; + height: 100%; + width: 100%; + padding: 12px; + } + + .title { + font-size: 19px; + font-weight: bold; + color: white; + text-overflow: ellipsis; + max-lines: 1; + } + + .detail_text { + font-size: 16px; + color: white; + opacity: 0.66; + text-overflow: ellipsis; + max-lines: 1; + margin-top: 6px; + } + ``` + +- JSON file: + + ```json + { + "data": { + "title": "TitleDefault", + "detail": "TextDefault" + }, + "actions": { + "routerEvent": { + "action": "router", + "abilityName": "com.example.entry.MainAbility", + "params": { + "message": "add detail" + } + }, + "messageEvent": { + "action": "message", + "params": { + "message": "add detail" + } + } + } + } + ``` + diff --git a/en/application-dev/application-models/widget-development-stage.md b/en/application-dev/application-models/widget-development-stage.md new file mode 100644 index 0000000000000000000000000000000000000000..38f4e89d108d9d012c968b3d05de5b4e841ff482 --- /dev/null +++ b/en/application-dev/application-models/widget-development-stage.md @@ -0,0 +1,600 @@ +# FormExtensionAbility (Widget) + + +## Widget Overview + +FormExtensionAbility provides a service widget (also called widget), which is a set of UI components that display important information or operations specific to an application. It provides users with direct access to a desired application service, without the need to open the application first. + +A widget usually appears as a part of the UI of another application (which currently can only be a system application) and provides basic interactive features such as opening a UI page or sending a message. + +Before you get started, it would be helpful if you have a basic understanding of the following concepts: + +- Widget host: an application that displays the widget content and controls the widget location. + +- Widget Manager: a resident agent that provides widget management features such as periodic widget updates. + +- Widget provider: an atomic service that provides the widget content to display and controls how widget components are laid out and how they interact with users. + + +## Working Principles + +Figure 1 shows the working principles of the widget framework. + +**Figure 1** Widget framework working principles in the stage model +![form-extension](figures/form-extension.png) + +The widget host consists of the following modules: + +- Widget usage: provides operations such as creating, deleting, or updating a widget. + +- Communication adapter: provided by the OpenHarmony SDK for communication with the Widget Manager. It sends widget-related operations to the Widget Manager. + +The Widget Manager consists of the following modules: + +- Periodic updater: starts a scheduled task based on the update policy to periodically update a widget after it is added to the Widget Manager. + +- Cache manager: caches view information of a widget after it is added to the Widget Manager to directly return the cached data when the widget is obtained next time. This reduces the latency greatly. + +- Lifecycle manager: suspends update when a widget is switched to the background or is blocked, and updates and/or clears widget data during upgrade and deletion. + +- Object manager: manages RPC objects of the widget host. It is used to verify requests from the widget host and process callbacks after the widget update. + +- Communication adapter: communicates with the widget host and provider through RPCs. + +The widget provider consists of the following modules: + +- Widget service: implemented by the widget provider developer to process requests on widget creation, update, and deletion, and to provide corresponding widget services. + +- Instance manager: implemented by the widget provider developer for persistent management of widget instances allocated by the Widget Manager. + +- Communication adapter: provided by the OpenHarmony SDK for communication with the Widget Manager. It pushes update data to the Widget Manager. + +> **NOTE** +> +> You only need to develop the widget provider. The system automatically handles the work of the widget host and Widget Manager. + + +## Available APIs + +The **FormExtensionAbility** class has the following APIs. For details, see [FormExtensionAbility](../reference/apis/js-apis-app-form-formExtensionAbility.md). + +| API| Description| +| -------- | -------- | +| onAddForm(want: Want): formBindingData.FormBindingData | Called to notify the widget provider that a widget has been created.| +| onCastToNormalForm(formId: string): void | Called to notify the widget provider that a temporary widget has been converted to a normal one.| +| onUpdateForm(formId: string): void | Called to notify the widget provider that a widget has been updated.| +| onChangeFormVisibility(newStatus: { [key: string]: number }): void | Called to notify the widget provider of the change in widget visibility.| +| onFormEvent(formId: string, message: string): void | Called to instruct the widget provider to receive and process a widget event.| +| onRemoveForm(formId: string): void| Called to notify the widget provider that a widget has been destroyed.| +| onConfigurationUpdate(config: Configuration): void | Called when the configuration of the environment where the widget is running is updated.| +| onShareForm?(formId: string): { [key: string]: any }| Called by the widget provider to receive shared widget data.| + +The **FormExtensionAbility** class also has a member context, that is, the FormExtensionContext class. For details, see [FormExtensionContext](../reference/apis/js-apis-inner-application-formExtensionContext.md). + +| API| Description| +| -------- | -------- | +| startAbility(want: Want, callback: AsyncCallback<void>): void | Starts UIAbility of the application to which a widget belongs. This API uses an asynchronous callback to return the result. (This is a system API and cannot be called by third-party applications. You must apply for the permission to use the API.)| +| startAbility(want: Want): Promise<void> | Starts UIAbility of the application to which a widget belongs. This API uses a promise to return the result. (This is a system API and cannot be called by third-party applications. You must apply for the permission to use the API.)| + +The **FormProvider** class has the following APIs. For details, see [FormProvider](../reference/apis/js-apis-app-form-formProvider.md). + +| API| Description| +| -------- | -------- | +| setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback<void>): void; | Sets the next refresh time for a widget. This API uses an asynchronous callback to return the result.| +| setFormNextRefreshTime(formId: string, minute: number): Promise<void>; | Sets the next refresh time for a widget. This API uses a promise to return the result.| +| updateForm(formId: string, formBindingData: FormBindingData, callback: AsyncCallback<void>): void; | Updates a widget. This API uses an asynchronous callback to return the result.| +| updateForm(formId: string, formBindingData: FormBindingData): Promise<void>;| Updates a widget. This API uses a promise to return the result.| + +The **FormBindingData** class has the following APIs. For details, see [FormBindingData](../reference/apis/js-apis-app-form-formBindingData.md). + +| API| Description| +| -------- | -------- | +| createFormBindingData(obj?: Object \ string): FormBindingData| | Creates a **FormBindingData** object.| + + +## How to Develop + +The widget provider development based on the [stage model](stage-model-development-overview.md) involves the following key steps: + +- [Creating a FormExtensionAbility Instance](#creating-a-formextensionability-instance): Develop the lifecycle callback functions of FormExtensionAbility. + +- [Configuring the Widget Configuration File](#configuring-the-widget-configuration-file): Configure the application configuration file **module.json5** and profile configuration file. + +- [Persistently Storing Widget Data](#persistently-storing-widget-data): Perform persistent management on widget information. + +- [Updating Widget Data](#updating-widget-data): Call **updateForm()** to update the information displayed on a widget. + +- [Developing the Widget UI Page](#developing-the-widget-ui-page): Use HML+CSS+JSON to develop a JS widget UI page. + +- [Developing Widget Events](#developing-widget-events): Add the router and message events for a widget. + + +### Creating a FormExtensionAbility Instance + +To create a widget in the stage model, implement the lifecycle callbacks of **FormExtensionAbility**. Generate a widget template by referring to [Developing a Service Widget](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-development-service-widget-0000001263280425). + +1. Import related modules to **EntryFormAbility.ts**. + + ```ts + import FormExtension from '@ohos.app.form.FormExtensionAbility'; + import formBindingData from '@ohos.app.form.formBindingData'; + import formInfo from '@ohos.app.form.formInfo'; + import formProvider from '@ohos.app.form.formProvider'; + import dataStorage from '@ohos.data.storage'; + ``` + +2. Implement the FormExtension lifecycle callbacks in **EntryFormAbility.ts**. + + ```ts + export default class EntryFormAbility extends FormExtension { + onAddForm(want) { + console.info('[EntryFormAbility] onAddForm'); + // Called when the widget is created. The widget provider should return the widget data binding class. + let obj = { + "title": "titleOnCreate", + "detail": "detailOnCreate" + }; + let formData = formBindingData.createFormBindingData(obj); + return formData; + } + onCastToNormalForm(formId) { + // Called when the widget host converts the temporary widget into a normal one. The widget provider should do something to respond to the conversion. + console.info('[EntryFormAbility] onCastToNormalForm'); + } + onUpdateForm(formId) { + // Override this method to support scheduled updates, periodic updates, or updates requested by the widget host. + console.info('[EntryFormAbility] onUpdateForm'); + let obj = { + "title": "titleOnUpdate", + "detail": "detailOnUpdate" + }; + let formData = formBindingData.createFormBindingData(obj); + formProvider.updateForm(formId, formData).catch((error) => { + console.info('[EntryFormAbility] updateForm, error:' + JSON.stringify(error)); + }); + } + onChangeFormVisibility(newStatus) { + // Called when the widget host initiates an event about visibility changes. The widget provider should do something to respond to the notification. This callback takes effect only for system applications. + console.info('[EntryFormAbility] onChangeFormVisibility'); + } + onFormEvent(formId, message) { + // If the widget supports event triggering, override this method and implement the trigger. + console.info('[EntryFormAbility] onFormEvent'); + } + onRemoveForm(formId) { + // Delete widget data. + console.info('[EntryFormAbility] onRemoveForm'); + } + onConfigurationUpdate(config) { + console.info('[EntryFormAbility] nConfigurationUpdate, config:' + JSON.stringify(config)); + } + onAcquireFormState(want) { + return formInfo.FormState.READY; + } + } + ``` + +> **NOTE** +> +> FormExtensionAbility cannot reside in the background. Therefore, continuous tasks cannot be processed in the widget lifecycle callbacks. + +### Configuring the Widget Configuration File + +1. Configure ExtensionAbility information under **extensionAbilities** in the [module.json5 file](../quick-start/module-configuration-file.md). For a FormExtensionAbility, you must specify **metadata**. Specifically, set **name** to **ohos.extension.form** (fixed), and set **resource** to the index of the widget configuration information. + A configuration example is as follows: + + + ```json + { + "module": { + // ... + "extensionAbilities": [ + { + "name": "EntryFormAbility", + "srcEntrance": "./ets/entryformability/EntryFormAbility.ts", + "label": "$string:EntryFormAbility_label", + "description": "$string:EntryFormAbility_desc", + "type": "form", + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:form_config" + } + ] + } + ] + } + } + ``` + +2. Configure the widget configuration information. In the **metadata** configuration item of FormExtensionAbility, you can specify the resource index of specific configuration information of the widget. For example, if resource is set to **$profile:form_config**, **form_config.json** in the **resources/base/profile/** directory of the development view is used as the profile configuration file of the widget. The following table describes the internal field structure. + **Table 1** Widget profile configuration file + + | Field| Description| Data Type| Initial Value Allowed| + | -------- | -------- | -------- | -------- | + | name | Class name of a widget. The value is a string with a maximum of 127 bytes.| String| No| + | description | Description of the widget. The value can be a string or a resource index to descriptions in multiple languages. The value is a string with a maximum of 255 bytes.| String| Yes (initial value: left empty)| + | src | Full path of the UI code corresponding to the widget.| String| No| + | window | Window-related configurations.| Object| Yes| + | isDefault | Whether the widget is a default one. Each ability has only one default widget.
**true**: The widget is the default one.
**false**: The widget is not the default one.| Boolean| No| + | colorMode | Color mode of the widget.
**auto**: The widget adopts the auto-adaptive color mode.
**dark**: The widget adopts the dark color mode.
**light**: The widget adopts the light color mode.| String| Yes (initial value: **auto**)| + | supportDimensions | Grid styles supported by the widget.
**1 * 2**: indicates a grid with one row and two columns.
**2 * 2**: indicates a grid with two rows and two columns.
**2 * 4**: indicates a grid with two rows and four columns.
**4 * 4**: indicates a grid with four rows and four columns.| String array| No| + | defaultDimension | Default grid style of the widget. The value must be available in the **supportDimensions** array of the widget.| String| No| + | updateEnabled | Whether the widget can be updated periodically.
**true**: The widget can be updated at a specified interval (**updateDuration**) or at the scheduled time (**scheduledUpdateTime**). **updateDuration** takes precedence over **scheduledUpdateTime**.
**false**: The widget cannot be updated periodically.| Boolean| No| + | scheduledUpdateTime | Scheduled time to update the widget. The value is in 24-hour format and accurate to minute.
**updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used.| String| Yes (initial value: **0:0**)| + | updateDuration | Interval to update the widget. The value is a natural number, in the unit of 30 minutes.
If the value is **0**, this attribute does not take effect.
If the value is a positive integer *N*, the interval is calculated by multiplying *N* and 30 minutes.
**updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used.| Number| Yes (initial value: **0**)| + | formConfigAbility | Link to a specific page of the application. The value is a URI.| String| Yes (initial value: left empty)| + | formVisibleNotify | Whether the widget is allowed to use the widget visibility notification.| String| Yes (initial value: left empty)| + | metaData | Metadata of the widget. This attribute contains the array of the **customizeData** attribute.| Object| Yes (initial value: left empty)| + + A configuration example is as follows: + + ```json + { + "forms": [ + { + "name": "widget", + "description": "This is a service widget.", + "src": "./js/widget/pages/index/index", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": true, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] + } + ``` + + +### Persistently Storing Widget Data + +A widget provider is usually started when it is needed to provide information about a widget. The Widget Manager supports multi-instance management and uses the widget ID to identify an instance. If the widget provider supports widget data modification, it must persistently store the data based on the widget ID, so that it can access the data of the target widget when obtaining, updating, or starting a widget. + + +```ts +const DATA_STORAGE_PATH = "/data/storage/el2/base/haps/form_store"; +async function storeFormInfo(formId: string, formName: string, tempFlag: boolean) { + // Only the widget ID (formId), widget name (formName), and whether the widget is a temporary one (tempFlag) are persistently stored. + let formInfo = { + "formName": formName, + "tempFlag": tempFlag, + "updateCount": 0 + }; + try { + const storage = await dataStorage.getStorage(DATA_STORAGE_PATH); + // Put the widget information. + await storage.put(formId, JSON.stringify(formInfo)); + console.info(`[EntryFormAbility] storeFormInfo, put form info successfully, formId: ${formId}`); + await storage.flush(); + } catch (err) { + console.error(`[EntryFormAbility] failed to storeFormInfo, err: ${JSON.stringify(err)}`); + } +} + +export default class EntryFormAbility extends FormExtension { + // ... + onAddForm(want) { + console.info('[EntryFormAbility] onAddForm'); + + let formId = want.parameters["ohos.extra.param.key.form_identity"]; + let formName = want.parameters["ohos.extra.param.key.form_name"]; + let tempFlag = want.parameters["ohos.extra.param.key.form_temporary"]; + // Persistently store widget information for subsequent use, such as instance acquisition and update. + // Implement this API based on project requirements. + storeFormInfo(formId, formName, tempFlag); + + let obj = { + "title": "titleOnCreate", + "detail": "detailOnCreate" + }; + let formData = formBindingData.createFormBindingData(obj); + return formData; + } +} +``` + +You should override **onRemoveForm** to implement widget data deletion. + + +```ts +const DATA_STORAGE_PATH = "/data/storage/el2/base/haps/form_store"; +async function deleteFormInfo(formId: string) { + try { + const storage = await dataStorage.getStorage(DATA_STORAGE_PATH); + // Delete the widget information. + await storage.delete(formId); + console.info(`[EntryFormAbility] deleteFormInfo, del form info successfully, formId: ${formId}`); + await storage.flush(); + } catch (err) { + console.error(`[EntryFormAbility] failed to deleteFormInfo, err: ${JSON.stringify(err)}`); + } +} + +// ... + +export default class EntryFormAbility extends FormExtension { + // ... + onRemoveForm(formId) { + console.info('[EntryFormAbility] onRemoveForm'); + // Delete the persistent widget instance data. + // Implement this API based on project requirements. + deleteFormInfo(formId); + } +} +``` + +For details about how to implement persistent data storage, see [Lightweight Data Store Development](../database/database-preference-guidelines.md). + +The **Want** object passed by the widget host to the widget provider contains a flag that specifies whether the requested widget is normal or temporary. + +- Normal widget: a widget persistently used by the widget host + +- Temporary widget: a widget temporarily used by the widget host + +Data of a temporary widget will be deleted on the Widget Manager if the widget framework is killed and restarted. The widget provider, however, is not notified of the deletion and still keeps the data. Therefore, the widget provider needs to clear the data of temporary widgets proactively if the data has been kept for a long period of time. If the widget host has converted a temporary widget into a normal one, the widget provider should change the widget data from temporary storage to persistent storage. Otherwise, the widget data may be deleted by mistake. + + +### Updating Widget Data + +When an application initiates a scheduled or periodic update, the application obtains the latest data and calls **updateForm()** to update the widget. + + +```ts +onUpdateForm(formId) { + // Override this method to support scheduled updates, periodic updates, or updates requested by the widget host. + console.info('[EntryFormAbility] onUpdateForm'); + let obj = { + "title": "titleOnUpdate", + "detail": "detailOnUpdate" + }; + let formData = formBindingData.createFormBindingData(obj); + // Call the updateForm() method to update the widget. Only the data passed through the input parameter is updated. Other information remains unchanged. + formProvider.updateForm(formId, formData).catch((error) => { + console.info('[EntryFormAbility] updateForm, error:' + JSON.stringify(error)); + }); +} +``` + + +### Developing the Widget UI Page + +You can use the web-like paradigm (HML+CSS+JSON) to develop JS widget pages. This section describes how to develop a page shown below. + +![widget-development-stage](figures/widget-development-stage.png) + +> **NOTE** +> +> Only the JavaScript-based web-like development paradigm is supported when developing the widget UI. + +- HML: uses web-like paradigm components to describe the widget page information. + + ```html +
+ +
+ +
+
+ {{title}} + {{detail}} +
+
+
+ ``` + +- CSS: defines style information about the web-like paradigm components in HML. + + ```css + .container { + flex-direction: column; + justify-content: center; + align-items: center; + } + + .bg-img { + flex-shrink: 0; + height: 100%; + } + + .container-inner { + flex-direction: column; + justify-content: flex-end; + align-items: flex-start; + height: 100%; + width: 100%; + padding: 12px; + } + + .title { + font-size: 19px; + font-weight: bold; + color: white; + text-overflow: ellipsis; + max-lines: 1; + } + + .detail_text { + font-size: 16px; + color: white; + opacity: 0.66; + text-overflow: ellipsis; + max-lines: 1; + margin-top: 6px; + } + ``` + +- JSON: defines data and event interaction on the widget UI page. + + ```json + { + "data": { + "title": "TitleDefault", + "detail": "TextDefault" + }, + "actions": { + "routerEvent": { + "action": "router", + "abilityName": "EntryAbility", + "params": { + "message": "add detail" + } + } + } + } + ``` + + +### Developing Widget Events + +You can set router and message events for components on a widget. The router event applies to ability redirection, and the message event applies to custom click events. + +The key steps are as follows: + +1. Set the **onclick** field in the HML file to **routerEvent** or **messageEvent**, depending on the **actions** settings in the JSON file. + +2. Set the router event. + - **action**: **router**, which indicates a router event. + - **abilityName**: name of the ability to redirect to (PageAbility component in the FA model and UIAbility component in the stage model). For example, the default UIAbility name of the stage model created by DevEco Studio is EntryAbility. + - **params**: custom parameters passed to the target ability. Set them as required. The value can be obtained from **parameters** in **want** used for starting the target ability. For example, in the lifecycle function **onCreate** of the main ability in the stage model, you can obtain **want** and its **parameters** field. + +3. Set the message event. + - **action**: **message**, which indicates a message event. + - **params**: custom parameters of the message event. Set them as required. The value can be obtained from **message** in the widget lifecycle function **onFormEvent()**. + +The following is an example: + +- HML file: + + ```html +
+ +
+ +
+
+ {{title}} + {{detail}} +
+
+
+ ``` + +- CSS file: + + ```css + .container { + flex-direction: column; + justify-content: center; + align-items: center; + } + + .bg-img { + flex-shrink: 0; + height: 100%; + } + + .container-inner { + flex-direction: column; + justify-content: flex-end; + align-items: flex-start; + height: 100%; + width: 100%; + padding: 12px; + } + + .title { + font-size: 19px; + font-weight: bold; + color: white; + text-overflow: ellipsis; + max-lines: 1; + } + + .detail_text { + font-size: 16px; + color: white; + opacity: 0.66; + text-overflow: ellipsis; + max-lines: 1; + margin-top: 6px; + } + ``` + +- JSON file: + + ```json + { + "data": { + "title": "TitleDefault", + "detail": "TextDefault" + }, + "actions": { + "routerEvent": { + "action": "router", + "abilityName": "EntryAbility", + "params": { + "info": "router info", + "message": "router message" + } + }, + "messageEvent": { + "action": "message", + "params": { + "detail": "message detail" + } + } + } + } + ``` + +- Receive the router event and obtain parameters in UIAbility. + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility' + + export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + // Obtain the info parameter passed in the router event. + if (want.parameters.info === "router info") { + // Do something. + // console.log("router info:" + want.parameters.info) + } + // Obtain the message parameter passed in the router event. + if (want.parameters.message === "router message") { + // Do something. + // console.log("router message:" + want.parameters.message) + } + } + // ... + }; + ``` + +- Receive the message event in FormExtensionAbility and obtain parameters. + + ```ts + import FormExtension from '@ohos.app.form.FormExtensionAbility'; + + export default class FormAbility extends FormExtension { + // ... + onFormEvent(formId, message) { + // Obtain the detail parameter passed in the message event. + let msg = JSON.parse(message) + if (msg.params.detail === "message detail") { + // Do something. + // console.log("message info:" + msg.params.detail) + } + } + // ... + }; + ``` + + \ No newline at end of file diff --git a/en/application-dev/application-models/widget-switch.md b/en/application-dev/application-models/widget-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..8d9823385a8a05f71c742327dc966054427a6718 --- /dev/null +++ b/en/application-dev/application-models/widget-switch.md @@ -0,0 +1,48 @@ +# Widget Switching + + +Widget switching involves the following parts: + + +- Widget UI layout: Both the FA model and stage model use the web-like paradigm to develop the widget UI layout. Therefore, the UI layout of a widget in the FA model can be directly reused in the stage mode. +- Widget configuration file: Widgets are configured in the **config.json** file in the FA model and in **module.json5** and **form_config.json** files in the stage model (as shown in Figure 1 and Figure 2). +- Widget service logic: The widget entry file and lifecycle of the FA model are slightly different from those of the stage model, as shown in Figure 3 and Figure 4. + +| Configuration Item | FA Model | Stage Model | +| ---------------- | ------------------------------------------- | ------------------------------------------------------------ | +| Configuration item location | **formAbility** and **forms** are in the **config.json** file.| **extensionAbilities** (configuration for **formExtensionAbility**) is in the **module.json5** file in the level-1 directory, and **forms** (configuration for **forms** contained in **formExtensionAbility**) is in the **form_config.json** file in the level-2 directory.| +| Widget code path | Specified by **srcPath**, without the file name. | Specified by **srcEntrance**, with the file name. | +| Programming language | **srcLanguage** can be set to **js** or **ets**. | This configuration item is unavailable. Only ets is supported. | +| Whether to enable widgets | formsEnabled | This configuration item is unavailable. The setting of **type** set to **form** means that the widgets are enabled. | +| Ability type | type: service | type: form | +| Level-2 directory configuration tag| This configuration item is unavailable. | **metadata**, which consists of **name**, **value**, and **resource**, where **resource** points to the location of the **form_config.json** file in the level-2 directory.| + + +Figure 1 Entry configuration differences + + +![widget-switch1](figures/widget-switch1.png) + + +Figure 2 Widget configuration differences + + +![widget-switch2](figures/widget-switch2.png) + + +| Item| FA Model| Stage Model| +| -------- | -------- | -------- | +| Entry file| **form.ts** in the directory pointed to by **srcPath**| File pointed to by **srcEntrance**| +| Lifecycle| export default| import FormExtension from '\@ohos.app.form.FormExtensionAbility';
export default class FormAbility extends FormExtension| + + +Figure 3 Entry file differences + + +![widget-switch3](figures/widget-switch3.png) + + +Figure 4 Lifecycle differences (The lifecycle callbacks are the same and require no adjustment.) + + +![widget-switch4](figures/widget-switch4.png) diff --git a/en/application-dev/application-models/window-properties.md b/en/application-dev/application-models/window-properties.md new file mode 100644 index 0000000000000000000000000000000000000000..250476f05f7fc66b5deaa52ee2e4905f8de0edf6 --- /dev/null +++ b/en/application-dev/application-models/window-properties.md @@ -0,0 +1,4 @@ +# Window Properties + + +For details about the APIs for obtaining a window instance and setting window properties, see [Application Window Development (FA Model)](../windowmanager/application-window-fa.md). diff --git a/en/application-dev/application-models/window-switch.md b/en/application-dev/application-models/window-switch.md new file mode 100644 index 0000000000000000000000000000000000000000..379f0282b1e50e856d0010a9087622e2e1363d89 --- /dev/null +++ b/en/application-dev/application-models/window-switch.md @@ -0,0 +1,8 @@ +# window Switching + + +| API in the FA Model| Corresponding d.ts File in the Stage Model| Corresponding API in the Stage Model| +| -------- | -------- | -------- | +| [create(id: string, type: WindowType, callback: AsyncCallback<Window>): void;](../reference/apis/js-apis-window.md#windowcreatedeprecated)
[create(id: string, type: WindowType): Promise<Window>;](../reference/apis/js-apis-window.md#windowcreatedeprecated-1) | \@ohos.window.d.ts | [createSubWindow(name: string, callback: AsyncCallback<Window>): void;](../reference/apis/js-apis-window.md#createsubwindow9)
[createSubWindow(name: string): Promise;](../reference/apis/js-apis-window.md#createsubwindow9-1)
An application developed on the FA model uses **window.create(id, WindowType.TYPE_APP)** to create a subwindow, whereas an application developed on the stage model uses **WindowStage.CreateSubWindow()** to create a subwindow.| +| [getTopWindow(callback: AsyncCallback<Window>): void;](../reference/apis/js-apis-window.md#windowgettopwindowdeprecated)
[getTopWindow(): Promise<Window>;](../reference/apis/js-apis-window.md#windowgettopwindowdeprecated-1) | \@ohos.window.d.ts | [getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void;](../reference/apis/js-apis-window.md#windowgetlastwindow9)
[getLastWindow(ctx: BaseContext): Promise<Window>;](../reference/apis/js-apis-window.md#windowgetlastwindow9-1) | + diff --git a/en/application-dev/dfx/Readme-EN.md b/en/application-dev/dfx/Readme-EN.md index af9e5d190ab515b61be1c7441d72e264c87ca310..b8a4496e09420b3a7557e5c8b8996deaf14ce1c9 100644 --- a/en/application-dev/dfx/Readme-EN.md +++ b/en/application-dev/dfx/Readme-EN.md @@ -1,14 +1,8 @@ # DFX -- Application Event Logging - - [Overview of Application Event Logging](hiappevent-overview.md) - - [Development of Application Event Logging](hiappevent-guidelines.md) -- Performance Tracing - - [Overview of Performance Tracing](hitracemeter-overview.md) - - [Development of Performance Tracing](hitracemeter-guidelines.md) -- Distributed Call Chain Tracing - - [Overview of Distributed Call Chain Tracing](hitracechain-overview.md) - - [Development of Distributed Call Chain Tracing](hitracechain-guidelines.md) +- [Development of Application Event Logging](hiappevent-guidelines.md) +- [Development of Performance Tracing](hitracemeter-guidelines.md) +- [Development of Distributed Call Chain Tracing](hitracechain-guidelines.md) - Error Management - [Development of Error Manager](errormanager-guidelines.md) - [Development of Application Recovery](apprecovery-guidelines.md) diff --git a/en/application-dev/dfx/apprecovery-guidelines.md b/en/application-dev/dfx/apprecovery-guidelines.md index 0e4e7c257cbde0853a36bd8a3729ee707a4b2391..b2992e7c9958f0a1ffd87db9e4549bf0187bad78 100644 --- a/en/application-dev/dfx/apprecovery-guidelines.md +++ b/en/application-dev/dfx/apprecovery-guidelines.md @@ -17,7 +17,7 @@ The application recovery APIs are provided by the **appRecovery** module, which | API | Description | | ------------------------------------------------------------ | ------------------------------------------------------------ | -| enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMode?: SaveModeFlag) : void; | Enables the application recovery function. | +| enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMode?: SaveModeFlag) : void; | Enables the application recovery function. | | saveAppState(): boolean; | Saves the ability status of an application. | | restartApp(): void; | Restarts the current process. If there is saved ability status, it will be passed to the **want** parameter's **wantParam** attribute of the **onCreate** lifecycle callback of the ability.| diff --git a/en/application-dev/dfx/errormanager-guidelines.md b/en/application-dev/dfx/errormanager-guidelines.md index 835a6ab9ce3c0beacd19f7c76f5a1eec68bf36cd..631445b862097d5aa71320ff154d6e235660a95e 100644 --- a/en/application-dev/dfx/errormanager-guidelines.md +++ b/en/application-dev/dfx/errormanager-guidelines.md @@ -48,28 +48,28 @@ var callback = { export default class MainAbility extends Ability { onCreate(want, launchParam) { console.log("[Demo] MainAbility onCreate") + registerId = errorManager.registerErrorObserver(callback); globalThis.abilityWant = want; } onDestroy() { console.log("[Demo] MainAbility onDestroy") + errorManager.unregisterErrorObserver(registerId, (result) => { + console.log("[Demo] result " + result.code + ";" + result.message) + }); } onWindowStageCreate(windowStage) { // Main window is created for this ability. console.log("[Demo] MainAbility onWindowStageCreate") - globalThis.registerObserver = (() => { - registerId = errorManager.registerErrorObserver(callback); - }) - - globalThis.unRegisterObserver = (() => { - errorManager.unregisterErrorObserver(registerId, (result) => { - console.log("[Demo] result " + result.code + ";" + result.message) - }); - }) - - windowStage.setUIContent(this.context, "pages/index", null) + 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)) + }); } onWindowStageDestroy() { diff --git a/en/application-dev/dfx/figures/fault_rectification.png b/en/application-dev/dfx/figures/fault_rectification.png index 63ac5e5f666d5c23c9e9ea3123a9566013336aba..67aa40592f7bcad23e216222e898c1f1327a4efb 100644 Binary files a/en/application-dev/dfx/figures/fault_rectification.png and b/en/application-dev/dfx/figures/fault_rectification.png differ diff --git a/en/application-dev/dfx/hiappevent-guidelines.md b/en/application-dev/dfx/hiappevent-guidelines.md index 067b9b8c915417b93340ab55bf34a74bca422a3d..6343b502fad6e7572f1d08eee1debd6cd8407061 100644 --- a/en/application-dev/dfx/hiappevent-guidelines.md +++ b/en/application-dev/dfx/hiappevent-guidelines.md @@ -1,12 +1,29 @@ # Development of Application Event Logging -## When to Use +## Introduction -The event logging function helps applications log various information generated during running. +A traditional log system aggregates log information generated by all applications running on the entire device, making it difficult to identify key information in the log. Therefore, an effective logging mechanism is needed to evaluate mission-critical information, for example, number of visits, number of daily active users, user operation habits, and key factors that affect application usage. -## Available APIs +HiAppEvent is a module that provides the event logging function for applications to log the fault, statistical, security, and user behavior events reported during running. Based on event information, you will be able to analyze the running status of applications. + +## Basic Concepts + +- **Logging** + + Logs changes caused by user operations to provide service data for development, product, and O&M analysis. + +## Event Design Specifications -JS application event logging APIs are provided by the **hiAppEvent** module. +- Event domain: identifies the domain of an event. You are advised to set this parameter to the service module name to differentiate service modules. +- Event name: specifies the name of an event. You are advised to set this parameter to a specific service name to differentiate services. +- Event type: specifies the type of an event. Four event types are supported: + - Behavior event: used to record the daily operation behavior of a user, for example, button click and page redirection. + - Fault event: used to locate and analyze application faults, for example, frame freezing, network disconnection, and call drop. + - Statistical event: used to collect statistics on key application behaviors, for example, usage duration and number of visits. + - Security event: used to record events related to application security, for example, password change and user authorization. +- Event parameter: specifies the parameters of an event. Each event can contain a group of parameters. You are advised to set this parameter to an event attribute or event context to depict the event details. + +## Available APIs The following table provides only a brief description of related APIs. For details, see [HiAppEvent](../reference/apis/js-apis-hiviewdfx-hiappevent.md). @@ -17,33 +34,68 @@ The following table provides only a brief description of related APIs. For detai | write(AppEventInfo info, AsyncCallback\ callback): void | Logs application events in asynchronous mode. This API uses an asynchronous callback to return the result.| | write(AppEventInfo info): Promise\ | Logs application events in asynchronous mode. This API uses a promise to return the result. | -**Table 2** APIs for event logging configuration - -| API | Description | -| ------------------------------------ | ---------------------------------------------------- | -| configure(ConfigOption config): void | Sets the configuration options for application event logging.| - **Table 3** APIs for watcher management -| API | Description | -| -------------------------------------------------- | -------------------- | -| addWatcher(Watcher watcher): AppEventPackageHolder | Adds an event watcher.| -| removeWatcher(Watcher watcher): void | Removes an event watcher.| +| API | Description | +| -------------------------------------------------- | -------------------------------------------- | +| addWatcher(Watcher watcher): AppEventPackageHolder | Adds an event watcher to subscribe to expected application events.| +| removeWatcher(Watcher watcher): void | Adds an event watcher to unsubscribe from expected application events.| -**Table 4** APIs for clearing logging data +## How to Develop -| API | Description | -| ----------------- | -------------------- | -| clearData(): void | Clears local logging data.| +The following example illustrates how to log and subscribe to button click events of users. -## How to Develop +1. Create an eTS application project. In the displayed **Project** window, choose **entry** > **src** > **main** > **ets** > **entryability** > **EntryAbility.ts**, and double-click **EntryAbility.ts**. Then, add an event watcher to subscribe to button click events. The complete sample code is as follows: -The following uses a one-time event watcher as an example to illustrate the development procedure. + ```js + import hilog from '@ohos.hilog'; + import Ability from '@ohos.application.Ability' + import Window from '@ohos.window' + import hiAppEvent from '@ohos.hiviewdfx.hiAppEvent' + + export default class EntryAbility extends Ability { + onCreate(want, launchParam) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); + + hiAppEvent.addWatcher({ + // Add a watcher. You can customize the watcher name. The system identifies different watchers based on their names. + name: "watcher1", + // Subscribe to application events you are interested in, for example, button click events. + appEventFilters: [{ domain: "button" }], + // Set the subscription callback trigger condition. In this example, a callback is triggered if one event is logged. + triggerCondition: { row: 1 }, + // Implement the subscription callback function to apply custom processing to the event logging data obtained through subscription. + onTrigger: function (curRow, curSize, holder) { + // If the watcher incurs an error while it is working, return a null holder object after recording the error in the log. + if (holder == null) { + hilog.error(0x0000, 'testTag', "HiAppEvent holder is null") + return + } + let eventPkg = null + // Fetch the subscription event package based on the specified threshold (512 KB by default) until all subscription event data is fetched. + // If all subscription event data is fetched, return a null event package object. The subscription callback process is ended. + while ((eventPkg = holder.takeNext()) != null) { + // Apply custom processing to the event logging data in the event package, for example, print the event logging data in the log. + hilog.info(0x0000, 'testTag', `HiAppEvent eventPkg.packageId=%{public}d`, eventPkg.packageId) + hilog.info(0x0000, 'testTag', `HiAppEvent eventPkg.row=%{public}d`, eventPkg.row) + hilog.info(0x0000, 'testTag', `HiAppEvent eventPkg.size=%{public}d`, eventPkg.size) + for (const eventInfo of eventPkg.data) { + hilog.info(0x0000, 'testTag', `HiAppEvent eventPkg.info=%{public}s`, eventInfo) + } + } + } + }) + } + } -1. Create an eTS application project. In the displayed **Project** window, choose **entry** > **src** > **main** > **ets** > **pages** > **index.ets**, and double-click **index.ets**. Then, add three buttons to simulate the process of watching for application events. Wherein, button 1 is used to invoke application event logging, button 2 to add an event watcher that automatically triggers a callback, and button 3 to remove the watcher. The complete sample code is as follows: +2. Choose **entry** > **src** > **main** > **ets** > **pages** > **index.ets**, and double-click **index.ets**. Then, add a button, and enable logging of button click events in its **onClick** function. The complete sample code is as follows: - ```ts - import hiAppEvent from '@ohos.hiviewdfx.hiAppEvent'; + ```js + import hiAppEvent from '@ohos.hiviewdfx.hiAppEvent' + import hilog from '@ohos.hilog' @Entry @Component @@ -57,61 +109,21 @@ The following uses a one-time event watcher as an example to illustrate the deve .fontSize(50) .fontWeight(FontWeight.Bold) - Button("1 writeTest").onClick(()=>{ - // Perform event logging based on the input event parameters. + Button("writeTest").onClick(()=>{ + // Enable event logging in the button click function to log button click events. hiAppEvent.write({ - domain: "test_domain", - name: "test_event", - eventType: hiAppEvent.EventType.FAULT, - params: { - int_data: 100, - str_data: "strValue" - } + // Define the event domain. + domain: "button", + // Define the event name. + name: "click", + // Define the event type. + eventType: hiAppEvent.EventType.BEHAVIOR, + // Define event parameters. + params: { click_time: 100 } }).then(() => { - console.log(`HiAppEvent success to write event`); + hilog.info(0x0000, 'testTag', `HiAppEvent success to write event`) }).catch((err) => { - console.error(`code: ${err.code}, message: ${err.message}`); - }); - }) - - Button("2 addWatcherTest").onClick(()=>{ - // Add an event watcher based on the input subscription parameters. - hiAppEvent.addWatcher({ - name: "watcher1", - appEventFilters: [{ domain: "test_domain" }], - triggerCondition: { - row: 2, - size: 1000, - timeOut: 2 - }, - onTrigger: function (curRow, curSize, holder) { - // If the holder object is null, return an error after recording it in the log. - if (holder == null) { - console.error("HiAppEvent holder is null"); - return; - } - // Set the size threshold to 1,000 bytes for obtaining an event package. - holder.setSize(1000); - let eventPkg = null; - // Obtain the event package based on the configured size threshold. If returned event package is null, all event data has been obtained. - while ((eventPkg = holder.takeNext()) != null) { - // Parse the obtained event package and display the result on the Log page. - console.info(`HiAppEvent eventPkg.packageId=${eventPkg.packageId}`); - console.info(`HiAppEvent eventPkg.row=${eventPkg.row}`); - console.info(`HiAppEvent eventPkg.size=${eventPkg.size}`); - // Traverse and parse event string arrays in the obtained event package. - for (const eventInfo of eventPkg.data) { - console.info(`HiAppEvent eventPkg.data=${eventInfo}`); - } - } - } - }); - }) - - Button("3 removeWatcherTest").onClick(()=>{ - // Remove the specified event watcher. - hiAppEvent.removeWatcher({ - name: "watcher1" + hilog.error(0x0000, 'testTag', `HiAppEvent err.code: ${err.code}, err.message: ${err.message}`) }) }) } @@ -121,26 +133,20 @@ The following uses a one-time event watcher as an example to illustrate the deve } } ``` + +3. Touch the run button on the IDE to run the project. Then, touch the **writeTest** button on the application UI to trigger application event logging. -2. Touch the run button on the IDE to run the project. - -3. Touch button 1 on the application UI to start application event logging. If the logging is successful, you'll see the following message in the **Log** window: - - ``` - success to write event: 0 - ``` - -4. On the application UI, touch button 2 to add an event watcher, and touch button 1 for multiple times to perform application event logging. If any callback trigger condition (event count, event data size, and timeout duration) is met, the event watcher will invoke a callback and the event package obtained through the callback will be displayed in the **Log** window. +4. View the information printed in the **Log** window. If logging of the button click event is successful, you will see a message indicating successful event logging as well as the log information specific to processing of the event logging data in the subscription callback. - ``` + ```js + HiAppEvent success to write event + HiAppEvent eventPkg.packageId=0 - HiAppEvent eventPkg.row=2 - HiAppEvent eventPkg.size=308 - HiAppEvent eventPkg.data={"domain_":"test_domain","name_":"test_event","type_":1,"time_":1502096107556,"tz_":"+0000","pid_":4204,"tid_":4223,"int_data":100,"str_data":"strValue"} + HiAppEvent eventPkg.row=1 + HiAppEvent eventPkg.size=124 + HiAppEvent eventPkg.info={"domain_":"button","name_":"click","type_":4,"time_":1670268234523,"tz_":"+0800","pid_":3295,"tid_":3309,"click_time":100} ``` -5. On the application UI, touch button 3 to remove the event watcher. Then, touch button 1 for multiple times to perform application event logging. In such a case, there will be no log information about the callback invoked by the event watcher. - ## Samples The following sample is provided to help you better understand how to develop the application event logging feature: diff --git a/en/application-dev/dfx/hiappevent-overview.md b/en/application-dev/dfx/hiappevent-overview.md deleted file mode 100644 index 2e54f28d8a69623accc2aff1b8dc96f30045f8ed..0000000000000000000000000000000000000000 --- a/en/application-dev/dfx/hiappevent-overview.md +++ /dev/null @@ -1,11 +0,0 @@ -# Overview of Application Event Logging - -The HiAppEvent module provides event logging APIs for applications to log the fault, statistical, security, and user behavior events reported during running. Based on event information, you will be able to analyze the running status of your application. - -You can use this module to develop application event-related functions, including flushing application events to a disk, querying and clearing application events, and customizing application event logging configuration. - -## Basic Concepts - -**Logging** - - A function that logs changes caused by user operations to provide service data for development, product, and O&M analysis. \ No newline at end of file diff --git a/en/application-dev/dfx/hitracechain-guidelines.md b/en/application-dev/dfx/hitracechain-guidelines.md index 06d849872941ab84a894224ef4e3d17ddb8d491d..affd260b0503f3c4f4c4b748d5911d94f7fef9e3 100644 --- a/en/application-dev/dfx/hitracechain-guidelines.md +++ b/en/application-dev/dfx/hitracechain-guidelines.md @@ -1,8 +1,16 @@ # Development of Distributed Call Chain Tracing -## When to Use +## Introduction -HiTraceChain is the module that provides APIs to implement call chain tracing throughout a service process. With HiTraceChain, you can quickly obtain the run log for the call chain of a specified service process and locate faults in inter-device, inter-process, or inter-thread communications. +The hiTraceChain module provides APIs to implement call chain tracing throughout a service process. This can help you quickly obtain the run log for the call chain of a specified service process and locate faults in inter-device, inter-process, or inter-thread communications. + +hiTraceChain is a lightweight implementation of the cloud-based distributed call chain tracing. It allows applications to trace cross-thread, cross-process, and cross-device service calls. The hiTraceChain module generates a unique **chainId** for a service process and passes it to various information (including application events, system time, and logs) specific to the service process. During debugging and fault locating, you can use the unique **chainId** to quickly correlate various information related to the service process. + +## Basic Concepts + +- **chainId** + + Distributed call chain tracing ID, which is a part of **HiTraceId** and is used to identify the service process being traced. ## Available APIs diff --git a/en/application-dev/dfx/hitracechain-overview.md b/en/application-dev/dfx/hitracechain-overview.md deleted file mode 100644 index 64eae517ace23beb6e3ad80bc7b6f0df1ef9b34a..0000000000000000000000000000000000000000 --- a/en/application-dev/dfx/hitracechain-overview.md +++ /dev/null @@ -1,17 +0,0 @@ -# Overview of Distributed Call Chain Tracing - -hiTraceChain is a lightweight implementation of the cloud-based distributed call chain tracing. It allows applications to trace cross-thread, cross-process, and cross-device service calls. - -## Basic Concepts - -- **chainId** - - Distributed call chain tracing ID, which is a part of **HiTraceId** and is used to identify the service process being traced. - -## Working Principles - -The hiTraceChain module generates a unique **chainId** for a service process and passes it to various information (including application events, system time, and logs) specific to the service process. During debugging and fault locating, you can use the unique **chainId** to quickly correlate various information related to the service process. - -## Constraints - -All APIs provided by the hiTraceChain module work in synchronous mode. diff --git a/en/application-dev/dfx/hitracemeter-guidelines.md b/en/application-dev/dfx/hitracemeter-guidelines.md index 1b45886ca4c593bbfff1b1b07d5892ad20ba58ae..2b8b7a562a7e896db40faba9de194777c4d1c170 100644 --- a/en/application-dev/dfx/hitracemeter-guidelines.md +++ b/en/application-dev/dfx/hitracemeter-guidelines.md @@ -1,8 +1,23 @@ # Development of Performance Tracing -## When to Use +## Introduction -HiTraceMeter provides APIs for system performance tracing. You can call the APIs provided by HiTraceMeter module in your own service logic to effectively track service processes and check the system performance. +hiTraceMeter provides APIs for system performance tracing. You can call the APIs provided by the hiTraceMeter module in your own service logic to effectively track service processes and check the system performance. + +## Basic Concepts + +- **hiTraceMeter Tag** + + Tag used for tracing data categorization. It is also known as **hiTraceMeter Category**. Generally, one subsystem maps to a tag. The tag is passed as the **Tag** parameter in performance tracing APIs. When you use the hiTraceMeter CLI tool to collect tracing data, only the tracing data specified by the **Tag** parameter is collected. + +## Working Principles + +- The application calls hiTraceMeter APIs to perform performance tracing. The APIs output the tracing data to the kernel's ftrace data buffer through the kernel's sysfs file interface. +- The hiTraceMeter CLI tool reads the tracing data in the ftrace data buffer and saves the trace data as a text file on the device. + +## Constraints + +Due to the asynchronous I/O feature of JS, the hiTraceMeter module provides only asynchronous APIs. ## Available APIs diff --git a/en/application-dev/dfx/hitracemeter-overview.md b/en/application-dev/dfx/hitracemeter-overview.md deleted file mode 100644 index 649fa7704dd566ab8bc02776de6f62756d7f26a6..0000000000000000000000000000000000000000 --- a/en/application-dev/dfx/hitracemeter-overview.md +++ /dev/null @@ -1,18 +0,0 @@ -# Overview of Performance Tracing - -hiTraceMeter is a tool for you to trace service processes and monitor system performance. Through encapsulating and extending the ftrace inside the kernel, hiTraceMeter supports performance tracing for code execution in the user space. You can use hiTraceMeter APIs to implement performance tracing and use the hiTraceMeter CLI tool to collect traced data. - -## Basic Concepts - -- **hiTraceMeter Tag** - - Tag used for tracing data categorization. It is also known as **hiTraceMeter Category**. Generally, one subsystem maps to a tag. The tag is passed as the **Tag** parameter in performance tracing APIs. When you use the hiTraceMeter CLI tool to collect tracing data, only the tracing data specified by the **Tag** parameter is collected. - -## Working Principles - -- The application calls hiTraceMeter APIs to perform performance tracing. The APIs output the tracing data to the kernel's ftrace data buffer through the kernel's sysfs file interface. -- The hiTraceMeter CLI tool reads the tracing data in the ftrace data buffer and saves the trace data as a text file on the device. - -## Constraints - -Due to the asynchronous I/O feature of JS, the hiTraceMeter module provides only asynchronous APIs. diff --git a/en/application-dev/faqs/faqs-dfx.md b/en/application-dev/faqs/faqs-dfx.md index ec1c8dbfedd5fa3c087c96d54c9c2aab73d75e8a..9fc12a1b1c26e109240702cca50e50b77495bdf5 100644 --- a/en/application-dev/faqs/faqs-dfx.md +++ b/en/application-dev/faqs/faqs-dfx.md @@ -6,7 +6,7 @@ Applicable to: OpenHarmony SDK 3.2.5.5 1. Locate the crash-related code based on the service log. -2. View the error information in the crash file. The crash file is located at **/data/log/faultlog/faultlogger/**. +2. View the error information in the crash file, which is located at **/data/log/faultlog/faultlogger/**. ## Why cannot access controls in the UiTest test framework? diff --git a/en/application-dev/faqs/faqs-language.md b/en/application-dev/faqs/faqs-language.md index 4c0a6cba384f4e94832a6a4a933aebeee4b2f364..db7e95d5ede5c3bead52e16bceb16e90c6188b79 100644 --- a/en/application-dev/faqs/faqs-language.md +++ b/en/application-dev/faqs/faqs-language.md @@ -51,9 +51,9 @@ build() { Applicable to: OpenHarmony SDK 3.2.2.5, stage model of API version 9 -1. Obtain data in Uint8Array format by calling the **RawFile** API of **resourceManager**. +1. Obtain Uint8Array data by calling the **RawFile** API of **resourceManager**. -2. Convert data in Uint8Array format to the string type by calling the **String.fromCharCode** API. +2. Convert the Uint8Array data to strings by calling the **String.fromCharCode** API. Reference: [Resource Manager](../reference/apis/js-apis-resource-manager.md) diff --git a/en/application-dev/media/image.md b/en/application-dev/media/image.md index 048716dfdcd76d0e35f4ed3ad70a5eeb266ac8cc..fb4e648b56839ef76cb0e5277443605734d7ab6f 100644 --- a/en/application-dev/media/image.md +++ b/en/application-dev/media/image.md @@ -19,112 +19,121 @@ const color = new ArrayBuffer(96); // Create a buffer to store image pixel data. let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } } // Image pixel data. // Create a PixelMap object. -const color = new ArrayBuffer(96); -let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } } image.createPixelMap(color, opts, (err, pixelmap) => { console.log('Succeeded in creating pixelmap.'); -}) - -// Read pixels. -const area = { - pixels: new ArrayBuffer(8), - offset: 0, - stride: 8, - region: { size: { height: 1, width: 2 }, x: 0, y: 0 } -} -pixelmap.readPixels(area,() => { - var bufferArr = new Uint8Array(area.pixels); - var res = true; - for (var i = 0; i < bufferArr.length; i++) { - console.info(' buffer ' + bufferArr[i]); - if(res) { - if(bufferArr[i] == 0) { - res = false; - console.log('readPixels end.'); - break; - } - } + // Failed to create the PixelMap object. + if (err) { + console.info('create pixelmap failed, err' + err); + return } -}) - -// Store pixels. -const readBuffer = new ArrayBuffer(96); -pixelmap.readPixelsToBuffer(readBuffer,() => { - var bufferArr = new Uint8Array(readBuffer); - var res = true; - for (var i = 0; i < bufferArr.length; i++) { - if(res) { - if (bufferArr[i] !== 0) { - res = false; - console.log('readPixelsToBuffer end.'); - break; - } - } + + // Read pixels. + const area = { + pixels: new ArrayBuffer(8), + offset: 0, + stride: 8, + region: { size: { height: 1, width: 2 }, x: 0, y: 0 } } -}) - -// Write pixels. -pixelmap.writePixels(area,() => { - const readArea = { pixels: new ArrayBuffer(20), offset: 0, stride: 8, region: { size: { height: 1, width: 2 }, x: 0, y: 0 }} - pixelmap.readPixels(readArea,() => { - var readArr = new Uint8Array(readArea.pixels); - var res = true; - for (var i = 0; i < readArr.length; i++) { + pixelmap.readPixels(area,() => { + let bufferArr = new Uint8Array(area.pixels); + let res = true; + for (let i = 0; i < bufferArr.length; i++) { + console.info(' buffer ' + bufferArr[i]); if(res) { - if (readArr[i] !== 0) { + if(bufferArr[i] == 0) { res = false; - console.log('readPixels end.please check buffer'); + console.log('readPixels end.'); break; } } } }) -}) - -// Write pixels to the buffer. -pixelmap.writeBufferToPixels(writeColor).then(() => { + + // Store pixels. const readBuffer = new ArrayBuffer(96); - pixelmap.readPixelsToBuffer(readBuffer).then (() => { - var bufferArr = new Uint8Array(readBuffer); - var res = true; - for (var i = 0; i < bufferArr.length; i++) { + pixelmap.readPixelsToBuffer(readBuffer,() => { + let bufferArr = new Uint8Array(readBuffer); + let res = true; + for (let i = 0; i < bufferArr.length; i++) { if(res) { - if (bufferArr[i] !== i) { + if (bufferArr[i] !== 0) { res = false; - console.log('readPixels end.please check buffer'); + console.log('readPixelsToBuffer end.'); break; } } } }) -}) + + // Write pixels. + pixelmap.writePixels(area,() => { + const readArea = { pixels: new ArrayBuffer(20), offset: 0, stride: 8, region: { size: { height: 1, width: 2 }, x: 0, y: 0 }} + pixelmap.readPixels(readArea,() => { + let readArr = new Uint8Array(readArea.pixels); + let res = true; + for (let i = 0; i < readArr.length; i++) { + if(res) { + if (readArr[i] !== 0) { + res = false; + console.log('readPixels end.please check buffer'); + break; + } + } + } + }) + }) -// Obtain image information. -pixelmap.getImageInfo((error, imageInfo) => { - if (imageInfo !== null) { - console.log('Succeeded in getting imageInfo'); - } -}) + const writeColor = new ArrayBuffer(96); // Pixel data of the image. + // Write pixels to the buffer. + pixelmap.writeBufferToPixels(writeColor).then(() => { + const readBuffer = new ArrayBuffer(96); + pixelmap.readPixelsToBuffer(readBuffer).then (() => { + let bufferArr = new Uint8Array(readBuffer); + let res = true; + for (let i = 0; i < bufferArr.length; i++) { + if(res) { + if (bufferArr[i] !== i) { + res = false; + console.log('readPixels end.please check buffer'); + break; + } + } + } + }) + }) -// Release the PixelMap object. -pixelmap.release(()=>{ - console.log('Succeeded in releasing pixelmap'); + // Obtain image information. + pixelmap.getImageInfo((err, imageInfo) => { + // Failed to obtain the image information. + if (err || imageInfo == null) { + console.info('getImageInfo failed, err' + err); + return + } + if (imageInfo !== null) { + console.log('Succeeded in getting imageInfo'); + } + }) + + // Release the PixelMap object. + pixelmap.release(()=>{ + console.log('Succeeded in releasing pixelmap'); + }) }) // Create an image source (uri). let path = '/data/local/tmp/test.jpg'; -const imageSourceApi = image.createImageSource(path); +const imageSourceApi1 = image.createImageSource(path); // Create an image source (fd). let fd = 29; -const imageSourceApi = image.createImageSource(fd); +const imageSourceApi2 = image.createImageSource(fd); // Create an image source (data). const data = new ArrayBuffer(96); -const imageSourceApi = image.createImageSource(data); +const imageSourceApi3 = image.createImageSource(data); // Release the image source. -imageSourceApi.release(() => { +imageSourceApi3.release(() => { console.log('Succeeded in releasing imagesource'); }) @@ -133,6 +142,10 @@ const imagePackerApi = image.createImagePacker(); const imageSourceApi = image.createImageSource(0); let packOpts = { format:"image/jpeg", quality:98 }; imagePackerApi.packing(imageSourceApi, packOpts, (err, data) => { + if (err) { + console.info('packing from imagePackerApi failed, err' + err); + return + } console.log('Succeeded in packing'); }) @@ -161,36 +174,33 @@ let decodingOptions = { // Create a pixel map in callback mode. imageSourceApi.createPixelMap(decodingOptions, (err, pixelmap) => { + // Failed to create the PixelMap object. + if (err) { + console.info('create pixelmap failed, err' + err); + return + } console.log('Succeeded in creating pixelmap.'); }) // Create a pixel map in promise mode. imageSourceApi.createPixelMap().then(pixelmap => { console.log('Succeeded in creating pixelmap.'); -}) - -// Capture error information when an exception occurs during function invoking. -catch(error => { - console.log('Failed in creating pixelmap.' + error); -}) -// Obtain the number of bytes in each line of pixels. -var num = pixelmap.getBytesNumberPerRow(); + // Obtain the number of bytes in each line of pixels. + let num = pixelmap.getBytesNumberPerRow(); -// Obtain the total number of pixel bytes. -var pixelSize = pixelmap.getPixelBytesNumber(); + // Obtain the total number of pixel bytes. + let pixelSize = pixelmap.getPixelBytesNumber(); -// Obtain the pixel map information. -pixelmap.getImageInfo().then( imageInfo => {}); + // Obtain the pixel map information. + pixelmap.getImageInfo().then( imageInfo => {}); -// Release the PixelMap object. -pixelmap.release(()=>{ - console.log('Succeeded in releasing pixelmap'); -}) - -// Capture release failure information. -catch(error => { - console.log('Failed in releasing pixelmap.' + error); + // Release the PixelMap object. + pixelmap.release(()=>{ + console.log('Succeeded in releasing pixelmap'); + }) +}).catch(error => { + console.log('Failed in creating pixelmap.' + error); }) ``` @@ -216,7 +226,7 @@ if (imagePackerApi == null) { } // Set encoding parameters if the image packer is successfully created. -let packOpts = { format:["image/jpeg"], // The supported encoding format is jpg. +let packOpts = { format:"image/jpeg", // The supported encoding format is jpg. quality:98 } // Image quality, which ranges from 0 to 100. // Encode the image. @@ -233,8 +243,9 @@ imageSourceApi.getImageInfo((err, imageInfo) => { console.log('Succeeded in getting imageInfo'); }) +const array = new ArrayBuffer(100); // Incremental data. // Update incremental data. -imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error, data)=> {}) +imageSourceApi.updateData(array, false, 0, 10,(error, data)=> {}) ``` @@ -246,10 +257,15 @@ Example scenario: The camera functions as the client to transmit image data to t public async init(surfaceId: any) { // (Server code) Create an ImageReceiver object. - var receiver = image.createImageReceiver(8 * 1024, 8, image.ImageFormat.JPEG, 1); + let receiver = image.createImageReceiver(8 * 1024, 8, image.ImageFormat.JPEG, 1); // Obtain the surface ID. receiver.getReceivingSurfaceId((err, surfaceId) => { + // Failed to obtain the surface ID. + if (err) { + console.info('getReceivingSurfaceId failed, err' + err); + return + } console.info("receiver getReceivingSurfaceId success"); }); // Register a surface listener, which is triggered after the buffer of the surface is ready. diff --git a/en/application-dev/quick-start/arkts-basic-ui-description.md b/en/application-dev/quick-start/arkts-basic-ui-description.md index d20efe12859e944d9d78fb71688dc4aada729228..4ef7f97c280d7fcac0771a304359e58c26183d34 100644 --- a/en/application-dev/quick-start/arkts-basic-ui-description.md +++ b/en/application-dev/quick-start/arkts-basic-ui-description.md @@ -15,7 +15,7 @@ In ArkTS, you define a custom component by using decorators **@Component** and * } ``` -- **build** function: a function that complies with the **Builder** API definition and is used to define the declarative UI description of components. A **build** function must be defined for custom components, and custom constructors are prohibited for custom components. +- **build** function: A custom component must implement the **build** function and must implement no constructor. The **build** function meets the definition of the **Builder** API and is used to define the declarative UI description of components. ```ts interface Builder { @@ -49,9 +49,9 @@ Column() { } ``` -### Structs with Mandatory Parameters +### Structs with Parameters -A struct with mandatory parameters is a component whose API definition expects parameters enclosed in the parentheses. You can use constants to assign values to the parameters. +A struct with parameters is a component whose API definition expects parameters enclosed in the parentheses. You can use constants to assign values to the parameters. Sample code: @@ -61,7 +61,7 @@ Sample code: Image('https://xyz/test.jpg') ``` -- Set the mandatory parameter **content** of the **\** component as follows: +- Set the optional parameter **content** of the **\** component as follows: ```ts Text('test') @@ -83,35 +83,35 @@ Component attributes are configured using an attribute method, which follows the ```ts Text('test') - .fontSize(12) + .fontSize(12) ``` - Example of configuring multiple attributes at the same time by using the "**.**" operator to implement chain call: ```ts Image('test.jpg') - .alt('error.jpg') - .width(100) - .height(100) + .alt('error.jpg') + .width(100) + .height(100) ``` - Example of passing variables or expressions in addition to constants: ```ts Text('hello') - .fontSize(this.size) + .fontSize(this.size) Image('test.jpg') - .width(this.count % 2 === 0 ? 100 : 200) - .height(this.offset + 100) + .width(this.count % 2 === 0 ? 100 : 200) + .height(this.offset + 100) ``` - For attributes of built-in components, ArkUI also provides some predefined [enumeration types](../reference/arkui-ts/ts-appendix-enums.md), which you can pass as parameters to methods if they meet the parameter type requirements. For example, you can configure the font color and weight attributes of the **\** component as follows: ```ts Text('hello') - .fontSize(20) - .fontColor(Color.Red) - .fontWeight(FontWeight.Bold) + .fontSize(20) + .fontColor(Color.Red) + .fontWeight(FontWeight.Bold) ``` ### Event Configuration @@ -123,7 +123,7 @@ Events supported by components are configured using event methods, which each fo ```ts Button('add counter') .onClick(() => { - this.counter += 2 + this.counter += 2; }) ``` @@ -132,7 +132,7 @@ Events supported by components are configured using event methods, which each fo ```ts Button('add counter') .onClick(function () { - this.counter += 2 + this.counter += 2; }.bind(this)) ``` @@ -140,13 +140,13 @@ Events supported by components are configured using event methods, which each fo ```ts myClickHandler(): void { - this.counter += 2 + this.counter += 2; } ... - + Button('add counter') - .onClick(this.myClickHandler) + .onClick(this.myClickHandler.bind(this)) ``` ### Child Component Configuration @@ -158,11 +158,11 @@ For a component that supports child components, for example, a container compone ```ts Column() { Text('Hello') - .fontSize(100) + .fontSize(100) Divider() Text(this.myText) - .fontSize(100) - .fontColor(Color.Red) + .fontSize(100) + .fontColor(Color.Red) } ``` @@ -176,10 +176,10 @@ For a component that supports child components, for example, a container compone .height(100) Button('click +1') .onClick(() => { - console.info('+1 clicked!') + console.info('+1 clicked!'); }) } - + Divider() Row() { Image('test2.jpg') @@ -187,10 +187,10 @@ For a component that supports child components, for example, a container compone .height(100) Button('click +2') .onClick(() => { - console.info('+2 clicked!') + console.info('+2 clicked!'); }) } - + Divider() Row() { Image('test3.jpg') @@ -198,7 +198,7 @@ For a component that supports child components, for example, a container compone .height(100) Button('click +3') .onClick(() => { - console.info('+3 clicked!') + console.info('+3 clicked!'); }) } } diff --git a/en/application-dev/quick-start/arkts-rendering-control.md b/en/application-dev/quick-start/arkts-rendering-control.md index dff2cda50c02afabc15d0f5c8bb576218cab316e..d0ff5a8c183d8efba03b12f7343f001a3ba31fe5 100644 --- a/en/application-dev/quick-start/arkts-rendering-control.md +++ b/en/application-dev/quick-start/arkts-rendering-control.md @@ -34,7 +34,7 @@ Column() { You can use **ForEach** to obtain data from arrays and create components for each data item. -``` +```ts ForEach( arr: any[], itemGenerator: (item: any, index?: number) => void, @@ -275,7 +275,7 @@ struct MyComponent { > > ```ts > LazyForEach(dataSource, -> item => Text(`${item.i}. item.data.label`)), +> item => Text(`${item.i}. item.data.label`), > item => item.data.id.toString()) > ``` diff --git a/en/application-dev/quick-start/arkts-state-mgmt-concepts.md b/en/application-dev/quick-start/arkts-state-mgmt-concepts.md index d3f1002dca22fe4522134d662d4c640742d86952..2eae06eca22030673ef35bcf756279444fcd9c60 100644 --- a/en/application-dev/quick-start/arkts-state-mgmt-concepts.md +++ b/en/application-dev/quick-start/arkts-state-mgmt-concepts.md @@ -15,8 +15,8 @@ In the multi-dimensional state management mechanism for ArkUI, UI-related data c | @Link | Primitive data types, classes, and arrays | This decorator is used to establish two-way data binding between the parent and child components. The internal state data of the parent component is used as the data source. Any changes made to one component will be reflected to the other.| | @Observed | Class | This decorator is used to indicate that the data changes in the class will be managed by the UI page. | | @ObjectLink | Objects of **@Observed** decorated classes| When the decorated state variable is modified, the parent and sibling components that have the state variable will be notified for UI re-rendering.| -| @Consume | Primitive data types, classes, and arrays | When the **@Consume** decorated variable detects the update of the **@Provide** decorated variable, the re-rendering of the current custom component is triggered.| | @Provide | Primitive data types, classes, and arrays | As the data provider, **@Provide** can update the data of child nodes and trigger page re-rendering.| +| @Consume | Primitive data types, classes, and arrays | When the **@Consume** decorated variable detects the update of the **@Provide** decorated variable, the re-rendering of the current custom component is triggered.| ## State Management with Application-level Variables @@ -25,5 +25,8 @@ In the multi-dimensional state management mechanism for ArkUI, UI-related data c - **@StorageLink**: works in a way similar to that of **@Consume**. The difference is that the target object is obtained from the **AppStorage** based on the given name. **@StorageLink** establishes two-way binding between the decorated UI component and **AppStorage** to synchronize data. - **@StorageProp**: synchronizes UI component attributes with the **AppStorage** unidirectionally. That is, the value change in the **AppStorage** will trigger an update of the corresponding UI component, but the change of the UI component will not cause an update of the attribute value in the **AppStorage**. - Service logic implementation API: adds, reads, modifies, or deletes the state data of applications. The changes made by this API will be synchronized to the UI component for UI update. +- **LocalStorage**: provides ability-specific storage. +- **@LocalStorageLink**: establishes two-way data binding between a component and the **LocalStorage**. Specifically, this is achieved by decorating the component's state variable with **@LocalStorageLink(*key*)**. Wherein, **key** is the attribute key value in the **LocalStorage**. +- **@LocalStorageProp**: establishes one-way data binding between a component and the **LocalStorage**. Specifically, this is achieved by decorating the component's state variable with **@LocalStorageProp(*key*)**. Wherein, **key** is the attribute key value in the **LocalStorage**. - **PersistentStorage**: provides a set of static methods for managing persistent data of applications. Persistent data with specific tags can be linked to the **AppStorage**, and then the persistent data can be accessed through the **AppStorage** APIs. Alternatively, the **@StorageLink** decorator can be used to access the variable that matches the specific key. - **Environment**: provides the **AppStorage** with an array of environment state attributes that are required by the application and describe the device environment where the application runs. It is a singleton object created by the framework when the application is started. diff --git a/en/application-dev/quick-start/arkts-state-mgmt-page-level.md b/en/application-dev/quick-start/arkts-state-mgmt-page-level.md index accda367a04ab0c77bdce7557bf47cc73f48c8a3..504665688a8eada31cd51531c7cd8c485d795892 100644 --- a/en/application-dev/quick-start/arkts-state-mgmt-page-level.md +++ b/en/application-dev/quick-start/arkts-state-mgmt-page-level.md @@ -82,14 +82,18 @@ struct MyComponent { ## @Prop -**@Prop** and **@State** have the same semantics but different initialization modes. Variables decorated by **@Prop** must be initialized using the **@State** decorated variable provided by their parent components. The **@Prop** decorated variable can be modified in the component, but the modification is not updated to the parent component; that is, **@Prop** uses one-way data binding. +**@Prop** and **@State** have the same semantics but different initialization modes. A **@Prop** decorated variable in a component must be initialized using the **@State** decorated variable in its parent component. The **@Prop** decorated variable can be modified in the component, but the modification is not updated to the parent component; the modification to the **@State** decorated variable is synchronized to the **@Prop** decorated variable. That is, **@Prop** establishes one-way data binding. The **@Prop** decorated state variable has the following features: - Support for simple types: The number, string, and boolean types are supported. - Private: Data is accessed only within the component. - Support for multiple instances: A component can have multiple attributes decorated by **@Prop**. -- Support for initialization with a value passed to the @Prop decorated variable: When a new instance of the component is created, all **@Prop** decorated variables must be initialized. Initialization inside the component is not supported. +- Support for initialization with a value passed to the @Prop decorated variable: When a new instance of the component is created, all **@Prop** variables must be initialized. Initialization inside the component is not supported. + +> **NOTE** +> +> A **@Prop** decorated variable cannot be initialized inside the component. **Example** @@ -152,13 +156,13 @@ Two-way binding can be established between the **@Link** decorated variable and - Support for multiple types: The **@Link** decorated variables support the data types the same as the **@State** decorated variables; that is, the value can be of the following types: class, number, string, boolean, or arrays of these types. - Private: Data is accessed only within the component. -- Single data source: The variable of the parent component used for initializing the **@Link** decorated variable must be a **@State** decorated variable. +- Single data source: The variable used to initialize the **@Link** decorated variable in a component must be a state variable defined in the parent component. - **Two-way binding**: When a child component changes the **@Link** decorated variable, the **@State** decorated variable of its parent component is also changed. - Support for initialization with the variable reference passed to the @Link decorated variable: When creating an instance of the component, you must use the naming parameter to initialize all **@Link** decorated variables. **@Link** decorated variables can be initialized by using the reference of the **@State** or **@Link** decorated variable. Wherein, the **@State** decorated variables can be referenced using the **'$'** operator. > **NOTE** > -> **@Link** decorated variables cannot be initialized within the component. +> A **@Link** decorated variable cannot be initialized inside the component. **Simple Type Example** @@ -391,13 +395,13 @@ struct ViewB { ``` -## @Consume and @Provide +## @Provide and @Consume As the data provider, **@Provide** can update the data of child nodes and trigger page rendering. After **@Consume** detects that the **@Provide** decorated variable is updated, it will initiate re-rendering of the current custom component. > **NOTE** > -> To avoid infinite loops caused by circular reference, exercise caution when using **@Provide** and **@Consume**. +> When using **@Provide** and **@Consume**, avoid circular reference that may lead to infinite loops. ### @Provide diff --git a/en/application-dev/quick-start/figures/alarm.png b/en/application-dev/quick-start/figures/alarm.png new file mode 100644 index 0000000000000000000000000000000000000000..d8710f4cb2d41a8f9dde0be779909867aa237536 Binary files /dev/null and b/en/application-dev/quick-start/figures/alarm.png differ diff --git a/en/application-dev/quick-start/figures/alarmHand.png b/en/application-dev/quick-start/figures/alarmHand.png new file mode 100644 index 0000000000000000000000000000000000000000..020ae09b94904b6b89e4503b7139dcc2843daeb2 Binary files /dev/null and b/en/application-dev/quick-start/figures/alarmHand.png differ diff --git a/en/application-dev/quick-start/figures/arkts-get-started.png b/en/application-dev/quick-start/figures/arkts-get-started.png index 8858c1d09bc4624ad9ace341b8d4aff2f2c4f2fa..0a83234882aecf0c1cfe390d1b9d49bccdbd0362 100644 Binary files a/en/application-dev/quick-start/figures/arkts-get-started.png and b/en/application-dev/quick-start/figures/arkts-get-started.png differ diff --git a/en/application-dev/quick-start/full-sdk-switch-guide.md b/en/application-dev/quick-start/full-sdk-switch-guide.md index 818249975bfd00cd582414549237f955fec1fcb8..f9116ce7ead9c4dbcf15f9d7e6b88a1d8b274d6d 100644 --- a/en/application-dev/quick-start/full-sdk-switch-guide.md +++ b/en/application-dev/quick-start/full-sdk-switch-guide.md @@ -4,7 +4,7 @@ Both the public SDK and full SDK are toolkits for application development.
T The full SDK is intended for original equipment manufacturers (OEMs) and provided separately. It contains system APIs. -The SDK of API version 8 provided in DevEco Studio is a public SDK. If your project depends on any system API, such as the **animator** component, **xcomponent** component, or APIs in **@ohos.application.abilityManager.d.ts**, **@ohos.application.formInfo.d.ts**, or **@ohos.bluetooth.d.ts**, switch to the full SDK by performing the following steps. +The SDK of API version 8 provided in DevEco Studio is a public SDK. If your project depends on any system API, such as the **animator** component, **XComponent**, or APIs in **@ohos.application.abilityManager.d.ts**, **@ohos.application.formInfo.d.ts**, or **@ohos.bluetooth.d.ts**, switch to the full SDK by performing the following steps. > **NOTE** > @@ -16,7 +16,8 @@ Manually download the system-specific full SDK package from the mirror. For deta ## Checking the Local SDK Location -In this example, an ArkTS project is used. For a JS project, replace **ets** with **js**. +In this example, an eTS project is used. For a JS project, replace **ets** with **js**. + In DevEco Studio, choose **Tools** > **OpenHarmony SDK Manager** to check the location of the local SDK. @@ -35,11 +36,15 @@ In DevEco Studio, choose **Tools** > **OpenHarmony SDK Manager** to check the lo b. Verify that the SDK contains system APIs (such as APIs defined in **@ohos.application.abilityManager.d.ts**, **@ohos.application.formInfo.d.ts**, and **@ohos.bluetooth.d.ts**). - Note: The criteria for identifying system APIs are subject to the released API documentation. + Note: The criteria for identifying system APIs are subject to the official API documentation. + + 2. Replace the SDK. The following uses public-SDK-3.x.x.x for Windows as an example. - a. Decompress the downloaded full SDK file: `ets-windows-3.x.x.x-Release.zip` + + + a. Decompress the downloaded full SDK file: **ets-windows-3.x.x.x-Release.zip** ![image-20220613165018184](figures/en-us_image_0000001655129264.png) @@ -51,13 +56,13 @@ In DevEco Studio, choose **Tools** > **OpenHarmony SDK Manager** to check the lo ![image-20220613161352157](figures/en-us_image_0000001655129041.png) - Note: The name of the backup version directory must be different from the value of **version** field in the **oh-uni-package.json** file. In the example below, the name of the backup version directory is **3.x.x.x_backup**. + Note: The name of the backup version directory must be different from the value of the **version** field in the **oh-uni-package.json** file. In the example below, the name of the backup version directory is **3.1.6.6_backup**. ![image-20220613165018184](figures/en-us_image_0000001655129398.png) - The configuration in the **oh-uni-package.json** file is as follows, where the value of `apiVersion` is subject to the API version of the SDK, and the value of `version` is subject to the version number in the SDK file. + The configuration in the **oh-uni-package.json** file is as follows, where the value of **apiVersion** is subject to the API version of the SDK, and the value of **version** is subject to the version number in the SDK file. - ``` + ```json { "apiVersion": "X", "displayName": "Ets", @@ -71,24 +76,42 @@ In DevEco Studio, choose **Tools** > **OpenHarmony SDK Manager** to check the lo ``` - Delete all files in the original SDK (3.x.x.x) directory. Failure to do so may result in some files being unable to be overwritten. + **Delete all files in the original SDK (3.x.x.x) directory.** Failure to do so may result in some files being unable to be overwritten. Copy the full SDK to the location of the local SDK. - Copy all files in the **ets** directory in the full SDK to the **ets\*3.x.x.x*** directory in the location of the local SDK. + Copy all files in the **ets** directory in the full SDK to the **ets\3.x.x.x** directory in the location of the local SDK. Change the value of **version** in the **oh-uni-package.json** file to the current SDK version number. - In the ***3.x.x.x*\build-tools\ets-loader** directory, open the **cmd/powerShell** window and run the `npm install` command to download the **node_modules** dependency package. + In the ***3.x.x.x*\build-tools\ets-loader** directory, open the **cmd/powerShell** window and run the **npm install** command to download the **node_modules** dependency package. ![image-20220613171111405](figures/en-us_image_0000001655129333.png) c. Check for system APIs. - + ![image-20220613213038104](figures/en-us_image_0000001655129372.png) + +## Appendix: macOS Security Alarm Handling + +After the SDK is switched to the full SDK in DevEco Studio on macOS, an alarm is generated when the Previewer is opened. + +![alarm](figures/alarm.png) + +To clear the alarm, perform the following steps: + +1. Start the Terminal application. + +2. In Terminal, run **sudo spctl -- master - disable**. + +3. In **System Preferences**, choose **Security & Privacy**, click the **General** tab and select **Anywhere** under **Allow apps downloaded from**. + +![alarmHand](figures/alarmHand.png) + +Now, applications downloaded from third-party sources will not be blocked, meaning that you can open the Previewer. For security purposes, change the **Allow apps downloaded from** settings back to the original option when the Previewer is not in use. diff --git a/en/application-dev/quick-start/resource-categories-and-access.md b/en/application-dev/quick-start/resource-categories-and-access.md index d1d342fe74eaed80516a7ca554cbe84f84ad927c..56e8209a5c19e353a21b80ff8b34dd51885db310 100644 --- a/en/application-dev/quick-start/resource-categories-and-access.md +++ b/en/application-dev/quick-start/resource-categories-and-access.md @@ -83,6 +83,7 @@ You can create resource group subdirectories (including element, media, and prof | ------- | ---------------------------------------- | ---------------------------------------- | | element | Indicates element resources. Each type of data is represented by a JSON file. The options are as follows:
- **boolean**: boolean data
- **color**: color data
- **float**: floating-point data
- **intarray**: array of integers
- **integer**: integer data
- **pattern**: pattern data
- **plural**: plural form data
- **strarray**: array of strings
- **string**: string data| It is recommended that files in the **element** subdirectory be named the same as the following files, each of which can contain only data of the same type:
- boolean.json
- color.json
- float.json
- intarray.json
- integer.json
- pattern.json
- plural.json
- strarray.json
- string.json | | media | Indicates media resources, including non-text files such as images, audios, and videos. | The file name can be customized, for example, **icon.png**. | +| profile | Indicates a user-defined configuration file. You can obtain the file content by using the [getProfileByAbility](../reference/apis/js-apis-bundleManager.md#bundlemanagergetprofilebyability) API. | The file name can be customized, for example, **test_profile.json**. | | rawfile | Indicates other types of files, which are stored in their raw formats after the application is built as an HAP file. They will not be integrated into the **resources.index** file.| The file name can be customized. | **Media Resource Types** @@ -230,27 +231,27 @@ When referencing resources in the **rawfile** subdirectory, use the **"$rawfile( > > The return value of **$r** is a **Resource** object. You can obtain the corresponding string by using the [getStringValue](../reference/apis/js-apis-resource-manager.md) API. -In the **.ets** file, you can use the resources defined in the **resources** directory. +In the **.ets** file, you can use the resources defined in the **resources** directory. The following is a resource usage example based on the resource file examples in [Resource Group Sub-directories](#resource-group-subdirectories): ```ts Text($r('app.string.string_hello')) - .fontColor($r('app.color.color_hello')) - .fontSize($r('app.float.font_hello')) -} + .fontColor($r('app.color.color_hello')) + .fontSize($r('app.float.font_hello')) Text($r('app.string.string_world')) - .fontColor($r('app.color.color_world')) - .fontSize($r('app.float.font_world')) -} - -Text($r('app.string.message_arrive', "five of the clock")) // Reference string resources. The second parameter of $r is used to replace %s. - .fontColor($r('app.color.color_hello')) - .fontSize($r('app.float.font_hello')) -} - -Text($r('app.plural.eat_apple', 5, 5)) // Reference plural resources. The first parameter indicates the plural resource, the second parameter indicates the number of plural resources, and the third parameter indicates the substitute of %d. - .fontColor($r('app.color.color_world')) - .fontSize($r('app.float.font_world')) + .fontColor($r('app.color.color_world')) + .fontSize($r('app.float.font_world')) + +// Reference string resources. The second parameter of $r is used to replace %s, and value is "We will arrive at five'o clock". +Text($r('app.string.message_arrive', "five'o clock")) + .fontColor($r('app.color.color_hello')) + .fontSize($r('app.float.font_hello')) + +// Reference plural resources. The first parameter indicates the plural resource, the second parameter indicates the number of plural resources, and the third parameter indicates the substitute of %d. +// The value is "5 apple" in singular form and "5 apples" in plural form. +Text($r('app.plural.eat_apple', 5, 5)) + .fontColor($r('app.color.color_world')) + .fontSize($r('app.float.font_world')) } Image($r('app.media.my_background_image')) // Reference media resources. @@ -274,14 +275,20 @@ To reference a system resource, use the **"$r('sys.type.resource_id')"** format. ```ts Text('Hello') - .fontColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize($r('sys.float.ohos_id_text_size_headline1')) - .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) - .backgroundColor($r('sys.color.ohos_id_color_palette_aux1')) + .fontColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize($r('sys.float.ohos_id_text_size_headline1')) + .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) + .backgroundColor($r('sys.color.ohos_id_color_palette_aux1')) + Image($r('sys.media.ohos_app_icon')) - .border({color: $r('sys.color.ohos_id_color_palette_aux1'), radius: $r('sys.float.ohos_id_corner_radius_button'), width: 2}) - .margin({top: $r('sys.float.ohos_id_elements_margin_horizontal_m'), bottom: $r('sys.float.ohos_id_elements_margin_horizontal_l')}) - .height(200) - .width(300) + .border({ + color: $r('sys.color.ohos_id_color_palette_aux1'), + radius: $r('sys.float.ohos_id_corner_radius_button'), width: 2 + }) + .margin({ + top: $r('sys.float.ohos_id_elements_margin_horizontal_m'), + bottom: $r('sys.float.ohos_id_elements_margin_horizontal_l') + }) + .height(200) + .width(300) ``` - diff --git a/en/application-dev/reference/apis/Readme-EN.md b/en/application-dev/reference/apis/Readme-EN.md index 76d12ed38f81bdf496fd228f9cbea11eb8422510..13110f9784e44ab0d406917924394ef5b84fc470 100644 --- a/en/application-dev/reference/apis/Readme-EN.md +++ b/en/application-dev/reference/apis/Readme-EN.md @@ -16,7 +16,7 @@ - [@ohos.app.ability.StartOptions](js-apis-app-ability-startOptions.md) - [@ohos.app.ability.UIAbility](js-apis-app-ability-uiAbility.md) - [@ohos.app.form.FormExtensionAbility](js-apis-app-form-formExtensionAbility.md) - - [@ohos.application.DataShareExtensionAbility](js-apis-application-DataShareExtensionAbility.md) + - [@ohos.application.DataShareExtensionAbility](js-apis-application-dataShareExtensionAbility.md) - [@ohos.application.StaticSubscriberExtensionAbility](js-apis-application-staticSubscriberExtensionAbility.md) - Stage Model (To Be Deprecated Soon) - [@ohos.application.Ability](js-apis-application-ability.md) @@ -212,7 +212,7 @@ - [@ohos.data.fileAccess](js-apis-fileAccess.md) - [@ohos.fileExtensionInfo](js-apis-fileExtensionInfo.md) - [@ohos.fileio](js-apis-fileio.md) - - [@ohos.filemanagement.userFileManager](js-apis-userfilemanager.md) + - [@ohos.filemanagement.userFileManager](js-apis-userFileManager.md) - [@ohos.multimedia.medialibrary](js-apis-medialibrary.md) - [@ohos.securityLabel](js-apis-securityLabel.md) - [@ohos.statfs](js-apis-statfs.md) diff --git a/en/application-dev/reference/apis/js-apis-animator.md b/en/application-dev/reference/apis/js-apis-animator.md index 4086ca77e506b148c95fdf81e942f44642a5ffca..da7ec7d145779eb5044427fdee758a34f6b33fdc 100644 --- a/en/application-dev/reference/apis/js-apis-animator.md +++ b/en/application-dev/reference/apis/js-apis-animator.md @@ -40,10 +40,10 @@ Creates an **Animator** object. easing: 'friction', delay: 0, fill: 'forwards', - direction: "normal", + direction: 'normal', iterations: 3, begin: 200.0, - end: 400.0, + end: 400.0 }; animator.create(options); ``` @@ -83,10 +83,10 @@ let options = { easing: 'friction', delay: 0, fill: 'forwards', - direction: "normal", + direction: 'normal', iterations: 3, begin: 200.0, - end: 400.0, + end: 400.0 }; try { animator.reset(options); @@ -283,7 +283,7 @@ export default { easing: 'friction', delay: 0, fill: 'forwards', - direction: "normal", + direction: 'normal', iterations: 2, begin: 200.0, end: 400.0 @@ -516,7 +516,7 @@ let options = { easing: 'friction', delay: 0, fill: 'forwards', - direction: "normal", + direction: 'normal', iterations: 3, begin: 200.0, end: 400.0, diff --git a/en/application-dev/reference/apis/js-apis-application-DataShareExtensionAbility.md b/en/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md similarity index 91% rename from en/application-dev/reference/apis/js-apis-application-DataShareExtensionAbility.md rename to en/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md index 7798cdee3d2f71f54e7cc6937816cbb4c253a833..c6192ce1235b2c75607e92788b68fd635dddaffd 100644 --- a/en/application-dev/reference/apis/js-apis-application-DataShareExtensionAbility.md +++ b/en/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md @@ -1,6 +1,6 @@ -# Data Share Extension Ability +# @ohos.application.DataShareExtensionAbility -The **DataShareExtensionAbility** module provides Extension abilities for data share services. +The **DataShareExtensionAbility** module provides extension abilities for data share services. >**NOTE** > @@ -23,7 +23,7 @@ import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbili | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| context | [ExtensionContext](js-apis-extension-context.md) | Yes| No|Context of the DataShare Extension ability.| +| context | [ExtensionContext](js-apis-inner-application-extensionContext.md) | Yes| No|Context of the DataShare Extension ability.| ## onCreate @@ -37,7 +37,7 @@ Called by the server to initialize service logic when the DataShare client conne | Name| Type| Mandatory| Description| | ----- | ------ | ------ | ------ | -| want | [Want](js-apis-application-Want.md#want) | Yes | **Want** information, including the ability name and bundle name.| +| want | [Want](js-apis-application-want.md#want) | Yes | **Want** information, including the ability name and bundle name.| | callback | AsyncCallback<void> | Yes| Callback that returns no value.| **Example** @@ -83,7 +83,7 @@ Inserts data into the database. This API can be overridden as required. | Name| Type| Mandatory| Description| | ----- | ------ | ------ | ------ | | uri |string | Yes | URI of the data to insert.| -| valueBucket |[ValuesBucket](js-apis-data-ValuesBucket.md#valuesbucket) | Yes| Data to insert.| +| valueBucket |[ValuesBucket](js-apis-data-valuesBucket.md#valuesbucket) | Yes| Data to insert.| | callback |AsyncCallback<number> | Yes| Callback invoked to return the index of the data inserted.| **Example** @@ -127,8 +127,8 @@ Updates data in the database. This API can be overridden as required. | Name| Type| Mandatory| Description| | ----- | ------ | ------ | ------ | | uri | string | Yes | URI of the data to update.| -| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Filter criteria for updating data.| -| valueBucket | [ValuesBucket](js-apis-data-ValuesBucket.md#valuesbucket) | Yes| New data.| +| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Filter criteria for updating data.| +| valueBucket | [ValuesBucket](js-apis-data-valuesBucket.md#valuesbucket) | Yes| New data.| | callback | AsyncCallback<number> | Yes| Callback invoked to return the number of updated data records.| **Example** @@ -170,7 +170,7 @@ Deletes data from the database. This API can be overridden as required. | Name | Type | Mandatory| Description | | ---------- | ------------------------------------------------------------ | ---- | ---------------------------------- | | uri | string | Yes | URI of the data to delete. | -| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Filter criteria for deleting data. | +| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Filter criteria for deleting data. | | callback | AsyncCallback<number> | Yes | Callback invoked to return the number of data records deleted.| **Example** @@ -212,7 +212,7 @@ Queries data from the database. This API can be overridden as required. | Name| Type| Mandatory| Description| | ----- | ------ | ------ | ------ | | uri | string | Yes | URI of the data to query.| -| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Filter criteria for querying data.| +| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Filter criteria for querying data.| | columns | Array<string> | Yes| Columns to query. If this parameter is empty, all columns will be queried.| | callback | AsyncCallback<Object> | Yes| Callback invoked to return the result set.| @@ -255,10 +255,10 @@ Batch inserts data into the database. This API is called by the server and can b **Parameters** -| Name | Type | Mandatory| Description | +| Name | Type | Mandatory| Description | | ------------ | ------------------------------------------------------------ | ---- | -------------------------------- | | uri | string | Yes | URI of the data to insert. | -| valueBuckets | Array<[ValuesBucket](js-apis-data-ValuesBucket.md#valuesbucket)> | Yes | Data to insert. | +| valueBuckets | Array<[ValuesBucket](js-apis-data-valuesBucket.md#valuesbucket)> | Yes | Data to insert. | | callback | AsyncCallback<number> | Yes | Callback invoked to return the number of inserted data records.| **Example** diff --git a/en/application-dev/reference/apis/js-apis-call.md b/en/application-dev/reference/apis/js-apis-call.md index 56596e1ffdb8e011627fa026240375ce1094d9ea..7c5bd52bd9ccbc5ee7ad99b8a1e7311ce8c5f8d5 100644 --- a/en/application-dev/reference/apis/js-apis-call.md +++ b/en/application-dev/reference/apis/js-apis-call.md @@ -55,7 +55,7 @@ Initiates a call based on the specified options. This API uses an asynchronous c | Name | Type | Mandatory | Description | | ----------- | ---------------------------- | ---- | --------------------------------------- | | phoneNumber | string | Yes | Phone number. | -| options | [DialOptions](#dialoptions) | Yes | Call option, which indicates whether the call is a voice call or video call. | +| options | [DialOptions](#dialoptions) | No | Call option, which indicates whether the call is a voice call or video call. | | callback | AsyncCallback<boolean> | Yes | Callback used to return the result.
- **true**: success
- **false**: failure | **Example** @@ -313,7 +313,7 @@ Checks whether the called number is an emergency number based on the specified p | Name | Type | Mandatory | Description | | ----------- | -------------------------------------------------- | ---- | -------------------------------------------- | | phoneNumber | string | Yes | Phone number. | -| options | [EmergencyNumberOptions](#emergencynumberoptions7) | Yes | Phone number options. | +| options | [EmergencyNumberOptions](#emergencynumberoptions7) | No | Phone number options. | | callback | AsyncCallback<boolean> | Yes | Callback used to return the result.
- **true**: The called number is an emergency number.
- **false**: The called number is not an emergency number. | **Example** @@ -397,7 +397,7 @@ A formatted phone number is a standard numeric string, for example, 555 0100. | Name | Type | Mandatory | Description | | ----------- | -------------------------------------------- | ---- | ------------------------------------ | | phoneNumber | string | Yes | Phone number. | -| options | [NumberFormatOptions](#numberformatoptions7) | Yes | Number formatting options, for example, country code. | +| options | [NumberFormatOptions](#numberformatoptions7) | No | Number formatting options, for example, country code. | | callback | AsyncCallback<string> | Yes | Callback used to return the result. | **Example** @@ -566,33 +566,6 @@ promise.then(data => { }); ``` -## call.answer7+ - -answer\(callback: AsyncCallback\): void - -Answers a call. This API uses an asynchronous callback to return the result. - -This is a system API. - -**Required permission**: ohos.permission.ANSWER_CALL - -**System capability**: SystemCapability.Telephony.CallManager - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------- | ---- | ---------- | -| callback | AsyncCallback<void> | Yes | Callback used to return the result.| - -**Example** - -```js -call.answer((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); -}); -``` - - ## call.answer7+ answer\(callId: number, callback: AsyncCallback\): void @@ -658,7 +631,7 @@ promise.then(data => { ## call.hangup7+ -hangup\(callback: AsyncCallback\): void +hangup\(callId: number, callback: AsyncCallback\): void Ends a call. This API uses an asynchronous callback to return the result. @@ -672,22 +645,23 @@ This is a system API. | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | +| callId | number | Yes | Call ID. You can obtain the value by subscribing to **callDetailsChange** events.| | callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** ```js -call.hangup((err, data) => { +call.hangup(1, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); ``` -## call.hangup7+ +## call.answer9+ -hangup\(callId: number, callback: AsyncCallback\): void +answer\(callback: AsyncCallback\): void -Ends a call based on the specified call ID. This API uses an asynchronous callback to return the result. +Answers a call.This API uses an asynchronous callback to return the result. This is a system API. @@ -699,13 +673,12 @@ This is a system API. | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ----------------------------------------------- | -| callId | number | Yes | Call ID. You can obtain the value by subscribing to **callDetailsChange** events.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js -call.hangup(1, (err, data) => { +call.answer((err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); ``` @@ -746,11 +719,11 @@ promise.then(data => { }); ``` -## call.reject7+ +## call.hangup9+ -reject\(callback: AsyncCallback\): void +hangup\(callback: AsyncCallback\): void -Rejects a call. This API uses an asynchronous callback to return the result. +Ends a call. This API uses an asynchronous callback to return the result. This is a system API. @@ -767,38 +740,7 @@ This is a system API. **Example** ```js -call.reject((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); -}); -``` - - -## call.reject7+ - -reject\(options: RejectMessageOptions, callback: AsyncCallback\): void - -Rejects a call based on the specified options. This API uses an asynchronous callback to return the result. - -This is a system API. - -**Required permission**: ohos.permission.ANSWER_CALL - -**System capability**: SystemCapability.Telephony.CallManager - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ---------------------------------------------- | ---- | -------------- | -| options | [RejectMessageOptions](#rejectmessageoptions7) | Yes | Options for the call rejection message.| -| callback | AsyncCallback<void> | Yes | Callback used to return the result. | - -**Example** - -```js -let rejectMessageOptions={ - messageContent: "Unknown number blocked" -} -call.reject(rejectMessageOptions, (err, data) => { +call.hangup((err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); ``` @@ -903,6 +845,65 @@ promise.then(data => { }); ``` + +## call.reject9+ + +reject\(callback: AsyncCallback\): void + +Rejects a call. This API uses an asynchronous callback to return the result. + +This is a system API. + +**Required permission**: ohos.permission.ANSWER_CALL + +**System capability**: SystemCapability.Telephony.CallManager + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| callback | AsyncCallback<void> | Yes | Callback used to return the result.| + +**Example:** + +```js +call.reject((err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + + +## call.reject9+ + +reject\(options: RejectMessageOptions, callback: AsyncCallback\): void + +Rejects a call. This API uses an asynchronous callback to return the result. + +This is a system API. + +**Required permission**: ohos.permission.ANSWER_CALL + +**System capability**: SystemCapability.Telephony.CallManager + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------------------- | ---- | -------------- | +| options | [RejectMessageOptions](#rejectmessageoptions7) | Yes | Options for the call rejection message.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result. | + +**Example:** + +```js +let rejectMessageOptions={ + messageContent: "Unknown number blocked" +} +call.reject(rejectMessageOptions, (err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + + ## call.holdCall7+ holdCall\(callId: number, callback: AsyncCallback\): void @@ -1344,8 +1345,8 @@ This is a system API. | Name | Type | Mandatory| Description | | -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2 | -| callback | AsyncCallback<[CallWaitingStatus](#callwaitingstatus7)\> | Yes | Callback used to return the result.

- **0**: Call waiting is disabled.
- **1**: Call waiting is enabled.| +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2 | +| callback | AsyncCallback<[CallWaitingStatus](#callwaitingstatus7)\> | Yes | Callback used to return the result.
- **0**: Call waiting is disabled.
- **1**: Call waiting is enabled.| **Example** @@ -1703,7 +1704,7 @@ This is a system API. | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------ | ---- | -------------------------- | | type | string | Yes | Cause of the call disconnection.| -| callback | Callback<[DisconnectedDetails](#disconnecteddetails8)> | Yes | Callback used to return the result. | +| callback | Callback<[DisconnectedDetails](#disconnecteddetails9)> | Yes | Callback used to return the result. | **Example** @@ -1811,7 +1812,7 @@ This is a system API. | Name | Type | Mandatory| Description | | -------- | ---------------------------------------------------------- | ---- | -------------------- | | type | 'callDisconnectedCause' | Yes | Unsubscription from the call disconnection cause when a call ends.| -| callback | Callback**<**[DisconnectedDetails](#disconnecteddetails8)> | No | Callback used to return the result. | +| callback | Callback**<**[DisconnectedDetails](#disconnecteddetails9)> | No | Callback used to return the result. | **Example** @@ -2399,7 +2400,7 @@ promise.then(data => { }); ``` -## call.setAudioDevice8+ +## call.setAudioDevice9+ setAudioDevice\(device: AudioDevice, callback: AsyncCallback\): void @@ -2425,7 +2426,7 @@ call.setAudioDevice(1, (err, data) => { ``` -## call.setAudioDevice8+ +## call.setAudioDevice9+ setAudioDevice\(device: AudioDevice, options: AudioDeviceOptions, callback: AsyncCallback\): void @@ -2907,11 +2908,15 @@ This is a system API. **System capability**: SystemCapability.Telephony.CallManager -| Name | Type | Mandatory| Description | -| ----------- | ---------------------------------------------------- | ---- | ---------------- | -| transferNum | string | Yes | Call transfer number. | -| type | [CallTransferType](#calltransfertype8) | Yes | Call transfer type. | -| settingType | [CallTransferSettingType](#calltransfersettingtype8) | Yes | Call transfer setting type.| +| Name | Type | Mandatory| Description | +| ------------------------ | ---------------------------------------------------- | ---- | ---------------- | +| transferNum | string | Yes | Call transfer number. | +| type | [CallTransferType](#calltransfertype8) | Yes | Call transfer type. | +| settingType | [CallTransferSettingType](#calltransfersettingtype8) | Yes | Call transfer setting type.| +| startHour9+ | number | No | Hour in the start time.| +| startMinute9+ | number | No | Minute in the start time.| +| endHour9+ | number | No | Hour in the end time.| +| endMinute9+ | number | No | Minute in the end time.| ## CallTransferType8+ @@ -3127,10 +3132,14 @@ This is a system API. **System capability**: SystemCapability.Telephony.CallManager -| Name| Type | Mandatory| Description | -| ------ | ---------------------------------- | ---- | -------- | -| status | [TransferStatus](#transferstatus8) | Yes | Transfer status.| -| number | string | Yes | Number. | +| Name | Type | Mandatory| Description | +| ------------------------ | ---------------------------------- | ---- | ---------------- | +| status | [TransferStatus](#transferstatus8) | Yes | Call transfer status. | +| number | string | Yes | Call transfer number. | +| startHour9+ | number | Yes | Hour in the start time.| +| startMinute9+ | number | Yes | Minute in the start time.| +| endHour9+ | number | Yes | Hour in the end time.| +| endMinute9+ | number | Yes | Minute in the end time.| ## CallWaitingStatus7+ @@ -3171,7 +3180,20 @@ This is a system API. | TRANSFER_DISABLE | 0 | Call transfer disabled.| | TRANSFER_ENABLE | 1 | Call transfer enabled.| -## DisconnectedDetails8+ +## DisconnectedDetails9+ + +Defines the cause of a call disconnection. + +This is a system API. + +**System capability**: SystemCapability.Telephony.CallManager + +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------ | ---- | --------------- | +| reason | [DisconnectedReason](#disconnectedreason8) | Yes | Cause of the call disconnection. | +| message | string | Yes | Message indicating the call disconnection.| + +## DisconnectedReason8+ Enumerates causes of call disconnection. @@ -3179,28 +3201,87 @@ This is a system API. **System capability**: SystemCapability.Telephony.CallManager -| Name | Value | Description | -| --------------------------- | ---- | ---------------------- | -| UNASSIGNED_NUMBER | 1 | Unallocated number. | -| NO_ROUTE_TO_DESTINATION | 3 | No route to the destination. | -| CHANNEL_UNACCEPTABLE | 6 | Unacceptable channel. | -| OPERATOR_DETERMINED_BARRING | 8 | Operator determined barring (ODB). | -| NORMAL_CALL_CLEARING | 16 | Normal call clearing. | -| USER_BUSY | 17 | User busy. | -| NO_USER_RESPONDING | 18 | No user response. | -| USER_ALERTING_NO_ANSWER | 19 | Alerting but no answer.| -| CALL_REJECTED | 21 | Call rejected. | -| NUMBER_CHANGED | 22 | Number changed. | -| DESTINATION_OUT_OF_ORDER | 27 | Destination fault. | -| INVALID_NUMBER_FORMAT | 28 | Invalid number format. | -| NETWORK_OUT_OF_ORDER | 38 | Network fault. | -| TEMPORARY_FAILURE | 41 | Temporary fault. | -| INVALID_PARAMETER | 1025 | Invalid parameter. | -| SIM_NOT_EXIT | 1026 | SIM card not exit. | -| SIM_PIN_NEED | 1027 | SIM card PIN required. | -| CALL_NOT_ALLOW | 1029 | Call not allowed. | -| SIM_INVALID | 1045 | Invalid SIM card. | -| UNKNOWN | 1279 | Unknown reason. | +| Name | Value | Description | +| ------------------------------------------------------------ | ---- | --------------------------------------- | +| UNASSIGNED_NUMBER | 1 | Unallocated (unassigned) number. | +| NO_ROUTE_TO_DESTINATION | 3 | No route to destination. | +| CHANNEL_UNACCEPTABLE | 6 | Channel unacceptable. | +| OPERATOR_DETERMINED_BARRING | 8 | Operator determined barring (ODB). | +| CALL_COMPLETED_ELSEWHERE9+ | 13 | Call completed elsewhere. | +| NORMAL_CALL_CLEARING | 16 | Normal call clearing. | +| USER_BUSY | 17 | User busy. | +| NO_USER_RESPONDING | 18 | No user responding. | +| USER_ALERTING_NO_ANSWER | 19 | User alerting, no answer. | +| CALL_REJECTED | 21 | Call rejected. | +| NUMBER_CHANGED | 22 | Number changed. | +| CALL_REJECTED_DUE_TO_FEATURE_AT_THE_DESTINATION9+ | 24 | Call rejected due to feature at the destination.| +| FAILED_PRE_EMPTION9+ | 25 | Failed preemption. | +| NON_SELECTED_USER_CLEARING9+ | 26 | Non-selected user clearing. | +| DESTINATION_OUT_OF_ORDER | 27 | Destination out of order. | +| INVALID_NUMBER_FORMAT | 28 | Invalid number format (incomplete number). | +| FACILITY_REJECTED9+ | 29 | Facility rejected. | +| RESPONSE_TO_STATUS_ENQUIRY9+ | 30 | Response to status enquiry. | +| NORMAL_UNSPECIFIED9+ | 31 | Normal, unspecified. | +| NO_CIRCUIT_CHANNEL_AVAILABLE9+ | 34 | No circuit/channel available. | +| NETWORK_OUT_OF_ORDER | 38 | Network fault. | +| TEMPORARY_FAILURE | 41 | Temporary failure. | +| SWITCHING_EQUIPMENT_CONGESTION9+ | 42 | Switching equipment congestion. | +| ACCESS_INFORMATION_DISCARDED9+ | 43 | Access information discarded. | +| REQUEST_CIRCUIT_CHANNEL_NOT_AVAILABLE9+ | 44 | Requested circuit/channel unavailable | +| RESOURCES_UNAVAILABLE_UNSPECIFIED9+ | 47 | Resources unavailable, unspecified. | +| QUALITY_OF_SERVICE_UNAVAILABLE9+ | 49 | QoS unavailable. | +| REQUESTED_FACILITY_NOT_SUBSCRIBED9+ | 50 | Requested facility not subscribed. | +| INCOMING_CALLS_BARRED_WITHIN_THE_CUG9+ | 55 | Incoming calls barred within the CUG. | +| BEARER_CAPABILITY_NOT_AUTHORIZED9+ | 57 | Bearer capability not authorized. | +| BEARER_CAPABILITY_NOT_PRESENTLY_AVAILABLE9+ | 58 | Bearer capability presently available. | +| SERVICE_OR_OPTION_NOT_AVAILABLE_UNSPECIFIED9+ | 63 | Service or option not available, unspecified. | +| BEARER_SERVICE_NOT_IMPLEMENTED9+ | 65 | Bearer service not implemented. | +| ACM_EQUALTO_OR_GREATER_THAN_THE_MAXIMUM_VALUE9+ | 68 | ACM greater than or equal to the maximum value. | +| REQUESTED_FACILITY_NOT_IMPLEMENTED9+ | 69 | Requested facility not implemented. | +| ONLY_RESTRICTED_DIGITAL_INFO_BEARER_CAPABILITY_IS_AVAILABLE9+ | 70 | Only restricted digital information capability available. | +| SERVICE_OR_OPTION_NOT_IMPLEMENTED_UNSPECIFIED9+ | 79 | Service or option not implemented, unspecified. | +| INVALID_TRANSACTION_IDENTIFIER_VALUE9+ | 81 | Invalid transaction identifier value. | +| USER_NOT_MEMBER_OF_CUG9+ | 87 | User not member of CUG. | +| INCOMPATIBLE_DESTINATION9+ | 88 | Incompatible destination. | +| INVALID_TRANSIT_NETWORK_SELECTION9+ | 91 | Invalid transit network selection. | +| SEMANTICALLY_INCORRECT_MESSAGE9+ | 95 | Semantically incorrect message. | +| INVALID_MANDATORY_INFORMATION9+ | 96 | Invalid mandatory information. | +| MESSAGE_TYPE_NON_EXISTENT_OR_NOT_IMPLEMENTED9+ | 97 | Message type non-existent or not implemented. | +| MESSAGE_TYPE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE9+ | 98 | Message type not compatible with protocol state. | +| INFORMATION_ELEMENT_NON_EXISTENT_OR_NOT_IMPLEMENTED9+ | 99 | IE non-existent or not implemented. | +| CONDITIONAL_IE_ERROR9+ | 100 | Conditional IE error. | +| MESSAGE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE9+ | 101 | Message not compatible with protocol state. | +| RECOVERY_ON_TIMER_EXPIRED9+ | 102 | Recovery on timer expiry. | +| PROTOCOL_ERROR_UNSPECIFIED9+ | 111 | Protocol error, unspecified. | +| INTERWORKING_UNSPECIFIED9+ | 127 | Interworking, unspecified. | +| CALL_BARRED9+ | 240 | Call barred. | +| FDN_BLOCKED9+ | 241 | FDN blocked. | +| IMSI_UNKNOWN_IN_VLR9+ | 242 | IMSI unknown in VLR. | +| IMEI_NOT_ACCEPTED9+ | 243 | IMEI not accepted. | +| DIAL_MODIFIED_TO_USSD9+ | 244 | Dial request modified to USSD request. | +| DIAL_MODIFIED_TO_SS9+ | 245 | Dial request modified to SS request. | +| DIAL_MODIFIED_TO_DIAL9+ | 246 | Dial request modified to dial with different number. | +| RADIO_OFF9+ | 247 | Radio off. | +| OUT_OF_SERVICE9+ | 248 | Out of service. | +| NO_VALID_SIM9+ | 249 | No valid SIM. | +| RADIO_INTERNAL_ERROR9+ | 250 | Radio internal error. | +| NETWORK_RESP_TIMEOUT9+ | 251 | Network response timeout. | +| NETWORK_REJECT9+ | 252 | Request rejected by network. | +| RADIO_ACCESS_FAILURE9+ | 253 | Radio access failure. | +| RADIO_LINK_FAILURE9+ | 254 | Radio link failure. | +| RADIO_LINK_LOST9+ | 255 | Radio link lost. | +| RADIO_UPLINK_FAILURE9+ | 256 | Radio uplink failure. | +| RADIO_SETUP_FAILURE9+ | 257 | Radio setup failure. | +| RADIO_RELEASE_NORMAL9+ | 258 | Radio release normal. | +| RADIO_RELEASE_ABNORMAL9+ | 259 | Radio release abnormal. | +| ACCESS_CLASS_BLOCKED9+ | 260 | Access class blocked. | +| NETWORK_DETACH9+ | 261 | Network detached. | +| INVALID_PARAMETER | 1025 | Invalid parameter. | +| SIM_NOT_EXIT | 1026 | SIM not exit. | +| SIM_PIN_NEED | 1027 | SIM PIN needed. | +| CALL_NOT_ALLOW | 1029 | Call not allowed. | +| SIM_INVALID | 1045 | No valid SIM. | +| UNKNOWN | 1279 | Unknown reason. | ## MmiCodeResults9+ diff --git a/en/application-dev/reference/apis/js-apis-cooperate.md b/en/application-dev/reference/apis/js-apis-cooperate.md index 81c2b8547c4433d86d04e9d1ebffbbfd55ff1a12..d63729a9dcf6a08133dd28f7cdabc6e63f0a4b6e 100644 --- a/en/application-dev/reference/apis/js-apis-cooperate.md +++ b/en/application-dev/reference/apis/js-apis-cooperate.md @@ -20,7 +20,7 @@ enable(enable: boolean, callback: AsyncCallback<void>): void Specifies whether to enable screen hopping. This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.MultimodalInput.Input.Cooperate +**System capability**: SystemCapability.MultimodalInput.Input.Cooperator **Parameters** @@ -54,7 +54,7 @@ enable(enable: boolean): Promise<void> Specifies whether to enable screen hopping. This API uses a promise to return the result. -**System capability**: SystemCapability.MultimodalInput.Input.Cooperate +**System capability**: SystemCapability.MultimodalInput.Input.Cooperator **Parameters** @@ -92,7 +92,7 @@ start(sinkDeviceDescriptor: string, srcInputDeviceId: number, callback: AsyncCal Starts screen hopping. This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.MultimodalInput.Input.Cooperate +**System capability**: SystemCapability.MultimodalInput.Input.Cooperator **Parameters** @@ -135,7 +135,7 @@ start(sinkDeviceDescriptor: string, srcInputDeviceId: number): Promise\ Starts screen hopping. This API uses a promise to return the result. -**System capability**: SystemCapability.MultimodalInput.Input.Cooperate +**System capability**: SystemCapability.MultimodalInput.Input.Cooperator **Parameters** @@ -183,7 +183,7 @@ stop(callback: AsyncCallback\): void Stops screen hopping. This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.MultimodalInput.Input.Cooperate +**System capability**: SystemCapability.MultimodalInput.Input.Cooperator **Parameters** @@ -215,7 +215,7 @@ stop(): Promise\ Stops screen hopping. This API uses a promise to return the result. -**System capability**: SystemCapability.MultimodalInput.Input.Cooperate +**System capability**: SystemCapability.MultimodalInput.Input.Cooperator **Return value** @@ -243,7 +243,7 @@ getState(deviceDescriptor: string, callback: AsyncCallback<{ state: boolean }>): Checks whether screen hopping is enabled. This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.MultimodalInput.Input.Cooperate +**System capability**: SystemCapability.MultimodalInput.Input.Cooperator **Parameters** @@ -275,7 +275,7 @@ getState(deviceDescriptor: string): Promise<{ state: boolean }> Checks whether screen hopping is enabled. This API uses a promise to return the result. -**System capability**: SystemCapability.MultimodalInput.Input.Cooperate +**System capability**: SystemCapability.MultimodalInput.Input.Cooperator **Parameters** @@ -313,7 +313,7 @@ on(type: 'cooperation', callback: AsyncCallback<{ deviceDescriptor: string, even Enables listening for screen hopping events. -**System capability**: SystemCapability.MultimodalInput.Input.Cooperate +**System capability**: SystemCapability.MultimodalInput.Input.Cooperator **Parameters** @@ -342,7 +342,7 @@ off(type: 'cooperation', callback?: AsyncCallback\): void Disables listening for screen hopping events. -**System capability**: SystemCapability.MultimodalInput.Input.Cooperate +**System capability**: SystemCapability.MultimodalInput.Input.Cooperator **Parameters** @@ -386,7 +386,7 @@ try { Enumerates screen hopping event. -**System capability**: SystemCapability.MultimodalInput.Input.Cooperate +**System capability**: SystemCapability.MultimodalInput.Input.Cooperator | Name | Value | Description | | -------- | --------- | ----------------- | diff --git a/en/application-dev/reference/apis/js-apis-curve.md b/en/application-dev/reference/apis/js-apis-curve.md index 11b95aa03d0135d811ee21f9e672ad1798d23b5c..2c90472a98a38d74e7211eb8dcef2061082f18c8 100644 --- a/en/application-dev/reference/apis/js-apis-curve.md +++ b/en/application-dev/reference/apis/js-apis-curve.md @@ -1,6 +1,6 @@ -# Interpolation Calculation +# @ohos.curves -The **Curves** module provides APIs for interpolation calculation to construct step, cubic Bezier, and spring curve objects. +The **Curves** module provides APIs for interpolation calculation to create step, cubic Bezier, and spring curves. > **NOTE** > @@ -19,7 +19,7 @@ import Curves from '@ohos.curves' initCurve(curve?: Curve): ICurve -Implements initialization for the interpolation curve, which is used to create an interpolation curve object based on the input parameter. +Implements initialization for the interpolation curve, which is used to create an interpolation curve based on the input parameter. **System capability**: SystemCapability.ArkUI.ArkUI.Full @@ -33,7 +33,7 @@ Implements initialization for the interpolation curve, which is used to create a | Type | Description | | ---------------------------------- | ---------------- | -| [ICurve](#icurve) | Curve object.| +| [ICurve](#icurve) | Interpolation curve.| **Example** @@ -49,7 +49,7 @@ Curves.initCurve(Curve.EaseIn) // Create a default ease-in curve, where the inte stepsCurve(count: number, end: boolean): ICurve -Constructs a step curve object. +Creates a step curve. **System capability**: SystemCapability.ArkUI.ArkUI.Full @@ -64,7 +64,7 @@ Constructs a step curve object. | Type | Description | | ---------------------------------- | ---------------- | -| [ICurve](#icurve) | Curve object.| +| [ICurve](#icurve) | Interpolation curve.| **Example** @@ -80,7 +80,7 @@ Curves.stepsCurve(9, true) // Create a step curve. cubicBezierCurve(x1: number, y1: number, x2: number, y2: number): ICurve -Constructs a cubic Bezier curve object. The curve values must be between 0 and 1. +Creates a cubic Bezier curve. The curve values must be between 0 and 1. **System capability**: SystemCapability.ArkUI.ArkUI.Full @@ -96,7 +96,7 @@ Constructs a cubic Bezier curve object. The curve values must be between 0 and 1 | Type | Description | | ---------------------------------- | ---------------- | -| [ICurve](#icurve) | Curve object.| +| [ICurve](#icurve) | Interpolation curve.| **Example** @@ -112,7 +112,7 @@ Curves.cubicBezierCurve(0.1, 0.0, 0.1, 1.0) // Create a cubic Bezier curve. springCurve(velocity: number, mass: number, stiffness: number, damping: number): ICurve -Constructs a spring curve object. +Creates a spring curve. **System capability**: SystemCapability.ArkUI.ArkUI.Full @@ -120,7 +120,7 @@ Constructs a spring curve object. | Name | Type | Mandatory | Description | | --------- | ------ | ---- | ----- | | velocity | number | Yes | Initial velocity. It is applied by external factors to the elastic animation. It aims to help ensure the smooth transition from the previous motion state to the elastic animation.| -| mass | number | Yes | Mass. Force object of the elastic system, which will have inertia effect on the elastic system. The greater the mass, the greater the amplitude of the oscillation, and the slower the speed of restoring to the equilibrium position.| +| mass | number | Yes | Mass, which influences the inertia in the spring system. The greater the mass, the greater the amplitude of the oscillation, and the slower the speed of restoring to the equilibrium position.| | stiffness | number | Yes | Stiffness. It is the degree to which an object deforms by resisting the force applied. In an elastic system, the greater the stiffness, the stronger the ability to resist deformation, and the faster the speed of restoring to the equilibrium position.| | damping | number | Yes | Damping. It is a pure number and has no real physical meaning. It is used to describe the oscillation and attenuation of the system after being disturbed. The larger the damping, the smaller the number of oscillations of elastic motion, and the smaller the oscillation amplitude.| @@ -129,7 +129,7 @@ Constructs a spring curve object. | Type | Description | | ---------------------------------- | ---------------- | -| [ICurve](#icurve)| Curve object.| +| [ICurve](#icurve)| Interpolation curve.| **Example** @@ -140,6 +140,68 @@ Curves.springCurve(100, 1, 228, 30) // Create a spring curve. ``` +## Curves.springMotion9+ + +springMotion(response?: number, dampingFraction?: number, overlapDuration?: number): ICurve + +Creates a spring animation curve. If multiple spring animations are applied to the same attribute of an object, each animation replaces their predecessor and inherits the velocity. + +**System capability**: SystemCapability.ArkUI.ArkUI.Full + +**Parameters** +| Name | Type | Mandatory | Description | +| --------- | ------ | ---- | ----- | +| response | number | No | Duration of one complete oscillation, in seconds.
Default value: **0.55**| +| dampingFraction | number | No | Damping coefficient.
**0**: undamped. In this case, the spring oscillates forever.
> 0 and < 1: underdamped. In this case, the spring overshoots the equilibrium position.
**1**: critically damped.
> 1: overdamped. In this case, the spring approaches equilibrium gradually.
Default value: **0.825**| +| overlapDuration | number | No | Duration for animations to overlap, in seconds. When animations overlap, if the **response** values of the two animations are different, they will transit smoothly over this duration.
Default value: **0**| + + +**Return value** + +| Type | Description | +| ---------------------------------- | ---------------- | +| [ICurve](#icurve)| Curve.
Note: The spring animation curve is physics-based. Its duration depends on the **springMotion** parameters and the previous velocity, rather than the **duration** parameter in **animation** or **animateTo**. The time cannot be normalized. Therefore, the interpolation cannot be obtained by using the [interpolate](#interpolate) function of the curve.| + +**Example** + +```ts +import Curves from '@ohos.curves' +Curves.springMotion() // Create a spring animation curve with default settings. +Curves.springMotion(0.5) // Create a spring animation curve with the specified response value. +Curves.springMotion (0.5, 0.6) // Create a spring animation curve with the specified response and dampingFraction values. +Curves.springMotion(0.5, 0.6, 0) // Create a spring animation curve with the specified parameter values. +``` + + +## Curves.responsiveSpringMotion9+ + +responsiveSpringMotion(response?: number, dampingFraction?: number, overlapDuration?: number): ICurve + +Creates a responsive spring animation curve. It is a special case of [springMotion](#curvesspringmotion9), with the only difference in the default values. It can be used together with **springMotion**. + +**System capability**: SystemCapability.ArkUI.ArkUI.Full + +**Parameters** +| Name | Type | Mandatory | Description | +| --------- | ------ | ---- | ----- | +| response | number | No | See **response** in **springMotion**. Default value: **0.15**| +| dampingFraction | number | No | See **dampingFraction** in **springMotion**. Default value: **0.86**| +| overlapDuration | number | No | See **overlapDuration** in **springMotion**. Default value: **0.25**| + +**Return value** + +| Type | Description | +| ---------------------------------- | ---------------- | +| [ICurve](#icurve)| Curve.
**NOTE**
1. To apply custom settings for a spring animation, you are advised to use **springMotion**. When using **responsiveSpringMotion**, you are advised to retain the default settings.
2. The duration of the responsive spring animation depends on the **responsiveSpringMotion** parameters and the previous velocity, rather than the **duration** parameter in **animation** or **animateTo**. In addition, the interpolation cannot be obtained by using the [interpolate](#interpolate) function of the curve.| + +**Example** + +```ts +import Curves from '@ohos.curves' +Curves.responsiveSpringMotion() // Create a responsive spring animation curve with default settings. +``` + + ## ICurve @@ -194,7 +256,7 @@ Implements initialization to create a curve. This API is deprecated since API ve steps(count: number, end: boolean): string -Constructs a step curve object. This API is deprecated since API version 9. You are advised to use [Curves.stepsCurve](#curvesstepscurve9) instead. +Creates a step curve. This API is deprecated since API version 9. You are advised to use [Curves.stepsCurve](#curvesstepscurve9) instead. **System capability**: SystemCapability.ArkUI.ArkUI.Full @@ -211,7 +273,7 @@ Constructs a step curve object. This API is deprecated since API version 9. You cubicBezier(x1: number, y1: number, x2: number, y2: number): string -Constructs a cubic Bezier curve object. The curve value must range from 0 to 1. This API is deprecated since API version 9. You are advised to use [Curves.cubicBezierCurve](#curvescubicbeziercurve9) instead. +Creates a cubic Bezier curve. The curve value must range from 0 to 1. This API is deprecated since API version 9. You are advised to use [Curves.cubicBezierCurve](#curvescubicbeziercurve9) instead. **System capability**: SystemCapability.ArkUI.ArkUI.Full @@ -229,7 +291,7 @@ Constructs a cubic Bezier curve object. The curve value must range from 0 to 1. spring(velocity: number, mass: number, stiffness: number, damping: number): string -Constructs a spring curve object. This API is deprecated since API version 9. You are advised to use [Curves.springCurve](#curvesspringcurve9) instead. +Creates a spring curve. This API is deprecated since API version 9. You are advised to use [Curves.springCurve](#curvesspringcurve9) instead. **System capability**: SystemCapability.ArkUI.ArkUI.Full @@ -238,7 +300,7 @@ Constructs a spring curve object. This API is deprecated since API version 9. Yo | Name | Type | Mandatory | Description | | --------- | ------ | ---- | ----- | | velocity | number | Yes | Initial velocity. It is applied by external factors to the elastic animation. It aims to help ensure the smooth transition from the previous motion state to the elastic animation.| -| mass | number | Yes | Mass. Force object of the elastic system, which will have inertia effect on the elastic system. The greater the mass, the greater the amplitude of the oscillation, and the slower the speed of restoring to the equilibrium position.| +| mass | number | Yes | Mass, which influences the inertia in the spring system. The greater the mass, the greater the amplitude of the oscillation, and the slower the speed of restoring to the equilibrium position.| | stiffness | number | Yes | Stiffness. It is the degree to which an object deforms by resisting the force applied. In an elastic system, the greater the stiffness, the stronger the ability to resist deformation, and the faster the speed of restoring to the equilibrium position.| | damping | number | Yes | Damping. It is a pure number and has no real physical meaning. It is used to describe the oscillation and attenuation of the system after being disturbed. The larger the damping, the smaller the number of oscillations of elastic motion, and the smaller the oscillation amplitude.| @@ -247,6 +309,7 @@ Constructs a spring curve object. This API is deprecated since API version 9. Yo ```ts // xxx.ets import Curves from '@ohos.curves' + @Entry @Component struct ImageComponent { @@ -256,16 +319,16 @@ struct ImageComponent { build() { Column() { Text() - .margin({top:100}) + .margin({ top: 100 }) .width(this.widthSize) .height(this.heightSize) .backgroundColor(Color.Red) - .onClick(()=> { + .onClick(() => { let curve = Curves.cubicBezierCurve(0.25, 0.1, 0.25, 1.0); this.widthSize = curve.interpolate(0.5) * this.widthSize; this.heightSize = curve.interpolate(0.5) * this.heightSize; }) - .animation({duration: 2000 , curve: Curves.stepsCurve(9, true)}) + .animation({ duration: 2000, curve: Curves.stepsCurve(9, true) }) }.width("100%").height("100%") } } diff --git a/en/application-dev/reference/apis/js-apis-data-storage.md b/en/application-dev/reference/apis/js-apis-data-storage.md index b724dfabc1fed1e99d98ad5bba715d81d91677b8..8df3ab1e84ff92e39f31566416a34c4ffb3afa9b 100644 --- a/en/application-dev/reference/apis/js-apis-data-storage.md +++ b/en/application-dev/reference/apis/js-apis-data-storage.md @@ -1,6 +1,6 @@ -# Lightweight Storage +# @ohos.data.storage -Lightweight storage provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value (KV) pairs. Keys are of the string type, and values can be of the number, string, or Boolean type. +The **DataStorage** module provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value (KV) pairs. Keys are of the string type, and values can be of the number, string, or Boolean type. > **NOTE** diff --git a/en/application-dev/reference/apis/js-apis-http.md b/en/application-dev/reference/apis/js-apis-http.md index a33f7369843df9ab17a1aa52df97af99125dae6c..3735792dd3f5ce66569fbebf3a1036019e7457ed 100644 --- a/en/application-dev/reference/apis/js-apis-http.md +++ b/en/application-dev/reference/apis/js-apis-http.md @@ -70,7 +70,7 @@ Creates an HTTP request. You can use this API to initiate or destroy an HTTP req **Return value** | Type | Description | -| :---------- | :----------------------------------------------------------- | +| ---------- | ----------------------------------------------------------- | | HttpRequest | An **HttpRequest** object, which contains the **request**, **destroy**, **on**, or **off** method.| **Example** @@ -179,7 +179,7 @@ Initiates an HTTP request to a given URL. This API uses a promise to return the **Return value** | Type | Description | -| :------------------------------------- | :-------------------------------- | +| ------------------------------------- | -------------------------------- | | Promise<[HttpResponse](#httpresponse)> | Promise used to return the result.| @@ -372,7 +372,7 @@ Defines an HTTP request method. **System capability**: SystemCapability.Communication.NetStack | Name | Value | Description | -| :------ | ------- | :------------------ | +| ------ | ------- | ------------------ | | OPTIONS | "OPTIONS" | OPTIONS method.| | GET | "GET" | GET method. | | HEAD | "HEAD" | HEAD method. | @@ -457,7 +457,7 @@ Creates a default object to store responses to HTTP access requests. **Return value** | Type | Description | -| :---------- | :----------------------------------------------------------- | +| ---------- | ----------------------------------------------------------- | | [HttpResponseCache](#httpresponsecache9) | Object that stores the response to the HTTP request.| **Example** @@ -600,6 +600,6 @@ Enumerates HTTP protocol versions. **System capability**: SystemCapability.Communication.NetStack | Name | Description | -| :-------- | :----------- | +| -------- | ----------- | | HTTP1_1 | HTTP1.1 | | HTTP2 | HTTP2 | diff --git a/en/application-dev/reference/apis/js-apis-i18n.md b/en/application-dev/reference/apis/js-apis-i18n.md index e990ecf8126054b0de5ad52308c4f83843782d97..08bf0cfe66b40f46262765048463081b9c1a66a6 100644 --- a/en/application-dev/reference/apis/js-apis-i18n.md +++ b/en/application-dev/reference/apis/js-apis-i18n.md @@ -1,13 +1,10 @@ # Internationalization – I18N - This module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402. +The I18N module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402. The [Intl](js-apis-intl.md) module provides basic I18N capabilities through the standard I18N APIs defined in ECMA 402. It works with the I18N module to provide a complete suite of I18N capabilities. > **NOTE** -> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> -> - This module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402. For details about the basic I18N capabilities, see [Intl](js-apis-intl.md). - +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import @@ -247,9 +244,9 @@ This is a system API. **Parameters** -| Name | Type | Description | -| -------- | ------ | ----- | -| language | string | Language ID.| +| Name | Type | Mandatory | Description | +| -------- | ------ | ----- | ----- | +| language | string | Yes | Language ID.| **Error codes** @@ -313,9 +310,9 @@ This is a system API. **Parameters** -| Name | Type | Description | -| ------ | ------ | ----- | -| region | string | Region ID.| +| Name | Type | Mandatory | Description | +| -------- | ------ | ----- | ----- | +| region | string | Yes | Region ID.| **Error codes** @@ -379,9 +376,9 @@ This is a system API. **Parameters** -| Name | Type | Description | -| ------ | ------ | --------------- | -| locale | string | System locale ID, for example, **zh-CN**.| +| Name | Type | Mandatory | Description | +| -------- | ------ | ----- | ----- | +| locale | string | Yes | System locale ID, for example, **zh-CN**.| **Error codes** @@ -713,9 +710,9 @@ Checks whether the localized script for the specified language is displayed from **Parameters** -| Name | Type | Description | -| ------ | ------ | ------- | -| locale | string | Locale ID.| +| Name | Type | Mandatory | Description | +| -------- | ------ | ----- | ----- | +| locale | string | Yes | Locale ID.| **Return value** @@ -905,7 +902,7 @@ Sets the start day of a week for this **Calendar** object. | Name | Type | Mandatory | Description | | ----- | ------ | ---- | --------------------- | -| value | number | No | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.| +| value | number | Yes | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.| **Example** ```js @@ -947,7 +944,7 @@ Sets the minimum number of days in the first week of a year. | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ------------ | -| value | number | No | Minimum number of days in the first week of a year.| +| value | number | Yes | Minimum number of days in the first week of a year.| **Example** ```js diff --git a/en/application-dev/reference/apis/js-apis-inputconsumer.md b/en/application-dev/reference/apis/js-apis-inputconsumer.md index 9df5f776acdac2bc7cac02c2c4bfb83b217b9da3..c2d5a421c87595094308e70c3bf317c8572b37bf 100644 --- a/en/application-dev/reference/apis/js-apis-inputconsumer.md +++ b/en/application-dev/reference/apis/js-apis-inputconsumer.md @@ -106,7 +106,7 @@ Represents combination key options. | Name | Type | Readable | Writable | Description | | --------- | ------ | ---- | ---- | ------- | -| preKeys | Array\ | Yes | No| Front key set. The number of front keys ranges from 0 to 4. There is no requirement on the sequence of the keys.| +| preKeys | Array | Yes | No| Front key set. The number of front keys ranges from 0 to 4. There is no requirement on the sequence of the keys.| | finalKey | number | Yes | No| Final key. This parameter is mandatory. A callback function is triggered by the final key.| | isFinalKeyDown | boolean | Yes | No| Whether the final key is pressed.| | finalKeyDownDuration | number | Yes | No| Duration within which the final key is pressed. If the value is **0**, the callback function is triggered immediately. If the value is greater than **0** and the value of **isFinalKeyDown** is **true**, the callback function is triggered when the key press duration is longer than the value of this parameter. If the value of **isFinalKeyDown** is **false**, the callback function is triggered when the duration from key press to key release is less than the value of this parameter. | diff --git a/en/application-dev/reference/apis/js-apis-inputdevice.md b/en/application-dev/reference/apis/js-apis-inputdevice.md index 54305e4f935b6203faddf31691d7c5bf109a0a62..2f286827a664af0d8dff2e7c8d133ca97f5e0ab7 100644 --- a/en/application-dev/reference/apis/js-apis-inputdevice.md +++ b/en/application-dev/reference/apis/js-apis-inputdevice.md @@ -32,7 +32,7 @@ Obtains the IDs of all input devices. This API uses an asynchronous callback to ```js try { - inputDevice.getDeviceList((error, ids) => { + inputDevice.getDeviceIds((error, ids) => { if (error) { console.log(`Failed to get device list. error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`); @@ -64,7 +64,7 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu ```js try { - inputDevice.getDeviceList().then((ids) => { + inputDevice.getDeviceIds().then((ids) => { console.log("The device ID list is: " + ids); }); } catch (error) { @@ -244,10 +244,15 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. **Example** ```js -inputDevice.getDeviceIds((ids)=>{ - console.log("The device ID list is: " + ids); +inputDevice.getDeviceIds((error, ids) => { + if (error) { + console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`); + return; + } + console.log(`Device id list: ${JSON.stringify(ids)}`); }); ``` +``` ## inputDevice.getDeviceIds(deprecated) @@ -268,8 +273,8 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. **Example** ```js -inputDevice.getDeviceIds().then((ids)=>{ - console.log("The device ID list is: " + ids); +inputDevice.getDeviceIds().then((ids) => { + console.log(`Device id list: ${JSON.stringify(ids)}`); }); ``` @@ -294,8 +299,12 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. ```js // Obtain the name of the device whose ID is 1. -inputDevice.getDevice(1, (inputDevice)=>{ - console.log("The device name is: " + inputDevice.name); +inputDevice.getDevice(1, (error, deviceData) => { + if (error) { + console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`); + return; + } + console.log(`Device info: ${JSON.stringify(deviceData)}`); }); ``` @@ -325,8 +334,8 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. ```js // Obtain the name of the device whose ID is 1. -inputDevice.getDevice(1).then((inputDevice)=>{ - console.log("The device name is: " + inputDevice.name); +inputDevice.getDevice(1).then((deviceData) => { + console.log(`Device info: ${JSON.stringify(deviceData)}`); }); ``` @@ -475,7 +484,7 @@ Defines the information about an input device. | id | number | Yes| No| Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| | name | string | Yes| No| Name of the input device. | | sources | Array<[SourceType](#sourcetype)> | Yes| No| Source type of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad.| -| axisRanges | Array<[axisRanges](#axisrange)> | Yes| No| Axis information of the input device. | +| axisRanges | Array<[AxisRange](#axisrange)> | Yes| No| Axis information of the input device. | | bus9+ | number | Yes| No| Bus type of the input device. | | product9+ | number | Yes| No| Product information of the input device. | | vendor9+ | number | Yes| No| Vendor information of the input device. | diff --git a/en/application-dev/reference/apis/js-apis-inputmethod-subtype.md b/en/application-dev/reference/apis/js-apis-inputmethod-subtype.md index 3db933a52a6f940e8d25a324d0fef7131330bc9f..61ec49997ccb35b204f860e57b0985793598e071 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethod-subtype.md +++ b/en/application-dev/reference/apis/js-apis-inputmethod-subtype.md @@ -1,6 +1,6 @@ -# Input Method Subtype +# @ohos.inputmethodsubtype -The **inputMethodEngine** module provides APIs for managing the attributes of input method subtypes. Different attribute settings result in different subtypes. +The **inputMethodSubtype** module provides APIs for managing the attributes of input method subtypes. Different attribute settings result in different subtypes. > **NOTE** > diff --git a/en/application-dev/reference/apis/js-apis-inputmethod.md b/en/application-dev/reference/apis/js-apis-inputmethod.md index 857bc3fd17b1fc4a29eda9c2e0185dfa11163702..424e48b357711a7ee94eb4b048f107d7ad4c7a3d 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethod.md +++ b/en/application-dev/reference/apis/js-apis-inputmethod.md @@ -1,15 +1,15 @@ -# Input Method Framework +# @ohos.inputmethod The **inputMethod** module provides an input method framework, which can be used to hide the keyboard, obtain the list of installed input methods, display the dialog box for input method selection, and more. ->**NOTE** +> **NOTE** > ->The initial APIs of this module are supported since API version 6. 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 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import -``` +```js import inputMethod from '@ohos.inputmethod'; ``` @@ -31,14 +31,14 @@ Describes the input method application attributes. | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| name9+ | string | Yes| No| Internal name of the input method.| -| id9+ | string | Yes| No| Unique ID of the input method.| -| label9+ | string | Yes| No| External display name of the input method.| -| icon9+ | string | Yes| No| Icon of the input method.| -| iconId9+ | number | Yes| No| Icon ID of the input method.| -| extra9+ | object | Yes| No| Extra information about the input method.| -| packageName(deprecated) | string | Yes| No| Name of the input method package.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.| -| methodId(deprecated) | string | Yes| No| Unique ID of the input method.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.| +| name9+ | string | Yes| No| Internal name of the input method. Mandatory.| +| id9+ | string | Yes| No| Unique ID of the input method. Mandatory.| +| label9+ | string | Yes| No| External display name of the input method. Optional.| +| icon9+ | string | Yes| No| Icon of the input method. Optional.| +| iconId9+ | number | Yes| No| Icon ID of the input method. Optional.| +| extra9+ | object | Yes| Yes| Extra information about the input method. Mandatory.| +| packageName(deprecated) | string | Yes| No| Name of the input method package. Mandatory.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.| +| methodId(deprecated) | string | Yes| No| Unique ID of the input method. Mandatory.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.| ## inputMethod.getController9+ @@ -102,7 +102,7 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolea Switches to another input method. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -120,25 +120,33 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js +let im = inputMethod.getCurrentInputMethod(); +let prop = { + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, + extra: {} +} try{ - inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}, (err, result) => { - if (err) { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + inputMethod.switchInputMethod(prop, (err, result) => { + if (err !== undefined) { + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to switchInputMethod.(callback)'); + console.info('Succeeded in switching inputmethod.'); } else { - console.error('Failed to switchInputMethod.(callback)'); + console.error('Failed to switchInputMethod.'); } }); } catch(err) { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); } ``` ## inputMethod.switchInputMethod9+ @@ -146,7 +154,7 @@ switchInputMethod(target: InputMethodProperty): Promise<boolean> Switches to another input method. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -169,23 +177,31 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js +let im = inputMethod.getCurrentInputMethod(); +let prop = { + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, + extra: {} +} try { - inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}).then((result) => { + inputMethod.switchInputMethod(prop).then((result) => { if (result) { - console.info('Success to switchInputMethod.'); + console.info('Succeeded in switching inputmethod.'); } else { console.error('Failed to switchInputMethod.'); } }).catch((err) => { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); }) } catch(err) { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); } ``` @@ -215,7 +231,7 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallb Switches to another subtype of the current input method. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -233,36 +249,35 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js -let inputMethodSubtype = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, - extra: {} -} try { - inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype, (err, result) => { - if (err) { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + inputMethod.switchCurrentInputMethodSubtype({ + id: "com.example.kikakeyboard", + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }, (err, result) => { + if (err !== undefined) { + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to switchCurrentInputMethodSubtype.(callback)'); + console.info('Succeeded in switching currentInputMethodSubtype.'); } else { - console.error('Failed to switchCurrentInputMethodSubtype.(callback)'); + console.error('Failed to switchCurrentInputMethodSubtype'); } }); } catch(err) { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -272,7 +287,7 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean& Switches to another subtype of the current input method. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -295,34 +310,33 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js -let inputMethodSubtype = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, - extra: {} -} try { - inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype).then((result) => { + inputMethod.switchCurrentInputMethodSubtype({ + id: "com.example.kikakeyboard", + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }).then((result) => { if (result) { - console.info('Success to switchCurrentInputMethodSubtype.'); + console.info('Succeeded in switching currentInputMethodSubtype.'); } else { console.error('Failed to switchCurrentInputMethodSubtype.'); } }).catch((err) => { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -352,7 +366,7 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp Switches to a specified subtype of a specified input method. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -371,41 +385,43 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js +let im = inputMethod.getCurrentInputMethod(); let inputMethodProperty = { - packageName: "com.example.kikakeyboard", - methodId: "ServiceExtAbility", - extra: {} -} -let inputMethodSubProperty = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, extra: {} } try { - inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,result) => { - if (err) { - console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err)); + inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, { + id: "com.example.kikakeyboard", + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }, (err,result) => { + if (err !== undefined) { + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to switchCurrentInputMethodAndSubtype.(callback)'); + console.info('Succeeded in switching currentInputMethodAndSubtype.'); } else { - console.error('Failed to switchCurrentInputMethodAndSubtype.(callback)'); + console.error('Failed to switchCurrentInputMethodAndSubtype.'); } }); } catch (err) { - console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); } ``` @@ -415,7 +431,7 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp Switches to a specified subtype of a specified input method. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -439,39 +455,41 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js +let im = inputMethod.getCurrentInputMethod(); let inputMethodProperty = { - packageName: "com.example.kikakeyboard", - methodId: "ServiceExtAbility", - extra: {} -} -let inputMethodSubProperty = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, extra: {} } try { - inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty).then((result) => { + inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, { + id: im.packageName, + label: im.methodId, + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }).then((result) => { if (result) { - console.info('Success to switchCurrentInputMethodAndSubtype.'); + console.info('Succeeded in switching currentInputMethodAndSubtype.'); } else { console.error('Failed to switchCurrentInputMethodAndSubtype.'); } }).catch((err) => { - console.error('switchCurrentInputMethodAndSubtype err: ' + err); + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('switchCurrentInputMethodAndSubtype err: ' + err); + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); } ``` @@ -548,25 +566,25 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js try { inputMethodController.stopInputSession((error, result) => { - if (error) { - console.error('stopInputSession err: ' + JSON.stringify(error)); + if (error !== undefined) { + console.error('Failed to stopInputSession: ' + JSON.stringify(error)); return; } if (result) { - console.info('Success to stopInputSession.(callback)'); + console.info('Succeeded in stopping inputSession.'); } else { - console.error('Failed to stopInputSession.(callback)'); + console.error('Failed to stopInputSession.'); } }); } catch(error) { - console.error('stopInputSession err: ' + JSON.stringify(error)); + console.error('Failed to stopInputSession: ' + JSON.stringify(error)); } ``` @@ -591,7 +609,7 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** @@ -599,15 +617,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e try { inputMethodController.stopInputSession().then((result) => { if (result) { - console.info('Success to stopInputSession.'); + console.info('Succeeded in stopping inputSession.'); } else { console.error('Failed to stopInputSession.'); } }).catch((err) => { - console.error('stopInputSession err: ' + JSON.stringify(err)); + console.error('Failed to stopInputSession: ' + JSON.stringify(err)); }) } catch(err) { - console.error('stopInputSession err: ' + JSON.stringify(err)); + console.error('Failed to stopInputSession: ' + JSON.stringify(err)); } ``` @@ -617,7 +635,7 @@ showSoftKeyboard(callback: AsyncCallback<void>): void Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -634,16 +652,16 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js inputMethodController.showSoftKeyboard((err) => { if (err === undefined) { - console.info('showSoftKeyboard success'); + console.info('Succeeded in showing softKeyboard.'); } else { - console.error('showSoftKeyboard failed because : ' + JSON.stringify(err)); + console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); } }) ``` @@ -654,7 +672,7 @@ showSoftKeyboard(): Promise<void> Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -671,15 +689,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js -inputMethodController.showSoftKeyboard().then(async (err) => { - console.log('showSoftKeyboard success'); +inputMethodController.showSoftKeyboard().then(() => { + console.log('Succeeded in showing softKeyboard.'); }).catch((err) => { - console.error('showSoftKeyboard err: ' + JSON.stringify(err)); + console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); }); ``` @@ -689,7 +707,7 @@ hideSoftKeyboard(callback: AsyncCallback<void>): void Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -706,16 +724,16 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js inputMethodController.hideSoftKeyboard((err) => { if (err === undefined) { - console.info('hideSoftKeyboard success'); + console.info('Succeeded in hiding softKeyboard.'); } else { - console.error('hideSoftKeyboard failed because : ' + JSON.stringify(err)); + console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); } }) ``` @@ -726,7 +744,7 @@ hideSoftKeyboard(): Promise<void> Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -743,15 +761,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js -inputMethodController.hideSoftKeyboard().then(async (err) => { - console.log('hideSoftKeyboard success'); +inputMethodController.hideSoftKeyboard().then(() => { + console.log('Succeeded in hiding softKeyboard.'); }).catch((err) => { - console.error('hideSoftKeyboard err: ' + JSON.stringify(err)); + console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); }); ``` @@ -777,14 +795,14 @@ Ends this input session. The invoking of this API takes effect only after the in ```js inputMethodController.stopInput((error, result) => { - if (error) { - console.error('failed to stopInput because: ' + JSON.stringify(error)); + if (error !== undefined) { + console.error('Failed to stopInput: ' + JSON.stringify(error)); return; } if (result) { - console.info('Success to stopInput.(callback)'); + console.info('Succeeded in stopping input.'); } else { - console.error('Failed to stopInput.(callback)'); + console.error('Failed to stopInput.'); } }); ``` @@ -812,12 +830,12 @@ Ends this input session. The invoking of this API takes effect only after the in ```js inputMethodController.stopInput().then((result) => { if (result) { - console.info('Success to stopInput.'); + console.info('Succeeded in stopping input.'); } else { console.error('Failed to stopInput.'); } }).catch((err) => { - console.error('stopInput err: ' + err); + console.error('Failed to stopInput: ' + err); }) ``` @@ -891,26 +909,28 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js let inputMethodProperty = { - packageName:'com.example.kikakeyboard', - methodId:'com.example.kikakeyboard', + packageName: 'com.example.kikakeyboard', + methodId: 'com.example.kikakeyboard', + name: 'com.example.kikakeyboard', + id: 'com.example.kikakeyboard', extra:{} } try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => { - if (err) { - console.error('listInputMethodSubtype failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); return; } - console.log('listInputMethodSubtype success'); + console.log('Succeeded in listing inputMethodSubtype.'); }); } catch (err) { - console.error('listInputMethodSubtype failed: ' + JSON.stringify(err)); + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -941,24 +961,26 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js let inputMethodProperty = { - packageName:'com.example.kikakeyboard', - methodId:'com.example.kikakeyboard', + packageName: 'com.example.kikakeyboard', + methodId: 'com.example.kikakeyboard', + name: 'com.example.kikakeyboard', + id: 'com.example.kikakeyboard', extra:{} } try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { - console.info('listInputMethodSubtype success'); + console.info('Succeeded in listing inputMethodSubtype.'); }).catch((err) => { - console.error('listInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('listInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -983,21 +1005,21 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { - if (err) { - console.error('listCurrentInputMethodSubtype failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); return; } - console.log('listCurrentInputMethodSubtype success'); + console.log('Succeeded in listing currentInputMethodSubtype.'); }); } catch(err) { - console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -1022,19 +1044,19 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.listCurrentInputMethodSubtype().then((data) => { - console.info('listCurrentInputMethodSubtype success'); + console.info('Succeeded in listing currentInputMethodSubtype.'); }).catch((err) => { - console.error('listCurrentInputMethodSubtype err: ' + err); + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -1060,21 +1082,21 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.getInputMethods(true, (err,data) => { - if (err) { - console.error('getInputMethods failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); return; } - console.log('getInputMethods success'); + console.log('Succeeded in getting inputMethods.'); }); } catch (err) { - console.error('getInputMethods failed: ' + JSON.stringify(err)); + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); } ``` @@ -1099,7 +1121,7 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Return value** @@ -1112,12 +1134,12 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { inputMethodSetting.getInputMethods(true).then((data) => { - console.info('getInputMethods success'); + console.info('Succeeded in getting inputMethods.'); }).catch((err) => { - console.error('getInputMethods err: ' + JSON.stringify(err)); + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); }) } catch(err) { - console.error('getInputMethods err: ' + JSON.stringify(err)); + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); } ``` @@ -1127,7 +1149,7 @@ showOptionalInputMethods(callback: AsyncCallback<boolean>): void Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1143,21 +1165,21 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.showOptionalInputMethods((err, data) => { - if (err) { - console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); return; } - console.info('showOptionalInputMethods success'); + console.info('Succeeded in showing optionalInputMethods.'); }); } catch (err) { - console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); + console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); } ``` @@ -1167,7 +1189,7 @@ showOptionalInputMethods(): Promise<boolean> Displays a dialog box for selecting an input method. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1183,15 +1205,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js inputMethodSetting.showOptionalInputMethods().then((data) => { - console.info('displayOptionalInputMethod success.'); + console.info('Succeeded in showing optionalInputMethods.'); }).catch((err) => { - console.error('displayOptionalInputMethod err: ' + err); + console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); }) ``` @@ -1217,11 +1239,11 @@ Obtains a list of installed input methods. This API uses an asynchronous callbac ```js inputMethodSetting.listInputMethod((err,data) => { - if (err) { - console.error('listInputMethod failed because: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to listInputMethod: ' + JSON.stringify(err)); return; } - console.log('listInputMethod success'); + console.log('Succeeded in listing inputMethod.'); }); ``` @@ -1247,9 +1269,9 @@ Obtains a list of installed input methods. This API uses a promise to return the ```js inputMethodSetting.listInputMethod().then((data) => { - console.info('listInputMethod success'); + console.info('Succeeded in listing inputMethod.'); }).catch((err) => { - console.error('listInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to listInputMethod: ' + JSON.stringify(err)); }) ``` @@ -1275,11 +1297,11 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono ```js inputMethodSetting.displayOptionalInputMethod((err) => { - if (err) { - console.error('displayOptionalInputMethod failed because: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); return; } - console.info('displayOptionalInputMethod success'); + console.info('Succeeded in displaying optionalInputMethod.'); }); ``` @@ -1305,8 +1327,8 @@ Displays a dialog box for selecting an input method. This API uses a promise to ```js inputMethodSetting.displayOptionalInputMethod().then(() => { - console.info('displayOptionalInputMethod success'); + console.info('Succeeded in displaying optionalInputMethod.'); }).catch((err) => { - console.error('displayOptionalInputMethod err: ' + err); + console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); }) ``` diff --git a/en/application-dev/reference/apis/js-apis-inputmethodengine.md b/en/application-dev/reference/apis/js-apis-inputmethodengine.md index d0512b5904dc67fdde8d8c1f85c3b181cb771188..2c87f74698434a68279b5e1c627e2a7352819a38 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethodengine.md +++ b/en/application-dev/reference/apis/js-apis-inputmethodengine.md @@ -1,4 +1,4 @@ -# Input Method Engine +# @ohos.inputmethodengine The **inputMethodEngine** module streamlines the interaction between input methods and applications. By calling APIs of this module, applications can be bound to input method services to accept text input through the input methods, request the keyboard to display or hide, listen for the input method status, and much more. @@ -137,7 +137,7 @@ Obtains a **KeyboardDelegate** instance. **Example** ```js -let KeyboardDelegate = inputMethodEngine.createKeyboardDelegate(); +let keyboardDelegate = inputMethodEngine.createKeyboardDelegate(); ``` ## InputMethodEngine @@ -162,9 +162,9 @@ Enables listening for the input method binding event. This API uses an asynchron **Example** ```js -inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textInputClient) => { - KeyboardController = kbController; - TextInputClient = textInputClient; +inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => { + let keyboardController = kbController; + let textInputClient = textClient; }); ``` @@ -229,18 +229,14 @@ Disables listening for a keyboard event. This API uses an asynchronous callback | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
- The value **'keyboardShow'** indicates the keyboard display event.
- The value **'keyboardHide'** indicates the keyboard hiding event. | +| type | string | Yes | Listening type.
- The value **'keyboardShow'** indicates the keyboard display event.
- The value **'keyboardHide'** indicates the keyboard hiding event.| | callback | () => void | No | Callback used to return the result.| **Example** ```js -inputMethodEngine.getInputMethodEngine().off('keyboardShow', () => { - console.log('inputMethodEngine delete keyboardShow notification.'); -}); -inputMethodEngine.getInputMethodEngine().off('keyboardHide', () => { - console.log('inputMethodEngine delete keyboardHide notification.'); -}); +inputMethodEngine.getInputMethodEngine().off('keyboardShow'); +inputMethodEngine.getInputMethodEngine().off('keyboardHide'); ``` ## InputMethodAbility @@ -265,9 +261,9 @@ Enables listening for the input method binding event. This API uses an asynchron **Example** ```js -inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, inputClient) => { - KeyboardController = kbController; - InputClient = inputClient; +inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => { + let keyboardController = kbController; + let inputClient = client; }); ``` @@ -289,9 +285,7 @@ Cancels listening for the input method binding event. This API uses an asynchron **Example** ```js -inputMethodEngine.getInputMethodAbility().off('inputStart', (kbController, inputClient) => { - console.log('delete inputStart notification.'); -}); +inputMethodEngine.getInputMethodAbility().off('inputStart'); ``` ### on('inputStop')9+ @@ -390,7 +384,7 @@ inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => { on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void -Enables listening for an input method event. This API uses an asynchronous callback to return the result. +Enables listening for a keyboard event. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -398,7 +392,7 @@ Enables listening for an input method event. This API uses an asynchronous callb | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
- The value **'keyboardShow'** indicates the keyboard display event.
- The value **'keyboardHide'** indicates the keyboard hiding event. | +| type | string | Yes | Listening type.
- The value **'keyboardShow'** indicates the keyboard display event.
- The value **'keyboardHide'** indicates the keyboard hiding event.| | callback | () => void | Yes | Callback used to return the result. | **Example** @@ -416,7 +410,7 @@ inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => { off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void -Disables listening for an input method event. This API uses an asynchronous callback to return the result. +Disables listening for a keyboard event. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -602,14 +596,14 @@ Enables listening for the text selection change event. This API uses an asynchro **System capability**: SystemCapability.MiscServices.InputMethodFramework - **Parameters** +**Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type.
The value **'selectionChange'** indicates the text selection change event.| | callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | Yes | Callback used to return the text selection information.
- **oldBegin**: start of the selected text before the change.
- **oldEnd**: end of the selected text before the change.
- **newBegin**: start of the selected text after the change.
- **newEnd**: end of the selected text after the change.| - **Example** +**Example** ```js inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { @@ -652,14 +646,14 @@ Enables listening for the text change event. This API uses an asynchronous callb **System capability**: SystemCapability.MiscServices.InputMethodFramework - **Parameters** +**Parameters** | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type.
The value **'textChange'** indicates the text change event.| | callback | (text: string) => void | Yes | Callback used to return the text content. | - **Example** +**Example** ```js inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => { @@ -719,12 +713,12 @@ For details about the error codes, see [Input Method Framework Error Codes](../e **Example** ```js -KeyboardController.hide((err) => { - if (err === undefined) { - console.error('hide err: ' + JSON.stringify(err)); +keyboardController.hide((err) => { + if (err !== undefined) { + console.error('Failed to hide keyboard: ' + JSON.stringify(err)); return; } - console.log('hide success.'); + console.log('Succeeded in hiding keyboard.'); }); ``` @@ -753,10 +747,10 @@ For details about the error codes, see [Input Method Framework Error Codes](../e **Example** ```js -KeyboardController.hide().then(() => { - console.info('hide success.'); +keyboardController.hide().then(() => { + console.info('Succeeded in hiding keyboard.'); }).catch((err) => { - console.info('hide err: ' + JSON.stringify(err)); + console.info('Failed to hide keyboard: ' + JSON.stringify(err)); }); ``` @@ -781,12 +775,12 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. **Example** ```js -KeyboardController.hideKeyboard((err) => { - if (err === undefined) { - console.error('hideKeyboard err: ' + JSON.stringify(err)); +keyboardController.hideKeyboard((err) => { + if (err !== undefined) { + console.error('Failed to hide Keyboard: ' + JSON.stringify(err)); return; } - console.log('hideKeyboard success.'); + console.log('Succeeded in hiding keyboard.'); }); ``` @@ -811,10 +805,10 @@ Hides the keyboard. This API uses a promise to return the result. **Example** ```js -KeyboardController.hideKeyboard().then(() => { - console.info('hideKeyboard success.'); +keyboardController.hideKeyboard().then(() => { + console.info('Succeeded in hiding keyboard.'); }).catch((err) => { - console.info('hideKeyboard err: ' + JSON.stringify(err)); + console.info('Failed to hide Keyboard: ' + JSON.stringify(err)); }); ``` @@ -850,13 +844,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let action = 1; try { - InputClient.sendKeyFunction(action, (err, result) => { - if (err) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)); + inputClient.sendKeyFunction(action, (err, result) => { + if (err !== undefined) { + console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } @@ -899,17 +893,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let action = 1; try { - InputClient.sendKeyFunction(action).then((result) => { + inputClient.sendKeyFunction(action).then((result) => { if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } }).catch((err) => { - console.error('sendKeyFunction err:' + JSON.stringify(err)); + console.error('Failed to sendKeyFunction:' + JSON.stringify(err)); }); } catch (err) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)); + console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); } ``` @@ -942,15 +936,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.getForward(length, (err, text) => { - if (err) { - console.error('getForward err: ' + JSON.stringify(err)); + inputClient.getForward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getForward: ' + JSON.stringify(err)); return; } - console.log('getForward result: ' + text); + console.log('Succeeded in getting forward, text: ' + text); }); } catch (err) { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -988,13 +982,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.getForward(length).then((text) => { - console.info('getForward resul: ' + text); + inputClient.getForward(length).then((text) => { + console.info('Succeeded in getting forward, text: ' + text); }).catch((err) => { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); }); } catch (err) { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -1027,15 +1021,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.getBackward(length, (err, text) => { - if (err) { - console.error('getBackward result: ' + JSON.stringify(err)); + inputClient.getBackward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getForward: ' + JSON.stringify(err)); return; } - console.log('getBackward result---text: ' + text); + console.log('Succeeded in getting backward, text: ' + text); }); } catch (err) { - console.error('getBackward result: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -1073,13 +1067,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.getBackward(length).then((text) => { - console.info('getBackward result: ' + text); + inputClient.getBackward(length).then((text) => { + console.info('Succeeded in getting backward, text: ' + text); }).catch((err) => { - console.error('getBackward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); }); } catch (err) { - console.error('getBackward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -1112,19 +1106,19 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.deleteForward(length, (err, result) => { - if (err) { - console.error('deleteForward result: ' + JSON.stringify(err)); + inputClient.deleteForward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to delete forward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteForward. '); + console.info('Succeeded in deleting forward. '); } else { - console.error('Failed to deleteForward. '); + console.error('Failed to delete forward: ' + JSON.stringify(err)); } }); } catch (err) { - console.error('deleteForward result: ' + JSON.stringify(err)); + console.error('Failed to delete forward: ' + JSON.stringify(err)); } ``` @@ -1162,17 +1156,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.deleteForward(length).then((result) => { + inputClient.deleteForward(length).then((result) => { if (result) { - console.info('Success to deleteForward. '); + console.info('Succeeded in deleting forward. '); } else { - console.error('Failed to deleteForward. '); + console.error('Failed to delete Forward. '); } }).catch((err) => { - console.error('deleteForward err: ' + JSON.stringify(err)); + console.error('Failed to delete Forward: ' + JSON.stringify(err)); }); } catch (err) { - console.error('deleteForward err: ' + JSON.stringify(err)); + console.error('Failed to delete Forward: ' + JSON.stringify(err)); } ``` @@ -1205,15 +1199,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.deleteBackward(length, (err, result) => { - if (err) { - console.error('deleteBackward err: ' + JSON.stringify(err)); + inputClient.deleteBackward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to delete Backward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { - console.error('Failed to deleteBackward. '); + console.error('Failed to delete Backward: ' + JSON.stringify(err)); } }); } catch (err) { @@ -1254,14 +1248,14 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; -InputClient.deleteBackward(length).then((result) => { +inputClient.deleteBackward(length).then((result) => { if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { console.error('Failed to deleteBackward. '); } }).catch((err) => { - console.error('deleteBackward err: ' + JSON.stringify(err)); + console.error('Failed to deleteBackward: ' + JSON.stringify(err)); }); ``` @@ -1292,13 +1286,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e **Example** ```js -InputClient.insertText('test', (err, result) => { - if (err) { - console.error('insertText err: ' + JSON.stringify(err)); +inputClient.insertText('test', (err, result) => { + if (err !== undefined) { + console.error('Failed to insertText: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } @@ -1338,17 +1332,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - InputClient.insertText('test').then((result) => { + inputClient.insertText('test').then((result) => { if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } }).catch((err) => { - console.error('insertText err: ' + JSON.stringify(err)); + console.error('Failed to insertText: ' + JSON.stringify(err)); }); } catch (err) { - console.error('insertText err: ' + JSON.stringify(err)); + console.error('Failed to insertText: ' + JSON.stringify(err)); } ``` @@ -1377,9 +1371,9 @@ For details about the error codes, see [Input Method Framework Error Codes](../e **Example** ```js -InputClient.getEditorAttribute((err, editorAttribute) => { - if (err) { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); +inputClient.getEditorAttribute((err, editorAttribute) => { + if (err !== undefined) { + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); return; } console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); @@ -1412,11 +1406,11 @@ For details about the error codes, see [Input Method Framework Error Codes](../e **Example** ```js -InputClient.getEditorAttribute().then((editorAttribute) => { +inputClient.getEditorAttribute().then((editorAttribute) => { console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }).catch((err) => { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); }); ``` @@ -1447,15 +1441,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - InputClient.moveCursor(inputMethodEngine.CURSOR_xxx, (err) => { - if (err) { - console.error('moveCursor err: ' + JSON.stringify(err)); + inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => { + if (err !== undefined) { + console.error('Failed to moveCursor: ' + JSON.stringify(err)); return; } - console.info('moveCursor success'); + console.info('Succeeded in moving cursor.'); }); } catch (err) { - console.error('moveCursor err: ' + JSON.stringify(err)); + console.error('Failed to moveCursor: ' + JSON.stringify(err)); } ``` @@ -1491,13 +1485,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - InputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { - console.log('moveCursor success'); + inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { + console.log('Succeeded in moving cursor.'); }).catch((err) => { - console.error('moveCursor success err: ' + JSON.stringify(err)); + console.error('Failed to moveCursor: ' + JSON.stringify(err)); }); } catch (err) { - console.log('moveCursor err: ' + JSON.stringify(err)); + console.log('Failed to moveCursor: ' + JSON.stringify(err)); } ``` @@ -1554,12 +1548,12 @@ Obtains the specific-length text before the cursor. This API uses an asynchronou ```js let length = 1; -TextInputClient.getForward(length, (err, text) => { - if (err === undefined) { - console.error('getForward err: ' + JSON.stringify(err)); +textInputClient.getForward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getForward: ' + JSON.stringify(err)); return; } - console.log('getForward result---text: ' + text); + console.log('Succeeded in getting forward, text: ' + text); }); ``` @@ -1591,10 +1585,10 @@ Obtains the specific-length text before the cursor. This API uses a promise to r ```js let length = 1; -TextInputClient.getForward(length).then((text) => { - console.info('getForward result: ' + JSON.stringify(text)); +textInputClient.getForward(length).then((text) => { + console.info('Succeeded in getting forward, text: ' + text); }).catch((err) => { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); }); ``` @@ -1621,12 +1615,12 @@ Obtains the specific-length text after the cursor. This API uses an asynchronous ```js let length = 1; -TextInputClient.getBackward(length, (err, text) => { - if (err === undefined) { - console.error('getBackward err: ' + JSON.stringify(err)); +textInputClient.getBackward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getBackward: ' + JSON.stringify(err)); return; } - console.log('getBackward result---text: ' + text); + console.log('Succeeded in getting borward, text: ' + text); }); ``` @@ -1658,10 +1652,10 @@ Obtains the specific-length text after the cursor. This API uses a promise to re ```js let length = 1; -TextInputClient.getBackward(length).then((text) => { - console.info('getBackward result: ' + JSON.stringify(text)); +textInputClient.getBackward(length).then((text) => { + console.info('Succeeded in getting backward: ' + JSON.stringify(text)); }).catch((err) => { - console.error('getBackward err: ' + JSON.stringify(err)); + console.error('Failed to getBackward: ' + JSON.stringify(err)); }); ``` @@ -1688,13 +1682,13 @@ Deletes the fixed-length text before the cursor. This API uses an asynchronous c ```js let length = 1; -TextInputClient.deleteForward(length, (err, result) => { - if (err === undefined) { - console.error('deleteForward err: ' + JSON.stringify(err)); +textInputClient.deleteForward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to deleteForward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteForward. '); + console.info('Succeeded in deleting forward. '); } else { console.error('Failed to deleteForward. '); } @@ -1729,14 +1723,14 @@ Deletes the fixed-length text before the cursor. This API uses a promise to retu ```js let length = 1; -TextInputClient.deleteForward(length).then((result) => { +textInputClient.deleteForward(length).then((result) => { if (result) { - console.info('Succeed in deleting forward. '); + console.info('Succeeded in deleting forward. '); } else { console.error('Failed to delete forward. '); } }).catch((err) => { - console.error('Failed to delete forward err: ' + JSON.stringify(err)); + console.error('Failed to delete forward: ' + JSON.stringify(err)); }); ``` @@ -1763,13 +1757,13 @@ Deletes the fixed-length text after the cursor. This API uses an asynchronous ca ```js let length = 1; -TextInputClient.deleteBackward(length, (err, result) => { - if (err === undefined) { - console.error('deleteBackward err: ' + JSON.stringify(err)); +textInputClient.deleteBackward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to delete backward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { console.error('Failed to deleteBackward. '); } @@ -1804,14 +1798,14 @@ Deletes the fixed-length text after the cursor. This API uses an asynchronous ca ```js let length = 1; -TextInputClient.deleteBackward(length).then((result) => { +textInputClient.deleteBackward(length).then((result) => { if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { console.error('Failed to deleteBackward. '); } }).catch((err) => { - console.error('deleteBackward err: ' + JSON.stringify(err)); + console.error('Failed to deleteBackward: ' + JSON.stringify(err)); }); ``` ### sendKeyFunction(deprecated) @@ -1837,13 +1831,13 @@ Sends the function key. This API uses an asynchronous callback to return the res ```js let action = 1; -TextInputClient.sendKeyFunction(action, (err, result) => { - if (err === undefined) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)); +textInputClient.sendKeyFunction(action, (err, result) => { + if (err !== undefined) { + console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } @@ -1878,14 +1872,14 @@ Sends the function key. This API uses a promise to return the result. ```js let action = 1; -TextInputClient.sendKeyFunction(action).then((result) => { +textInputClient.sendKeyFunction(action).then((result) => { if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } }).catch((err) => { - console.error('sendKeyFunction err:' + JSON.stringify(err)); + console.error('Failed to sendKeyFunction:' + JSON.stringify(err)); }); ``` @@ -1911,13 +1905,13 @@ Inserts text. This API uses an asynchronous callback to return the result. **Example** ```js -TextInputClient.insertText('test', (err, result) => { - if (err === undefined) { - console.error('insertText err: ' + JSON.stringify(err)); +textInputClient.insertText('test', (err, result) => { + if (err !== undefined) { + console.error('Failed to insertText: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } @@ -1951,14 +1945,14 @@ Inserts text. This API uses a promise to return the result. **Example** ```js -TextInputClient.insertText('test').then((result) => { +textInputClient.insertText('test').then((result) => { if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } }).catch((err) => { - console.error('insertText err: ' + JSON.stringify(err)); + console.error('Failed to insertText: ' + JSON.stringify(err)); }); ``` @@ -1983,9 +1977,9 @@ Obtains the attribute of the edit box. This API uses an asynchronous callback to **Example** ```js -TextInputClient.getEditorAttribute((err, editorAttribute) => { - if (err === undefined) { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); +textInputClient.getEditorAttribute((err, editorAttribute) => { + if (err !== undefined) { + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); return; } console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); @@ -2014,10 +2008,10 @@ Obtains the attribute of the edit box. This API uses a promise to return the res **Example** ```js -TextInputClient.getEditorAttribute().then((editorAttribute) => { +textInputClient.getEditorAttribute().then((editorAttribute) => { console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }).catch((err) => { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-intl.md b/en/application-dev/reference/apis/js-apis-intl.md index 79cdf3ac5627984eba2f03e7eb37b9cc7137de4a..e3cb7bbfd684ae315d6d54363183401442f5167a 100644 --- a/en/application-dev/reference/apis/js-apis-intl.md +++ b/en/application-dev/reference/apis/js-apis-intl.md @@ -1,6 +1,6 @@ # Internationalization – Intl -This module provides basic I18N capabilities, such as time and date formatting, number formatting, and string sorting, through the standard I18N APIs defined in ECMA 402. +The Intl module provides basic I18N capabilities, such as time and date formatting, number formatting, and string sorting, through the standard I18N APIs defined in ECMA 402. The [I18N](js-apis-i18n.md) module provides enhanced I18N capabilities through supplementary APIs that are not defined in ECMA 402. It works with the Intl module to provide a complete suite of I18N capabilities. diff --git a/en/application-dev/reference/apis/js-apis-keycode.md b/en/application-dev/reference/apis/js-apis-keycode.md index 4fe73f6707d870e8089c6ec9e981ffc267448173..6f5ff70edc6cdcbb7fcc3a5ce90432eaaf6b312c 100644 --- a/en/application-dev/reference/apis/js-apis-keycode.md +++ b/en/application-dev/reference/apis/js-apis-keycode.md @@ -2,7 +2,8 @@ The **keyCode** module provides keycodes for a key device. -> **NOTE**
+> **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 @@ -15,335 +16,335 @@ import {KeyCode} from '@ohos.multimodalInput.keyCode'; **System capability**: SystemCapability.MultimodalInput.Input.Core -| Name| Type| Readable| Writable| Description| -| -------- | -------- | -------- | -------- | -------- | -| KEYCODE_FN | number | Yes| No| Function (Fn) key| -| KEYCODE_UNKNOWN | number | Yes| No| Unknown key| -| KEYCODE_HOME | number | Yes| No| Home key | -| KEYCODE_BACK | number | Yes| No| Back key| -| KEYCODE_MEDIA_PLAY_PAUSE | number | Yes| No| Play/Pause key| -| KEYCODE_MEDIA_STOP | number | Yes| No| Stop key| -| KEYCODE_MEDIA_NEXT | number | Yes| No| Next key| -| KEYCODE_MEDIA_PREVIOUS | number | Yes| No| Previous key| -| KEYCODE_MEDIA_REWIND | number | Yes| No| Rewind key| -| KEYCODE_MEDIA_FAST_FORWARD | number | Yes| No| Fast Forward key| -| KEYCODE_VOLUME_UP | number | Yes| No| Volume Up key| -| KEYCODE_VOLUME_DOWN | number | Yes| No| Volume Down key| -| KEYCODE_POWER | number | Yes| No| Power key| -| KEYCODE_CAMERA | number | Yes| No| Camera key| -| KEYCODE_VOLUME_MUTE | number | Yes| No| Speaker Mute key| -| KEYCODE_MUTE | number | Yes| No| Mute key| -| KEYCODE_BRIGHTNESS_UP | number | Yes| No| Brightness Up key| -| KEYCODE_BRIGHTNESS_DOWN | number | Yes| No| Brightness Down key| -| KEYCODE_0 | number | Yes| No| Key 0| -| KEYCODE_1 | number | Yes| No| Key 1| -| KEYCODE_2 | number | Yes| No| Key 2| -| KEYCODE_3 | number | Yes| No| Key 3| -| KEYCODE_4 | number | Yes| No| Key 4| -| KEYCODE_5 | number | Yes| No| Key 5| -| KEYCODE_6 | number | Yes| No| Key 6| -| KEYCODE_7 | number | Yes| No| Key 7| -| KEYCODE_8 | number | Yes| No| Key 8| -| KEYCODE_9 | number | Yes| No| Key 9| -| KEYCODE_STAR | number | Yes| No| Key *| -| KEYCODE_POUND | number | Yes| No| Key #| -| KEYCODE_DPAD_UP | number | Yes| No| Up key on D-pad| -| KEYCODE_DPAD_DOWN | number | Yes| No| Down key on D-pad| -| KEYCODE_DPAD_LEFT | number | Yes| No| Left key on D-pad| -| KEYCODE_DPAD_RIGHT | number | Yes| No| Right key on D-pad| -| KEYCODE_DPAD_CENTER | number | Yes| No| Center key on D-pad| -| KEYCODE_A | number | Yes| No| Key A| -| KEYCODE_B | number | Yes| No| Key B| -| KEYCODE_C | number | Yes| No| Key C| -| KEYCODE_D | number | Yes| No| Key D| -| KEYCODE_E | number | Yes| No| Key E| -| KEYCODE_F | number | Yes| No| Key F| -| KEYCODE_G | number | Yes| No| Key G| -| KEYCODE_H | number | Yes| No| Key H| -| KEYCODE_I | number | Yes| No| Key I| -| KEYCODE_J | number | Yes| No| Key J| -| KEYCODE_K | number | Yes| No| Key K| -| KEYCODE_L | number | Yes| No| Key L| -| KEYCODE_M | number | Yes| No| Key M| -| KEYCODE_N | number | Yes| No| Key N| -| KEYCODE_O | number | Yes| No| Key O| -| KEYCODE_P | number | Yes| No| Key P| -| KEYCODE_Q | number | Yes| No| Key Q| -| KEYCODE_R | number | Yes| No| Key R| -| KEYCODE_S | number | Yes| No| Key S| -| KEYCODE_T | number | Yes| No| Key T| -| KEYCODE_U | number | Yes| No| Key U| -| KEYCODE_V | number | Yes| No| Key V| -| KEYCODE_W | number | Yes| No| Key W| -| KEYCODE_X | number | Yes| No| Key X| -| KEYCODE_Y | number | Yes| No| Key Y| -| KEYCODE_Z | number | Yes| No| Key Z| -| KEYCODE_COMMA | number | Yes| No| Key ,| -| KEYCODE_PERIOD | number | Yes| No| Key .| -| KEYCODE_ALT_LEFT | number | Yes| No| Alt+Left key| -| KEYCODE_ALT_RIGHT | number | Yes| No| Alt+Right key| -| KEYCODE_SHIFT_LEFT | number | Yes| No| Shift+Left key| -| KEYCODE_SHIFT_RIGHT | number | Yes| No| Shift+Right key| -| KEYCODE_TAB | number | Yes| No| Tab key| -| KEYCODE_SPACE | number | Yes| No| Space key| -| KEYCODE_SYM | number | Yes| No| Symbol key| -| KEYCODE_EXPLORER | number | Yes| No| Explorer key, which is used to start the explorer application| -| KEYCODE_ENVELOPE | number | Yes| No| Email key, which is used to start the email application| -| KEYCODE_ENTER | number | Yes| No| Enter key| -| KEYCODE_DEL | number | Yes| No| Delete key| -| KEYCODE_GRAVE | number | Yes| No| Key `| -| KEYCODE_MINUS | number | Yes| No| Key -| -| KEYCODE_EQUALS | number | Yes| No| Key =| -| KEYCODE_LEFT_BRACKET | number | Yes| No| Key [| -| KEYCODE_RIGHT_BRACKET | number | Yes| No| Key ]| -| KEYCODE_BACKSLASH | number | Yes| No| Key \\| -| KEYCODE_SEMICOLON | number | Yes| No| Key ;| -| KEYCODE_APOSTROPHE | number | Yes| No| Key ' | -| KEYCODE_SLASH | number | Yes| No| Key /| -| KEYCODE_AT | number | Yes| No| Key @| -| KEYCODE_PLUS | number | Yes| No| Key +| -| KEYCODE_MENU | number | Yes| No| Menu key| -| KEYCODE_PAGE_UP | number | Yes| No| Page Up key| -| KEYCODE_PAGE_DOWN | number | Yes| No| Page Down key| -| KEYCODE_ESCAPE | number | Yes| No| ESC key| -| KEYCODE_FORWARD_DEL | number | Yes| No| Delete key| -| KEYCODE_CTRL_LEFT | number | Yes| No| Control+Left | -| KEYCODE_CTRL_RIGHT | number | Yes| No| Control+Right | -| KEYCODE_CAPS_LOCK | number | Yes| No| Caps Lock key| -| KEYCODE_SCROLL_LOCK | number | Yes| No| Scroll Lock key| -| KEYCODE_META_LEFT | number | Yes| No| Left Meta key| -| KEYCODE_META_RIGHT | number | Yes| No| Right Meta key| -| KEYCODE_FUNCTION | number | Yes| No| Function key| -| KEYCODE_SYSRQ | number | Yes| No| System Request/Print Screen key| -| KEYCODE_BREAK | number | Yes| No| Break/Pause key| -| KEYCODE_MOVE_HOME | number | Yes| No| Move to Home key| -| KEYCODE_MOVE_END | number | Yes| No| Move to End key| -| KEYCODE_INSERT | number | Yes| No| Insert key| -| KEYCODE_FORWARD | number | Yes| No| Delete key | -| KEYCODE_MEDIA_PLAY | number | Yes| No| Play key| -| KEYCODE_MEDIA_PAUSE | number | Yes| No| Pause key| -| KEYCODE_MEDIA_CLOSE | number | Yes| No| Close key| -| KEYCODE_MEDIA_EJECT | number | Yes| No| Eject key| -| KEYCODE_MEDIA_RECORD | number | Yes| No| Record key| -| KEYCODE_F1 | number | Yes| No| F1 key| -| KEYCODE_F2 | number | Yes| No| F2 key| -| KEYCODE_F3 | number | Yes| No| F3 key| -| KEYCODE_F4 | number | Yes| No| F4 key| -| KEYCODE_F5 | number | Yes| No| F5 key| -| KEYCODE_F6 | number | Yes| No| F6 key| -| KEYCODE_F7 | number | Yes| No| F7 key| -| KEYCODE_F8 | number | Yes| No| F8 key| -| KEYCODE_F9 | number | Yes| No| F9 key| -| KEYCODE_F10 | number | Yes| No| F10 key| -| KEYCODE_F11 | number | Yes| No| F11 key| -| KEYCODE_F12 | number | Yes| No| F12 key| -| KEYCODE_NUM_LOCK | number | Yes| No| Number Lock key| -| KEYCODE_NUMPAD_0 | number | Yes| No| Key 0 on numeric keypad| -| KEYCODE_NUMPAD_1 | number | Yes| No| Key 1 on numeric keypad| -| KEYCODE_NUMPAD_2 | number | Yes| No| Key 2 on numeric keypad| -| KEYCODE_NUMPAD_3 | number | Yes| No| Key 3 on numeric keypad| -| KEYCODE_NUMPAD_4 | number | Yes| No| Key 4 on numeric keypad| -| KEYCODE_NUMPAD_5 | number | Yes| No| Key 5 on numeric keypad| -| KEYCODE_NUMPAD_6 | number | Yes| No| Key 6 on numeric keypad| -| KEYCODE_NUMPAD_7 | number | Yes| No| Key 7 on numeric keypad| -| KEYCODE_NUMPAD_8 | number | Yes| No| Key 8 on numeric keypad| -| KEYCODE_NUMPAD_9 | number | Yes| No| Key 9 on numeric keypad| -| KEYCODE_NUMPAD_DIVIDE | number | Yes| No| Key / on numeric keypad| -| KEYCODE_NUMPAD_MULTIPLY | number | Yes| No| Key * on numeric keypad| -| KEYCODE_NUMPAD_SUBTRACT | number | Yes| No| Key - on numeric keypad| -| KEYCODE_NUMPAD_ADD | number | Yes| No| Key + on numeric keypad| -| KEYCODE_NUMPAD_DOT | number | Yes| No| Key . on numeric keypad| -| KEYCODE_NUMPAD_COMMA | number | Yes| No| Key , on numeric keypad| -| KEYCODE_NUMPAD_ENTER | number | Yes| No| Enter key on numeric keypad| -| KEYCODE_NUMPAD_EQUALS | number | Yes| No| Key = on numeric keypad| -| KEYCODE_NUMPAD_LEFT_PAREN | number | Yes| No| Key ( on numeric keypad| -| KEYCODE_NUMPAD_RIGHT_PAREN | number | Yes| No| Key ) on numeric keypad| -| KEYCODE_VIRTUAL_MULTITASK | number | Yes| No| Multi-task key| -| KEYCODE_SLEEP | number | Yes| No| Sleep key| -| KEYCODE_ZENKAKU_HANKAKU | number | Yes| No| Zenkaku/Hankaku key| -| KEYCODE_102ND | number | Yes| No| 102nd key| -| KEYCODE_RO | number | Yes| No| Ro key| -| KEYCODE_KATAKANA | number | Yes| No| Katakana key| -| KEYCODE_HIRAGANA | number | Yes| No| Hiragana key| -| KEYCODE_HENKAN | number | Yes| No| Henkan key| -| KEYCODE_KATAKANA_HIRAGANA | number | Yes| No| Katakana/Hiragana key| -| KEYCODE_MUHENKAN | number | Yes| No| Muhenkan key| -| KEYCODE_LINEFEED | number | Yes| No| Linefeed key| -| KEYCODE_MACRO | number | Yes| No| Macro key| -| KEYCODE_NUMPAD_PLUSMINUS | number | Yes| No| Plus/Minus key on the numeric keypad| -| KEYCODE_SCALE | number | Yes| No| Scale key| -| KEYCODE_HANGUEL | number | Yes| No| Hanguel key| -| KEYCODE_HANJA | number | Yes| No| Hanja key| -| KEYCODE_YEN | number | Yes| No| Yen key| -| KEYCODE_STOP | number | Yes| No| Stop key| -| KEYCODE_AGAIN | number | Yes| No| Again key| -| KEYCODE_PROPS | number | Yes| No| Props key| -| KEYCODE_UNDO | number | Yes| No| Undo key| -| KEYCODE_COPY | number | Yes| No| Copy key| -| KEYCODE_OPEN | number | Yes| No| Open key| -| KEYCODE_PASTE | number | Yes| No| Paste key| -| KEYCODE_FIND | number | Yes| No| Find key| -| KEYCODE_CUT | number | Yes| No| Cut key| -| KEYCODE_HELP | number | Yes| No| Help key| -| KEYCODE_CALC | number | Yes| No| Calc key, which is used to start the calculator application| -| KEYCODE_FILE | number | Yes| No| File key| -| KEYCODE_BOOKMARKS | number | Yes| No| Bookmarks key| -| KEYCODE_NEXT | number | Yes| No| Next key| -| KEYCODE_PLAYPAUSE | number | Yes| No| Play/Pause key| -| KEYCODE_PREVIOUS | number | Yes| No| Previous key| -| KEYCODE_STOPCD | number | Yes| No| Stop CD key| -| KEYCODE_CONFIG | number | Yes| No| Config key| -| KEYCODE_REFRESH | number | Yes| No| Refresh key| -| KEYCODE_EXIT | number | Yes| No| Exit key| -| KEYCODE_EDIT | number | Yes| No| Edit key| -| KEYCODE_SCROLLUP | number | Yes| No| Scroll Up key| -| KEYCODE_SCROLLDOWN | number | Yes| No| Scroll Down key| -| KEYCODE_NEW | number | Yes| No| New key| -| KEYCODE_REDO | number | Yes| No| Redo key| -| KEYCODE_CLOSE | number | Yes| No| Close key| -| KEYCODE_PLAY | number | Yes| No| Play key| -| KEYCODE_BASSBOOST | number | Yes| No| Bass Boost key| -| KEYCODE_PRINT | number | Yes| No| Print key| -| KEYCODE_CHAT | number | Yes| No| Chat key| -| KEYCODE_FINANCE | number | Yes| No| Finance key| -| KEYCODE_CANCEL | number | Yes| No| Cancel key| -| KEYCODE_KBDILLUM_TOGGLE | number | Yes| No| Keyboard Illumination Toggle key| -| KEYCODE_KBDILLUM_DOWN | number | Yes| No| Keyboard Illumination Up key| -| KEYCODE_KBDILLUM_UP | number | Yes| No| Keyboard Illumination Down key| -| KEYCODE_SEND | number | Yes| No| Send key| -| KEYCODE_REPLY | number | Yes| No| Reply key| -| KEYCODE_FORWARDMAIL | number | Yes| No| Forward Mail key| -| KEYCODE_SAVE | number | Yes| No| Save key| -| KEYCODE_DOCUMENTS | number | Yes| No| Documents key| -| KEYCODE_VIDEO_NEXT | number | Yes| No| Next Video key| -| KEYCODE_VIDEO_PREV | number | Yes| No| Previous Video key| -| KEYCODE_BRIGHTNESS_CYCLE | number | Yes| No| Brightness Cycle key| -| KEYCODE_BRIGHTNESS_ZERO | number | Yes| No| Brightness Zero key| -| KEYCODE_DISPLAY_OFF | number | Yes| No| Display Off Key| -| KEYCODE_BTN_MISC | number | Yes| No| Misc Button key| -| KEYCODE_GOTO | number | Yes| No| Goto key| -| KEYCODE_INFO | number | Yes| No| Info key| -| KEYCODE_PROGRAM | number | Yes| No| Program key| -| KEYCODE_PVR | number | Yes| No| PVR key| -| KEYCODE_SUBTITLE | number | Yes| No| Subtitle key| -| KEYCODE_FULL_SCREEN | number | Yes| No| Full Screen key| -| KEYCODE_KEYBOARD | number | Yes| No| Keyboard| -| KEYCODE_ASPECT_RATIO | number | Yes| No| Aspect Ratio key| -| KEYCODE_PC | number | Yes| No| Port Control key| -| KEYCODE_TV | number | Yes| No| TV key| -| KEYCODE_TV2 | number | Yes| No| TV key 2| -| KEYCODE_VCR | number | Yes| No| VCR key| -| KEYCODE_VCR2 | number | Yes| No| VCR key 2| -| KEYCODE_SAT | number | Yes| No| SAT key| -| KEYCODE_CD | number | Yes| No| CD key| -| KEYCODE_TAPE | number | Yes| No| Tape key| -| KEYCODE_TUNER | number | Yes| No| Tuner key| -| KEYCODE_PLAYER | number | Yes| No| Player key| -| KEYCODE_DVD | number | Yes| No| DVD key| -| KEYCODE_AUDIO | number | Yes| No| Audio key| -| KEYCODE_VIDEO | number | Yes| No| Video key| -| KEYCODE_MEMO | number | Yes| No| Memo key| -| KEYCODE_CALENDAR | number | Yes| No| Calendar key| -| KEYCODE_RED | number | Yes| No| Red indicator| -| KEYCODE_GREEN | number | Yes| No| Green indicator| -| KEYCODE_YELLOW | number | Yes| No| Yellow indicator| -| KEYCODE_BLUE | number | Yes| No| Blue indicator| -| KEYCODE_CHANNELUP | number | Yes| No| Channel Up key| -| KEYCODE_CHANNELDOWN | number | Yes| No| Channel Down key| -| KEYCODE_LAST | number | Yes| No| Last key| -| KEYCODE_RESTART | number | Yes| No| Restart key| -| KEYCODE_SLOW | number | Yes| No| Slow key| -| KEYCODE_SHUFFLE | number | Yes| No| Shuffle key| -| KEYCODE_VIDEOPHONE | number | Yes| No| Videophone key| -| KEYCODE_GAMES | number | Yes| No| Games key| -| KEYCODE_ZOOMIN | number | Yes| No| Zoom-in key| -| KEYCODE_ZOOMOUT | number | Yes| No| Zoom-out key| -| KEYCODE_ZOOMRESET | number | Yes| No| Zoom Reset key| -| KEYCODE_WORDPROCESSOR | number | Yes| No| Word Processor key| -| KEYCODE_EDITOR | number | Yes| No| Editor key| -| KEYCODE_SPREADSHEET | number | Yes| No| Spreadsheet key| -| KEYCODE_GRAPHICSEDITOR | number | Yes| No| Graphics Editor key| -| KEYCODE_PRESENTATION | number | Yes| No| Presentation key| -| KEYCODE_DATABASE | number | Yes| No| Database key| -| KEYCODE_NEWS | number | Yes| No| News key| -| KEYCODE_VOICEMAIL | number | Yes| No| Voicemail key| -| KEYCODE_ADDRESSBOOK | number | Yes| No| Addressbook key| -| KEYCODE_MESSENGER | number | Yes| No| Messenger key| -| KEYCODE_BRIGHTNESS_TOGGLE | number | Yes| No| Brightness Toggle key| -| KEYCODE_SPELLCHECK | number | Yes| No| Spell Check key| -| KEYCODE_COFFEE | number | Yes| No| Coffee key, which is used to launch screen lock or screen saver| -| KEYCODE_MEDIA_REPEAT | number | Yes| No| Media Repeat key| -| KEYCODE_IMAGES | number | Yes| No| Images key| -| KEYCODE_BUTTONCONFIG | number | Yes| No| Button Configuration key| -| KEYCODE_TASKMANAGER | number | Yes| No| Task Manager key| -| KEYCODE_JOURNAL | number | Yes| No| Log key| -| KEYCODE_CONTROLPANEL | number | Yes| No| Control Panel key| -| KEYCODE_APPSELECT | number | Yes| No| App Select key| -| KEYCODE_SCREENSAVER | number | Yes| No| Screen Saver key| -| KEYCODE_ASSISTANT | number | Yes| No| Assistant key| -| KEYCODE_KBD_LAYOUT_NEXT | number | Yes| No| Next Keyboard Layout key| -| KEYCODE_BRIGHTNESS_MIN | number | Yes| No| Min Brightness key| -| KEYCODE_BRIGHTNESS_MAX | number | Yes| No| Max Brightness key| -| KEYCODE_KBDINPUTASSIST_PREV | number | Yes| No| Keyboard Input-assisted Previous key| -| KEYCODE_KBDINPUTASSIST_NEXT | number | Yes| No| Keyboard Input-assisted Next key| -| KEYCODE_KBDINPUTASSIST_PREVGROUP | number | Yes| No| Keyboard Input-assisted Previous Group key| -| KEYCODE_KBDINPUTASSIST_NEXTGROUP | number | Yes| No| Keyboard Input-assisted Next Group key| -| KEYCODE_KBDINPUTASSIST_ACCEPT | number | Yes| No| Keyboard Input-assisted Accept key| -| KEYCODE_KBDINPUTASSIST_CANCEL | number | Yes| No| Keyboard Input-assisted Cancel key| -| KEYCODE_FRONT | number | Yes| No| Front key, which is used to launch the windshield defogger| -| KEYCODE_SETUP | number | Yes| No| Setup key| -| KEYCODE_WAKEUP | number | Yes| No| Wakeup key| -| KEYCODE_SENDFILE | number | Yes| No| Send File key| -| KEYCODE_DELETEFILE | number | Yes| No| Delete File key| -| KEYCODE_XFER | number | Yes| No| XFER key, which is used to start file transfer| -| KEYCODE_PROG1 | number | Yes| No| Program key 1| -| KEYCODE_PROG2 | number | Yes| No| Program key 2| -| KEYCODE_MSDOS | number | Yes| No| MS-DOS key| -| KEYCODE_SCREENLOCK | number | Yes| No| Screen Lock key| -| KEYCODE_DIRECTION_ROTATE_DISPLAY | number | Yes| No| Directional Rotation Display key| -| KEYCODE_CYCLEWINDOWS | number | Yes| No| Windows Cycle key| -| KEYCODE_COMPUTER | number | Yes| No| Key | -| KEYCODE_EJECTCLOSECD | number | Yes| No| Eject CD key| -| KEYCODE_ISO | number | Yes| No| ISO key| -| KEYCODE_MOVE | number | Yes| No| Move key| -| KEYCODE_F13 | number | Yes| No| F13 key| -| KEYCODE_F14 | number | Yes| No| F14 key| -| KEYCODE_F15 | number | Yes| No| F15 key| -| KEYCODE_F16 | number | Yes| No| F16 key| -| KEYCODE_F17 | number | Yes| No| F17 key| -| KEYCODE_F18 | number | Yes| No| F18 key| -| KEYCODE_F19 | number | Yes| No| F19 key| -| KEYCODE_F20 | number | Yes| No| F20 key| -| KEYCODE_F21 | number | Yes| No| F21 key| -| KEYCODE_F22 | number | Yes| No| F22 key| -| KEYCODE_F23 | number | Yes| No| F23 key| -| KEYCODE_F24 | number | Yes| No| F24 key| -| KEYCODE_PROG3 | number | Yes| No| Program key 3| -| KEYCODE_PROG4 | number | Yes| No| Program key 4| -| KEYCODE_DASHBOARD | number | Yes| No| Dashboard| -| KEYCODE_SUSPEND | number | Yes| No| Suspend key| -| KEYCODE_HP | number | Yes| No| HP key| -| KEYCODE_SOUND | number | Yes| No| Sound key| -| KEYCODE_QUESTION | number | Yes| No| Question key| -| KEYCODE_CONNECT | number | Yes| No| Connect key| -| KEYCODE_SPORT | number | Yes| No| Sport key| -| KEYCODE_SHOP | number | Yes| No| Shop key| -| KEYCODE_ALTERASE | number | Yes| No| Alternate key| -| KEYCODE_SWITCHVIDEOMODE | number | Yes| No| Switch Video Mode key (monitor, LCD, and TV, etc.)| -| KEYCODE_BATTERY | number | Yes| No| Battery key| -| KEYCODE_BLUETOOTH | number | Yes| No| Bluetooth key| -| KEYCODE_WLAN | number | Yes| No| WLAN key| -| KEYCODE_UWB | number | Yes| No| Ultra-wideband key| -| KEYCODE_WWAN_WIMAX | number | Yes| No| WWAN WiMAX key| -| KEYCODE_RFKILL | number | Yes| No| RF Kill key| -| KEYCODE_CHANNEL | number | Yes| No| Channel key| -| KEYCODE_BTN_0 | number | Yes| No| Key 0| -| KEYCODE_BTN_1 | number | Yes| No| Button 1| -| KEYCODE_BTN_2 | number | Yes| No| Button 2| -| KEYCODE_BTN_3 | number | Yes| No| Button 3| -| KEYCODE_BTN_4 | number | Yes| No| Button 4| -| KEYCODE_BTN_5 | number | Yes| No| Button 5| -| KEYCODE_BTN_6 | number | Yes| No| Button 6| -| KEYCODE_BTN_7 | number | Yes| No| Button 7| -| KEYCODE_BTN_8 | number | Yes| No| Button 8| -| KEYCODE_BTN_9 | number | Yes| No| Button 9| +| Name | Value | Description | +| -------------------------------- | ------ | --------------------------- | +| KEYCODE_FN | 0 | Function (Fn) key | +| KEYCODE_UNKNOWN | -1 | Unknown key | +| KEYCODE_HOME | 1 | Function (Home) key | +| KEYCODE_BACK | 2 | Back key | +| KEYCODE_MEDIA_PLAY_PAUSE | 10 | Play/Pause key | +| KEYCODE_MEDIA_STOP | 11 | Stop key | +| KEYCODE_MEDIA_NEXT | 12 | Next key | +| KEYCODE_MEDIA_PREVIOUS | 13 | Previous key | +| KEYCODE_MEDIA_REWIND | 14 | Rewind key | +| KEYCODE_MEDIA_FAST_FORWARD | 15 | Fast Forward key | +| KEYCODE_VOLUME_UP | 16 | Volume Up key | +| KEYCODE_VOLUME_DOWN | 17 | Volume Down key | +| KEYCODE_POWER | 18 | Power key | +| KEYCODE_CAMERA | 19 | Camera key | +| KEYCODE_VOLUME_MUTE | 22 | Speaker Mute key | +| KEYCODE_MUTE | 23 | Mute key | +| KEYCODE_BRIGHTNESS_UP | 40 | Brightness Up key | +| KEYCODE_BRIGHTNESS_DOWN | 41 | Brightness Down key | +| KEYCODE_0 | 2000 | Key 0 | +| KEYCODE_1 | 2001 | Key 1 | +| KEYCODE_2 | 2002 | Key 2 | +| KEYCODE_3 | 2003 | Key 3 | +| KEYCODE_4 | 2004 | Key 4 | +| KEYCODE_5 | 2005 | Key 5 | +| KEYCODE_6 | 2006 | Key 6 | +| KEYCODE_7 | 2007 | Key 7 | +| KEYCODE_8 | 2008 | Key 8 | +| KEYCODE_9 | 2009 | Key 9 | +| KEYCODE_STAR | 2010 | Key * | +| KEYCODE_POUND | 2011 | Key # | +| KEYCODE_DPAD_UP | 2012 | Up key on D-pad | +| KEYCODE_DPAD_DOWN | 2013 | Down key on D-pad | +| KEYCODE_DPAD_LEFT | 2014 | Left key on D-pad | +| KEYCODE_DPAD_RIGHT | 2015 | Right key on D-pad | +| KEYCODE_DPAD_CENTER | 2016 | Center key on D-pad | +| KEYCODE_A | 2017 | Key A | +| KEYCODE_B | 2018 | Key B | +| KEYCODE_C | 2019 | Key C | +| KEYCODE_D | 2020 | Key D | +| KEYCODE_E | 2021 | Key E | +| KEYCODE_F | 2022 | Key F | +| KEYCODE_G | 2023 | Key G | +| KEYCODE_H | 2024 | Key H | +| KEYCODE_I | 2025 | Key I | +| KEYCODE_J | 2026 | Key J | +| KEYCODE_K | 2027 | Key K | +| KEYCODE_L | 2028 | Key L | +| KEYCODE_M | 2029 | Key M | +| KEYCODE_N | 2030 | Key N | +| KEYCODE_O | 2031 | Key O | +| KEYCODE_P | 2032 | Key P | +| KEYCODE_Q | 2033 | Key Q | +| KEYCODE_R | 2034 | Key R | +| KEYCODE_S | 2035 | Key S | +| KEYCODE_T | 2036 | Key T | +| KEYCODE_U | 2037 | Key U | +| KEYCODE_V | 2038 | Key V | +| KEYCODE_W | 2039 | Key W | +| KEYCODE_X | 2040 | Key X | +| KEYCODE_Y | 2041 | Key Y | +| KEYCODE_Z | 2042 | Key Z | +| KEYCODE_COMMA | 2043 | Key , | +| KEYCODE_PERIOD | 2044 | Key . | +| KEYCODE_ALT_LEFT | 2045 | Left Alt key | +| KEYCODE_ALT_RIGHT | 2046 | Right Alt key | +| KEYCODE_SHIFT_LEFT | 2047 | Left Shift key | +| KEYCODE_SHIFT_RIGHT | 2048 | Right Shift key | +| KEYCODE_TAB | 2049 | Tab key | +| KEYCODE_SPACE | 2050 | Space key | +| KEYCODE_SYM | 2051 | Symbol key | +| KEYCODE_EXPLORER | 2052 | Explorer key, which is used to start the explorer application | +| KEYCODE_ENVELOPE | 2053 | Email key, which is used to start the email application | +| KEYCODE_ENTER | 2054 | Enter key | +| KEYCODE_DEL | 2055 | Delete key | +| KEYCODE_GRAVE | 2056 | Key ` | +| KEYCODE_MINUS | 2057 | Key - | +| KEYCODE_EQUALS | 2058 | Key = | +| KEYCODE_LEFT_BRACKET | 2059 | Key [ | +| KEYCODE_RIGHT_BRACKET | 2060 | Key ] | +| KEYCODE_BACKSLASH | 2061 | Key \\ | +| KEYCODE_SEMICOLON | 2062 | Key ; | +| KEYCODE_APOSTROPHE | 2063 | Key ' | +| KEYCODE_SLASH | 2064 | Key / | +| KEYCODE_AT | 2065 | Key @ | +| KEYCODE_PLUS | 2066 | Key + | +| KEYCODE_MENU | 2067 | Menu key | +| KEYCODE_PAGE_UP | 2068 | Page Up key | +| KEYCODE_PAGE_DOWN | 2069 | Page Down key | +| KEYCODE_ESCAPE | 2070 | ESC key | +| KEYCODE_FORWARD_DEL | 2071 | Delete key | +| KEYCODE_CTRL_LEFT | 2072 | Left Ctrl key | +| KEYCODE_CTRL_RIGHT | 2073 | Right Ctrl key | +| KEYCODE_CAPS_LOCK | 2074 | Caps Lock key | +| KEYCODE_SCROLL_LOCK | 2075 | Scroll Lock key | +| KEYCODE_META_LEFT | 2076 | Left Meta key | +| KEYCODE_META_RIGHT | 2077 | Right Meta key | +| KEYCODE_FUNCTION | 2078 | Function key | +| KEYCODE_SYSRQ | 2079 | System Request/Print Screen key | +| KEYCODE_BREAK | 2080 | Break/Pause key | +| KEYCODE_MOVE_HOME | 2081 | Move to Home key | +| KEYCODE_MOVE_END | 2082 | Move to End key | +| KEYCODE_INSERT | 2083 | Insert key | +| KEYCODE_FORWARD | 2084 | Forward key | +| KEYCODE_MEDIA_PLAY | 2085 | Play key | +| KEYCODE_MEDIA_PAUSE | 2086 | Pause key | +| KEYCODE_MEDIA_CLOSE | 2087 | Close key | +| KEYCODE_MEDIA_EJECT | 2088 | Eject key | +| KEYCODE_MEDIA_RECORD | 2089 | Record key | +| KEYCODE_F1 | 2090 | F1 key | +| KEYCODE_F2 | 2091 | F2 key | +| KEYCODE_F3 | 2092 | F3 key | +| KEYCODE_F4 | 2093 | F4 key | +| KEYCODE_F5 | 2094 | F5 key | +| KEYCODE_F6 | 2095 | F6 key | +| KEYCODE_F7 | 2096 | F7 key | +| KEYCODE_F8 | 2097 | F8 key | +| KEYCODE_F9 | 2098 | F9 key | +| KEYCODE_F10 | 2099 | F10 key | +| KEYCODE_F11 | 2100 | F11 key | +| KEYCODE_F12 | 2101 | F12 key | +| KEYCODE_NUM_LOCK | 2102 | Number Lock key | +| KEYCODE_NUMPAD_0 | 2103 | Key 0 on numeric keypad | +| KEYCODE_NUMPAD_1 | 2104 | Key 1 on numeric keypad | +| KEYCODE_NUMPAD_2 | 2105 | Key 2 on numeric keypad | +| KEYCODE_NUMPAD_3 | 2106 | Key 3 on numeric keypad | +| KEYCODE_NUMPAD_4 | 2107 | Key 4 on numeric keypad | +| KEYCODE_NUMPAD_5 | 2108 | Key 5 on numeric keypad | +| KEYCODE_NUMPAD_6 | 2109 | Key 6 on numeric keypad | +| KEYCODE_NUMPAD_7 | 2110 | Key 7 on numeric keypad | +| KEYCODE_NUMPAD_8 | 2111 | Key 8 on numeric keypad | +| KEYCODE_NUMPAD_9 | 2112 | Key 9 on numeric keypad | +| KEYCODE_NUMPAD_DIVIDE | 2113 | Key / on numeric keypad | +| KEYCODE_NUMPAD_MULTIPLY | 2114 | Key * on numeric keypad | +| KEYCODE_NUMPAD_SUBTRACT | 2115 | Key - on numeric keypad | +| KEYCODE_NUMPAD_ADD | 2116 | Key + on numeric keypad | +| KEYCODE_NUMPAD_DOT | 2117 | Key . on numeric keypad | +| KEYCODE_NUMPAD_COMMA | 2118 | Key , on numeric keypad | +| KEYCODE_NUMPAD_ENTER | 2119 | Enter key on numeric keypad | +| KEYCODE_NUMPAD_EQUALS | 2120 | Key = on numeric keypad | +| KEYCODE_NUMPAD_LEFT_PAREN | 2121 | Key ( on numeric keypad | +| KEYCODE_NUMPAD_RIGHT_PAREN | 2122 | Key ) on numeric keypad | +| KEYCODE_VIRTUAL_MULTITASK | 2210 | Multi-task key | +| KEYCODE_SLEEP | 2600 | Sleep key | +| KEYCODE_ZENKAKU_HANKAKU | 2601 | Zenkaku/Hankaku key | +| KEYCODE_102ND | 2602 | 102nd key | +| KEYCODE_RO | 2603 | Ro key | +| KEYCODE_KATAKANA | 2604 | Katakana key | +| KEYCODE_HIRAGANA | 2605 | Hiragana key | +| KEYCODE_HENKAN | 2606 | Henkan key | +| KEYCODE_KATAKANA_HIRAGANA | 2607 | Katakana/Hiragana key | +| KEYCODE_MUHENKAN | 2608 | Muhenkan key | +| KEYCODE_LINEFEED | 2609 | Linefeed key | +| KEYCODE_MACRO | 2610 | Macro key | +| KEYCODE_NUMPAD_PLUSMINUS | 2611 | Plus/Minus key on the numeric keypad | +| KEYCODE_SCALE | 2612 | Scale key | +| KEYCODE_HANGUEL | 2613 | Hanguel key | +| KEYCODE_HANJA | 2614 | Hanja key | +| KEYCODE_YEN | 2615 | Yen key | +| KEYCODE_STOP | 2616 | Stop key | +| KEYCODE_AGAIN | 2617 | Again key | +| KEYCODE_PROPS | 2618 | Props key | +| KEYCODE_UNDO | 2619 | Undo key | +| KEYCODE_COPY | 2620 | Copy key | +| KEYCODE_OPEN | 2621 | Open key | +| KEYCODE_PASTE | 2622 | Paste key | +| KEYCODE_FIND | 2623 | Find key | +| KEYCODE_CUT | 2624 | Cut key | +| KEYCODE_HELP | 2625 | Help key | +| KEYCODE_CALC | 2626 | Calc key, which is used to start the calculator application | +| KEYCODE_FILE | 2627 | File key | +| KEYCODE_BOOKMARKS | 2628 | Bookmarks key | +| KEYCODE_NEXT | 2629 | Next key | +| KEYCODE_PLAYPAUSE | 2630 | Play/Pause key | +| KEYCODE_PREVIOUS | 2631 | Previous key | +| KEYCODE_STOPCD | 2632 | Stop CD key | +| KEYCODE_CONFIG | 2634 | Config key | +| KEYCODE_REFRESH | 2635 | Refresh key | +| KEYCODE_EXIT | 2636 | Exit key | +| KEYCODE_EDIT | 2637 | Edit key | +| KEYCODE_SCROLLUP | 2638 | Scroll Up key | +| KEYCODE_SCROLLDOWN | 2639 | Scroll Down key | +| KEYCODE_NEW | 2640 | New key | +| KEYCODE_REDO | 2641 | Redo key | +| KEYCODE_CLOSE | 2642 | Close key | +| KEYCODE_PLAY | 2643 | Play key | +| KEYCODE_BASSBOOST | 2644 | Bass Boost key | +| KEYCODE_PRINT | 2645 | Print key | +| KEYCODE_CHAT | 2646 | Chat key | +| KEYCODE_FINANCE | 2647 | Finance key | +| KEYCODE_CANCEL | 2648 | Cancel key | +| KEYCODE_KBDILLUM_TOGGLE | 2649 | Keyboard Illumination Toggle key | +| KEYCODE_KBDILLUM_DOWN | 2650 | Keyboard Illumination Up key | +| KEYCODE_KBDILLUM_UP | 2651 | Keyboard Illumination Down key | +| KEYCODE_SEND | 2652 | Send key | +| KEYCODE_REPLY | 2653 | Reply key | +| KEYCODE_FORWARDMAIL | 2654 | Forward Mail key | +| KEYCODE_SAVE | 2655 | Save key | +| KEYCODE_DOCUMENTS | 2656 | Documents key | +| KEYCODE_VIDEO_NEXT | 2657 | Next Video key | +| KEYCODE_VIDEO_PREV | 2658 | Previous Video key | +| KEYCODE_BRIGHTNESS_CYCLE | 2659 | Brightness Cycle key | +| KEYCODE_BRIGHTNESS_ZERO | 2660 | Brightness Zero key | +| KEYCODE_DISPLAY_OFF | 2661 | Display Off Key | +| KEYCODE_BTN_MISC | 2662 | Misc Button key | +| KEYCODE_GOTO | 2663 | Goto key | +| KEYCODE_INFO | 2664 | Info key | +| KEYCODE_PROGRAM | 2665 | Program key | +| KEYCODE_PVR | 2666 | PVR key | +| KEYCODE_SUBTITLE | 2667 | Subtitle key | +| KEYCODE_FULL_SCREEN | 2668 | Full Screen key | +| KEYCODE_KEYBOARD | 2669 | Keyboard | +| KEYCODE_ASPECT_RATIO | 2670 | Aspect Ratio key | +| KEYCODE_PC | 2671 | Port Control key | +| KEYCODE_TV | 2672 | TV key | +| KEYCODE_TV2 | 2673 | TV key 2 | +| KEYCODE_VCR | 2674 | VCR key | +| KEYCODE_VCR2 | 2675 | VCR key 2 | +| KEYCODE_SAT | 2676 | SAT key | +| KEYCODE_CD | 2677 | CD key | +| KEYCODE_TAPE | 2678 | Tape key | +| KEYCODE_TUNER | 2679 | Tuner key | +| KEYCODE_PLAYER | 2680 | Player key | +| KEYCODE_DVD | 2681 | DVD key | +| KEYCODE_AUDIO | 2682 | Audio key | +| KEYCODE_VIDEO | 2683 | Video key | +| KEYCODE_MEMO | 2684 | Memo key | +| KEYCODE_CALENDAR | 2685 | Calendar key | +| KEYCODE_RED | 2686 | Red indicator | +| KEYCODE_GREEN | 2687 | Green indicator | +| KEYCODE_YELLOW | 2688 | Yellow indicator | +| KEYCODE_BLUE | 2689 | Blue indicator | +| KEYCODE_CHANNELUP | 2690 | Channel Up key | +| KEYCODE_CHANNELDOWN | 2691 | Channel Down key | +| KEYCODE_LAST | 2692 | Last key | +| KEYCODE_RESTART | 2693 | Restart key | +| KEYCODE_SLOW | 2694 | Slow key | +| KEYCODE_SHUFFLE | 2695 | Shuffle key | +| KEYCODE_VIDEOPHONE | 2696 | Videophone key | +| KEYCODE_GAMES | 2697 | Games key | +| KEYCODE_ZOOMIN | 2698 | Zoom-in key | +| KEYCODE_ZOOMOUT | 2699 | Zoom-out key | +| KEYCODE_ZOOMRESET | 2700 | Zoom Reset key | +| KEYCODE_WORDPROCESSOR | 2701 | Word Processor key | +| KEYCODE_EDITOR | 2702 | Editor key | +| KEYCODE_SPREADSHEET | 2703 | Spreadsheet key | +| KEYCODE_GRAPHICSEDITOR | 2704 | Graphics Editor key | +| KEYCODE_PRESENTATION | 2705 | Presentation key | +| KEYCODE_DATABASE | 2706 | Database key | +| KEYCODE_NEWS | 2707 | News key | +| KEYCODE_VOICEMAIL | 2708 | Voicemail key | +| KEYCODE_ADDRESSBOOK | 2709 | Addressbook key | +| KEYCODE_MESSENGER | 2710 | Messenger key | +| KEYCODE_BRIGHTNESS_TOGGLE | 2711 | Brightness Toggle key | +| KEYCODE_SPELLCHECK | 2712 | Spell Check key | +| KEYCODE_COFFEE | 2713 | Coffee key, which is used to launch screen lock or screen saver | +| KEYCODE_MEDIA_REPEAT | 2714 | Media Repeat key | +| KEYCODE_IMAGES | 2715 | Images key | +| KEYCODE_BUTTONCONFIG | 2716 | Button Configuration key | +| KEYCODE_TASKMANAGER | 2717 | Task Manager key | +| KEYCODE_JOURNAL | 2718 | Log key | +| KEYCODE_CONTROLPANEL | 2719 | Control Panel key | +| KEYCODE_APPSELECT | 2720 | App Select key | +| KEYCODE_SCREENSAVER | 2721 | Screen Saver key | +| KEYCODE_ASSISTANT | 2722 | Assistant key | +| KEYCODE_KBD_LAYOUT_NEXT | 2723 | Next Keyboard Layout key | +| KEYCODE_BRIGHTNESS_MIN | 2724 | Min Brightness key | +| KEYCODE_BRIGHTNESS_MAX | 2725 | Max Brightness key | +| KEYCODE_KBDINPUTASSIST_PREV | 2726 | Keyboard Input-assisted Previous key | +| KEYCODE_KBDINPUTASSIST_NEXT | 2727 | Keyboard Input-assisted Next key | +| KEYCODE_KBDINPUTASSIST_PREVGROUP | 2728 | Keyboard Input-assisted Previous Group key | +| KEYCODE_KBDINPUTASSIST_NEXTGROUP | 2729 | Keyboard Input-assisted Next Group key | +| KEYCODE_KBDINPUTASSIST_ACCEPT | 2730 | Keyboard Input-assisted Accept key | +| KEYCODE_KBDINPUTASSIST_CANCEL | 2731 | Keyboard Input-assisted Cancel key | +| KEYCODE_FRONT | 2800 | Front key, which is used to launch the windshield defogger | +| KEYCODE_SETUP | 2801 | Setup key | +| KEYCODE_WAKEUP | 2802 | Wakeup key | +| KEYCODE_SENDFILE | 2803 | Send File key | +| KEYCODE_DELETEFILE | 2804 | Delete File key | +| KEYCODE_XFER | 2805 | XFER key, which is used to start file transfer | +| KEYCODE_PROG1 | 2806 | Program key 1 | +| KEYCODE_PROG2 | 2807 | Program key 2 | +| KEYCODE_MSDOS | 2808 | MS-DOS key | +| KEYCODE_SCREENLOCK | 2809 | Screen Lock key | +| KEYCODE_DIRECTION_ROTATE_DISPLAY | 2810 | Directional Rotation Display key | +| KEYCODE_CYCLEWINDOWS | 2811 | Windows Cycle key | +| KEYCODE_COMPUTER | 2812 | Keys | +| KEYCODE_EJECTCLOSECD | 2813 | Eject CD key | +| KEYCODE_ISO | 2814 | ISO key | +| KEYCODE_MOVE | 2815 | Move key | +| KEYCODE_F13 | 2816 | F13 key | +| KEYCODE_F14 | 2817 | F14 key | +| KEYCODE_F15 | 2818 | F15 key | +| KEYCODE_F16 | 2819 | F16 key | +| KEYCODE_F17 | 2820 | F17 key | +| KEYCODE_F18 | 2821 | F18 key | +| KEYCODE_F19 | 2822 | F19 key | +| KEYCODE_F20 | 2823 | F20 key | +| KEYCODE_F21 | 2824 | F21 key | +| KEYCODE_F22 | 2825 | F22 key | +| KEYCODE_F23 | 2826 | F23 key | +| KEYCODE_F24 | 2827 | F24 key | +| KEYCODE_PROG3 | 2828 | Program key 3 | +| KEYCODE_PROG4 | 2829 | Program key 4 | +| KEYCODE_DASHBOARD | 2830 | Dashboard | +| KEYCODE_SUSPEND | 2831 | Suspend key | +| KEYCODE_HP | 2832 | HP key | +| KEYCODE_SOUND | 2833 | Sound key | +| KEYCODE_QUESTION | 2834 | Question key | +| KEYCODE_CONNECT | 2836 | Connect key | +| KEYCODE_SPORT | 2837 | Sport key | +| KEYCODE_SHOP | 2838 | Shop key | +| KEYCODE_ALTERASE | 2839 | Alternate key | +| KEYCODE_SWITCHVIDEOMODE | 2841 | Switch Video Mode key (monitor, LCD, and TV, etc.)| +| KEYCODE_BATTERY | 2842 | Battery key | +| KEYCODE_BLUETOOTH | 2843 | Bluetooth key | +| KEYCODE_WLAN | 2844 | WLAN key | +| KEYCODE_UWB | 2845 | Ultra-wideband key | +| KEYCODE_WWAN_WIMAX | 2846 | WWAN WiMAX key | +| KEYCODE_RFKILL | 2847 | RF Kill key | +| KEYCODE_CHANNEL | 3001 | Channel key | +| KEYCODE_BTN_0 | 3100 | Button 0 | +| KEYCODE_BTN_1 | 3101 | Button 1 | +| KEYCODE_BTN_2 | 3102 | Button 2 | +| KEYCODE_BTN_3 | 3103 | Button 3 | +| KEYCODE_BTN_4 | 3104 | Button 4 | +| KEYCODE_BTN_5 | 3105 | Button 5 | +| KEYCODE_BTN_6 | 3106 | Button 6 | +| KEYCODE_BTN_7 | 3107 | Button 7 | +| KEYCODE_BTN_8 | 3108 | Button 8 | +| KEYCODE_BTN_9 | 3109 | Button 9 | diff --git a/en/application-dev/reference/apis/js-apis-matrix4.md b/en/application-dev/reference/apis/js-apis-matrix4.md index 97dd9e3f982d9f36d5feb6f17d59a40bb57e1a20..f5b9b27f55ed9d363939bef6f55582423afe4a28 100644 --- a/en/application-dev/reference/apis/js-apis-matrix4.md +++ b/en/application-dev/reference/apis/js-apis-matrix4.md @@ -145,11 +145,12 @@ Copies this matrix object. ```ts // xxx.ets import matrix4 from '@ohos.matrix4' + @Entry @Component struct Test { - private matrix1 = matrix4.identity().translate({x:100}) - private matrix2 = this.matrix1.copy().scale({x:2}) + private matrix1 = matrix4.identity().translate({ x: 100 }) + private matrix2 = this.matrix1.copy().scale({ x: 2 }) build() { Column() { @@ -160,7 +161,7 @@ struct Test { Image($r("app.media.bg2")) .width("40%") .height(100) - .margin({top:50}) + .margin({ top: 50 }) .transform(this.matrix2) } } @@ -199,11 +200,12 @@ Combines the effects of two matrices to generate a new matrix object. ```ts // xxx.ets import matrix4 from '@ohos.matrix4' + @Entry @Component struct Test { - private matrix1 = matrix4.identity().translate({x:200}).copy() - private matrix2 = matrix4.identity().scale({x:2}).copy() + private matrix1 = matrix4.identity().translate({ x: 200 }).copy() + private matrix2 = matrix4.identity().scale({ x: 2 }).copy() build() { Column() { @@ -211,13 +213,13 @@ struct Test { Image($r("app.media.icon")) .width("40%") .height(100) - .margin({top:50}) + .margin({ top: 50 }) // Translate the x-axis by 200px, and then scale it twice to obtain the resultant matrix. Image($r("app.media.icon")) .transform(this.matrix1.combine(this.matrix2)) .width("40%") - .height(100) - .margin({top:50}) + .height(100) + .margin({ top: 50 }) } } } @@ -245,8 +247,9 @@ Inverts this matrix object. ```ts import matrix4 from '@ohos.matrix4' // The effect of matrix 1 (width scaled up by 2x) is opposite to that of matrix 2 (width scaled down by 2x). -let matrix1 = matrix4.identity().scale({x:2}) +let matrix1 = matrix4.identity().scale({ x: 2 }) let matrix2 = matrix1.invert() + @Entry @Component struct Tests { @@ -295,10 +298,11 @@ Translates this matrix object along the x, y, and z axes. ```ts // xxx.ets import matrix4 from '@ohos.matrix4' + @Entry @Component struct Test { - private matrix1 = matrix4.identity().translate({x:100, y:200, z:30}) + private matrix1 = matrix4.identity().translate({ x: 100, y: 200, z: 30 }) build() { Column() { @@ -346,7 +350,7 @@ import matrix4 from '@ohos.matrix4' @Entry @Component struct Test { - private matrix1 = matrix4.identity().scale({x:2, y:3, z:4, centerX:50, centerY:50}) + private matrix1 = matrix4.identity().scale({ x:2, y:3, z:4, centerX:50, centerY:50 }) build() { Column() { @@ -392,17 +396,18 @@ Rotates this matrix object along the x, y, and z axes. ```ts // xxx.ets import matrix4 from '@ohos.matrix4' + @Entry @Component struct Test { - private matrix1 = matrix4.identity().rotate({x:1, y:1, z:2, angle:30}) + private matrix1 = matrix4.identity().rotate({ x: 1, y: 1, z: 2, angle: 30 }) build() { Column() { Image($r("app.media.bg1")).transform(this.matrix1) .width("40%") .height(100) - }.width("100%").margin({top:50}) + }.width("100%").margin({ top: 50 }) } } ``` diff --git a/en/application-dev/reference/apis/js-apis-mediaquery.md b/en/application-dev/reference/apis/js-apis-mediaquery.md index 4176338c0957632f67df2a74c73cd51a8ab1d48d..f44a0801b9ae1d9d4fec2f4485bf848e8595caa5 100644 --- a/en/application-dev/reference/apis/js-apis-mediaquery.md +++ b/en/application-dev/reference/apis/js-apis-mediaquery.md @@ -1,4 +1,4 @@ -# Media Query +# @ohos.mediaquery The **mediaquery** module provides different styles for different media types. @@ -14,64 +14,64 @@ import mediaquery from '@ohos.mediaquery' ``` -## Required Permissions - -None. - - ## mediaquery.matchMediaSync matchMediaSync(condition: string): MediaQueryListener -Sets the media query criteria and returns the corresponding listening handle. +Sets the media query condition. This API returns the corresponding media query listener. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** + | Name | Type | Mandatory | Description | | --------- | ------ | ---- | ---------------------------------------- | -| condition | string | Yes | Matching condition of a media event. For details, see [Syntax of Media Query Conditions](../../ui/ui-ts-layout-mediaquery.md#syntax-of-media-query-conditions).| +| condition | string | Yes | Media query condition. For details, see [Syntax of Media Query Conditions](../../ui/ui-ts-layout-mediaquery.md#syntax-of-media-query-conditions).| **Return value** + | Type | Description | | ------------------ | ---------------------- | -| MediaQueryListener | Listening handle to a media event, which is used to register or deregister the listening callback.| +| MediaQueryListener | Media query listener, which is used to register or deregister the listening callback.| **Example** - ```js + +```js let listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events. - ``` +``` ## MediaQueryListener -Media query handle, including the first query result when the handle is applied for. +Implements the media query listener, including the first query result when the listener is applied for. **System capability**: SystemCapability.ArkUI.ArkUI.Full ### Attributes -| Name | Type | Readable | Writable | Description | -| ------- | ------- | ---- | ---- | ---------- | -| matches | boolean | Yes | No | Whether the match condition is met. | -| media | string | Yes | No | Matching condition of a media event.| +| Name | Type | Readable| Writable| Description | +| ------- | ------- | ---- | ---- | -------------------- | +| matches | boolean | Yes | No | Whether the media query condition is met. | +| media | string | Yes | No | Media query condition.| ### on on(type: 'change', callback: Callback<MediaQueryResult>): void -Registers a callback with the corresponding query condition by using the handle. This callback is triggered when the media attributes change. +Registers the media query listener. The callback is triggered when the media attributes change. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** + | Name | Type | Mandatory | Description | | -------- | -------------------------------- | ---- | ---------------- | -| type | string | Yes | Must enter the string **change**.| +| type | string | Yes | Listener type. The value is fixed at **'change'**.| | callback | Callback<MediaQueryResult> | Yes | Callback registered with media query. | **Example** + For details, see [off Example](#off). @@ -79,17 +79,19 @@ Registers a callback with the corresponding query condition by using the handle. off(type: 'change', callback?: Callback<MediaQueryResult>): void -Deregisters a callback with the corresponding query condition by using the handle, so that no callback is triggered when the media attributes change. +Deregisters the media query listener, so that no callback is triggered when the media attributes change. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** -| Name | Type | Mandatory | Description | -| -------- | -------------------------------- | ---- | ----------------------------- | -| type | boolean | Yes | Must enter the string **change**. | -| callback | Callback<MediaQueryResult> | No | Callback to be deregistered. If the default value is used, all callbacks of the handle are deregistered.| + +| Name | Type | Mandatory| Description | +| -------- | -------------------------------- | ---- | ---------------------------------------------------------- | +| type | string | Yes | Listener type. The value is fixed at **'change'**. | +| callback | Callback<MediaQueryResult> | No | Callback to be deregistered. If the default value is used, all callbacks of the handle are deregistered.| **Example** + ```js import mediaquery from '@ohos.mediaquery' @@ -101,20 +103,23 @@ Deregisters a callback with the corresponding query condition by using the handl // do something here } } - listener.on('change', onPortrait) // Register a callback. - listener.off('change', onPortrait) // Deregister a callback. + listener.on('change', onPortrait) // Register the media query listener. + listener.off('change', onPortrait) // Deregister the media query listener. ``` - ## MediaQueryResult +Provides the media query result. + +**System capability**: SystemCapability.ArkUI.ArkUI.Full + ### Attributes -| Name | Type | Readable | Writable | Description | -| ------- | ------- | ---- | ---- | ---------- | -| matches | boolean | Yes | No | Whether the match condition is met. | -| media | string | Yes | No | Matching condition of a media event.| +| Name | Type | Readable| Writable| Description | +| ------- | ------- | ---- | ---- | -------------------- | +| matches | boolean | Yes | No | Whether the media query condition is met. | +| media | string | Yes | No | Media query condition.| ### Example diff --git a/en/application-dev/reference/apis/js-apis-net-connection.md b/en/application-dev/reference/apis/js-apis-net-connection.md index b52bf994b7697ccfaf86fce719f1e12a9da4568a..5df384d16ab9e802971b36cc2527ab36538f143f 100644 --- a/en/application-dev/reference/apis/js-apis-net-connection.md +++ b/en/application-dev/reference/apis/js-apis-net-connection.md @@ -60,7 +60,7 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` -## connection.getDefaultNetSync +## connection.getDefaultNetSync9+ getDefaultNetSync(): NetHandle; @@ -302,6 +302,55 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` +## connection.isDefaultNetMetered9+ + +isDefaultNetMetered(callback: AsyncCallback\): void + +Checks whether the data traffic usage on the current network is metered. This API uses an asynchronous callback to return the result. + +**Required permission**: ohos.permission.GET_NETWORK_INFO + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | -------------------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** indicates the data traffic usage is metered.| + +**Example**: + +```js +connection.isDefaultNetMetered(function (error, has) { + console.log(JSON.stringify(error)) + console.log('has: ' + has) +}) +``` + +## connection.isDefaultNetMetered9+ + +isDefaultNetMetered(): Promise\ + +Checks whether the data traffic usage on the current network is metered. This API uses a promise to return the result. + +**Required permission**: ohos.permission.GET_NETWORK_INFO + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Return value** + +| Type | Description | +| ----------------- | ----------------------------------------------- | +| Promise\ | Promise used to return the result. The value **true** indicates the data traffic usage is metered.| + +**Example**: + +```js +connection.isDefaultNetMetered().then(function (has) { + console.log('has: ' + has) +}) +``` + ## connection.reportNetConnected reportNetConnected(netHandle: NetHandle, callback: AsyncCallback<void>): void @@ -331,7 +380,6 @@ connection.getDefaultNet().then(function (netHandle) { }); ``` - ## connection.reportNetConnected reportNetConnected(netHandle: NetHandle): Promise<void> @@ -489,14 +537,13 @@ connection.getAddressesByName(host).then(function (addresses) { }) ``` - ## connection.enableAirplaneMode enableAirplaneMode(callback: AsyncCallback\): void Enables the airplane mode. This API uses an asynchronous callback to return the result. -This is a system API. +**System API**: This is a system API. **System capability**: SystemCapability.Communication.NetManager.Core @@ -520,7 +567,7 @@ enableAirplaneMode(): Promise\ Enables the airplane mode. This API uses a promise to return the result. -This is a system API. +**System API**: This is a system API. **System capability**: SystemCapability.Communication.NetManager.Core @@ -538,14 +585,13 @@ connection.enableAirplaneMode().then(function (error) { }) ``` - ## connection.disableAirplaneMode disableAirplaneMode(callback: AsyncCallback\): void Disables the airplane mode. This API uses an asynchronous callback to return the result. -This is a system API. +**System API**: This is a system API. **System capability**: SystemCapability.Communication.NetManager.Core @@ -569,7 +615,7 @@ disableAirplaneMode(): Promise\ Disables the airplane mode. This API uses a promise to return the result. -This is a system API. +**System API**: This is a system API. **System capability**: SystemCapability.Communication.NetManager.Core @@ -587,7 +633,6 @@ connection.disableAirplaneMode().then(function (error) { }) ``` - ## connection.createNetConnection createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection @@ -824,9 +869,9 @@ Before invoking NetHandle APIs, call **getNetHandle** to obtain a **NetHandle** | Name| Type | Description | | ------ | ------ | ------------------------- | -| netId | number | Network ID. The value must be greater than or equal to 100.| +| netId | number | Network ID. The value **0** indicates no default network. Any other value must be greater than or equal to 100.| -### bindSocket +### bindSocket9+ bindSocket(socketParam: TCPSocket \| UDPSocket, callback: AsyncCallback\): void; @@ -846,33 +891,50 @@ Binds a **TCPSocket** or **UDPSocket** object to the data network. This API uses **Example** ```js -connection.getDefaultNet().then(function (netHandle) { +import socket from "@ohos.net.socket"; +connection.getDefaultNet().then((netHandle)=>{ var tcp = socket.constructTCPSocketInstance(); var udp = socket.constructUDPSocketInstance(); - let socketType = "xxxx"; + let socketType = "TCPSocket"; if (socketType == "TCPSocket") { tcp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { - netHandle.bindSocket(tcp, function (error, data) { - console.log(JSON.stringify(error)) - console.log(JSON.stringify(data)) + if (err) { + console.log('bind fail'); + } + netHandle.bindSocket(tcp, (error, data)=>{ + if (error) { + console.log(JSON.stringify(error)); + } else { + console.log(JSON.stringify(data)); + } + }) }) } else { + let callback = value => { + console.log(TAG + "on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); + } udp.on('message', callback); udp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { + if (err) { + console.log('bind fail'); + } udp.on('message', (data) => { - console.log(JSON.stringify(data)) - }); - netHandle.bindSocket(udp, function (error, data) { - console.log(JSON.stringify(error)) - console.log(JSON.stringify(data)) + console.log(JSON.stringify(data)) }); + netHandle.bindSocket(udp,(error, data)=>{ + if (error) { + console.log(JSON.stringify(error)); + } else { + console.log(JSON.stringify(data)); + } + }) }) - } -} + } +}) ``` ### bindSocket @@ -900,31 +962,50 @@ Binds a **TCPSocket** or **UDPSocket** object to the data network. This API uses **Example** ```js -connection.getDefaultNet().then(function (netHandle) { +import socket from "@ohos.net.socket"; +connection.getDefaultNet().then((netHandle)=>{ var tcp = socket.constructTCPSocketInstance(); var udp = socket.constructUDPSocketInstance(); - let socketType = "xxxx"; - if(socketType == "TCPSocket") { + let socketType = "TCPSocket"; + if (socketType == "TCPSocket") { tcp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { - netHandle.bindSocket(tcp).then(err, data) { - console.log(JSON.stringify(data)) + if (err) { + console.log('bind fail'); + } + netHandle.bindSocket(tcp).then((err, data) => { + if (err) { + console.log(JSON.stringify(err)); + } else { + console.log(JSON.stringify(data)); + } + }) }) } else { + let callback = value => { + console.log(TAG + "on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); + } udp.on('message', callback); udp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { + if (err) { + console.log('bind fail'); + } udp.on('message', (data) => { - console.log(JSON.stringify(data)) - }); - netHandle.bindSocket(tcp).then(err, data) { - console.log(JSON.stringify(data)) - }); + console.log(JSON.stringify(data)); + }) + netHandle.bindSocket(udp).then((err, data) => { + if (err) { + console.log(JSON.stringify(err)); + } else { + console.log(JSON.stringify(data)); + } + }) }) - } -} + } +}) ``` @@ -1058,10 +1139,10 @@ Provides an instance that bears data network capabilities. **System capability**: SystemCapability.Communication.NetManager.Core -| Name | Type | Description | -| ----------------------- | ----------------------------------- | ------------------------------------------------------------ | -| netCapabilities | [NetCapabilities](#netcapabilities) | Network transmission capabilities and bearer types of the data network. | -| bearerPrivateIdentifier | string | Network identifier. The identifier of a Wi-Fi network is **wifi**, and that of a cellular network is **slot0** (corresponding to SIM card 1).| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| netCapabilities | [NetCapabilities](#netcapabilities) | Yes | Network transmission capabilities and bearer types of the data network. | +| bearerPrivateIdentifier | string | No | Network identifier. The identifier of a Wi-Fi network is **wifi**, and that of a cellular network is **slot0** (corresponding to SIM card 1).| ## NetCapabilities @@ -1069,12 +1150,12 @@ Defines the network capability set. **System capability**: SystemCapability.Communication.NetManager.Core -| Name | Type | Description | -| --------------------- | ---------------------------------- | ------------------------ | -| linkUpBandwidthKbps | number | Uplink (from the device to the network) bandwidth.| -| linkDownBandwidthKbps | number | Downlink (from the network to the device) bandwidth.| -| networkCap | Array<[NetCap](#netcap)> | Network capability. | -| bearerTypes | Array<[NetBearType](#netbeartype)> | Network type. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| linkUpBandwidthKbps | number | No | Uplink (from the device to the network) bandwidth.| +| linkDownBandwidthKbps | number | No | Downlink (from the network to the device) bandwidth.| +| networkCap | Array<[NetCap](#netcap)> | No | Network capability. | +| bearerTypes | Array<[NetBearType](#netbeartype)> | Yes | Network type. | ## NetCap @@ -1108,14 +1189,14 @@ Defines the network connection properties. **System capability**: SystemCapability.Communication.NetManager.Core -| Name | Type | Description | -| ------------- | ---------------------------------- | ---------------- | -| interfaceName | string | NIC card name. | -| domains | string | Domain. The default value is **""**.| -| linkAddresses | Array<[LinkAddress](#linkaddress)> | Link information. | -| routes | Array<[RouteInfo](#routeinfo)> | Route information. | -| dnses | Array<[NetAddress](#netaddress)> | Network address. For details, see [NetAddress](#netaddress).| -| mtu | number | Maximum transmission unit (MTU). | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| interfaceName | string | Yes | NIC card name. | +| domains | string | Yes | Domain. The default value is **""**.| +| linkAddresses | Array\<[LinkAddress](#linkaddress)> | Yes | Link information. | +| routes | Array\<[RouteInfo](#routeinfo)> | Yes | Route information. | +| dnses | Array\<[NetAddress](#netaddress)>; | Yes | Network address. For details, see [NetAddress](#netaddress).| +| mtu | number | Yes | Maximum transmission unit (MTU). | ## LinkAddress @@ -1123,10 +1204,10 @@ Network link information. **System capability**: SystemCapability.Communication.NetManager.Core -| Name | Type | Description | -| ------------ | ------------------------- | -------------------- | -| address | [NetAddress](#netaddress) | Link address. | -| prefixLength | number | Length of the link address prefix.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| address | [NetAddress](#netaddress) | Yes | Link address. | +| prefixLength | number | Yes | Length of the link address prefix.| ## RouteInfo @@ -1134,13 +1215,13 @@ Network route information. **System capability**: SystemCapability.Communication.NetManager.Core -| Name | Type | Description | -| -------------- | --------------------------- | ---------------- | -| interface | string | NIC card name. | -| destination | [LinkAddress](#linkaddress) | Destination IP address. | -| gateway | [NetAddress](#netaddress) | Gateway address. | -| hasGateway | boolean | Whether a gateway is present. | -| isDefaultRoute | boolean | Whether the route is the default route.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| interface | string | Yes | NIC card name. | +| destination | [LinkAddress](#linkaddress) | Yes | Destination IP address. | +| gateway | [NetAddress](#netaddress) | Yes | Gateway address. | +| hasGateway | boolean | Yes | Whether a gateway is present. | +| isDefaultRoute | boolean | Yes | Whether the route is the default route.| ## NetAddress @@ -1148,8 +1229,8 @@ Defines the network address. **System capability**: SystemCapability.Communication.NetManager.Core -| Name | Type | Description | -| ------- | ------ | ------------------------------ | -| address | string | Network address. | -| family | number | Address family identifier. The value is **1** for IPv4 and **2** for IPv6. The default value is **1**.| -| port | number | Port number. The value ranges from **0** to **65535**. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| address | string | Yes | Network address. | +| family | number | Yes | Address family identifier. The value is **1** for IPv4 and **2** for IPv6. The default value is **1**.| +| port | number | No | Port number. The value ranges from **0** to **65535**. | diff --git a/en/application-dev/reference/apis/js-apis-net-ethernet.md b/en/application-dev/reference/apis/js-apis-net-ethernet.md index c08a515429cb6354654ca66e93e970c3250edbdf..924d8157a82c8125506cf3a995c1d934cce2c7cc 100644 --- a/en/application-dev/reference/apis/js-apis-net-ethernet.md +++ b/en/application-dev/reference/apis/js-apis-net-ethernet.md @@ -13,7 +13,7 @@ import ethernet from '@ohos.net.ethernet' ## ethernet.setIfaceConfig -setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback\): void; +setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback\): void Sets the network interface configuration. This API uses an asynchronous callback to return the result. @@ -45,7 +45,7 @@ ethernet.setIfaceConfig("eth0", {mode:ethernet.STATIC,ipAddr:"192.168.1.123", ro ## ethernet.setIfaceConfig -setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\; +setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\ Sets the network interface configuration. This API uses a promise to return the result. @@ -79,7 +79,7 @@ ethernet.setIfaceConfig("eth0", {mode:ethernet.STATIC,ipAddr:"192.168.1.123", ro ## ethernet.getIfaceConfig -getIfaceConfig(iface: string, callback: AsyncCallback\): void; +getIfaceConfig(iface: string, callback: AsyncCallback\): void Obtains the configuration of a network interface. This API uses an asynchronous callback to return the result. @@ -114,7 +114,7 @@ ethernet.getIfaceConfig("eth0", (error, value) => { ## ethernet.getIfaceConfig -getIfaceConfig(iface: string): Promise\; +getIfaceConfig(iface: string): Promise\ Obtains the configuration of a network interface. This API uses a promise to return the result. @@ -152,7 +152,7 @@ ethernet.getIfaceConfig("eth0").then((data) => { ## ethernet.isIfaceActive -isIfaceActive(iface?: string, callback: AsyncCallback\): void; +isIfaceActive(iface?: string, callback: AsyncCallback\): void Checks whether a network interface is active. This API uses an asynchronous callback to return the result. @@ -164,7 +164,7 @@ Checks whether a network interface is active. This API uses an asynchronous call | Name | Type | Mandatory| Description | | -------- | --------------------------- | ---- | -------------------------------------------------- | -| iface | string | No | Name of the network interface. If this parameter is left empty, the API checks for any active network interface. | +| iface | string | Yes | Name of the network interface. If this parameter is left empty, the API checks for any active network interface. | | callback | AsyncCallback\ | Yes | Callback used to return the result. The value **1** means that the network interface is active, **0** means that the network interface is inactive, and any other value means that an error has occurred.| **Example** @@ -181,7 +181,7 @@ ethernet.isIfaceActive("eth0", (error, value) => { ## ethernet.isIfaceActive -isIfaceActive(iface?: string): Promise\; +isIfaceActive(iface: string): Promise\ Checks whether a network interface is active. This API uses a promise to return the result. @@ -193,7 +193,7 @@ Checks whether a network interface is active. This API uses a promise to return | Name| Type | Mandatory| Description | | ------ | ------ | ---- | -------------------------------------- | -| iface | string | No | Name of the network interface. If this parameter is left empty, the API checks for any active network interface.| +| iface | string | Yes | Name of the network interface. If this parameter is left empty, the API checks for any active network interface.| **Return value** @@ -213,7 +213,7 @@ ethernet.isIfaceActive("eth0").then((data) => { ## ethernet.getAllActiveIfaces -getAllActiveIfaces(callback: AsyncCallback\>): void; +getAllActiveIfaces(callback: AsyncCallback\>): void Obtains all active network interfaces. This API uses an asynchronous callback to return the result. @@ -244,7 +244,7 @@ ethernet.getAllActiveIfaces((error, value) => { ## ethernet.getAllActiveIfaces -getAllActiveIfaces(): Promise\>; +getAllActiveIfaces(): Promise\> Obtains all active network interfaces. This API uses a promise to return the result. @@ -279,14 +279,14 @@ Defines the network configuration for the Ethernet connection. **System capability**: SystemCapability.Communication.NetManager.Core -| Name | Type | Description | -| ----------------------- | ----------------------------------- | ------------------------------------------------------------ | -| mode | [IPSetMode](#ipsetmode) | Configuration mode of the Ethernet connection.| -| ipAddr | string | Static IP address of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in Dynamic Host Configuration Protocol (DHCP) mode.| -| route | string | Route of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.| -| gateway | string | Gateway of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.| -| netMask | string | Subnet mask of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.| -| dnsServers | string | DNS server addresses of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode. Multiple addresses are separated by commas (,).| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| mode | [IPSetMode](#ipsetmode) | Yes | Configuration mode of the Ethernet connection.| +| ipAddr | string | Yes | Static IP address of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in Dynamic Host Configuration Protocol (DHCP) mode.| +| route | string | Yes | Route of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.| +| gateway | string | Yes | Gateway of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.| +| netMask | string | Yes | Subnet mask of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.| +| dnsServers | string | Yes | DNS server addresses of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode. Multiple addresses are separated by commas (,).| ## IPSetMode diff --git a/en/application-dev/reference/apis/js-apis-net-sharing.md b/en/application-dev/reference/apis/js-apis-net-sharing.md index d03ae66622385309eba546ab7cc8c27405b81eed..a688bf46448c6371ba5c0bd2e740ed276c0bbe20 100644 --- a/en/application-dev/reference/apis/js-apis-net-sharing.md +++ b/en/application-dev/reference/apis/js-apis-net-sharing.md @@ -17,9 +17,11 @@ isSharingSupported(callback: AsyncCallback\): void Checks whether network sharing is supported. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -42,9 +44,11 @@ isSharingSupported(): Promise\ Checks whether network sharing is supported. This API uses a promise to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Return value** @@ -68,9 +72,11 @@ isSharing(callback: AsyncCallback\): void Checks whether network sharing is in progress. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -95,7 +101,9 @@ Checks whether network sharing is in progress. This API uses a promise to return **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System API**: This is a system API. + +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Return value** @@ -121,7 +129,9 @@ Starts network sharing of a specified type. This API uses an asynchronous callba **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System API**: This is a system API. + +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -145,9 +155,11 @@ startSharing(type: SharingIfaceType): Promise\ Starts network sharing of a specified type. This API uses a promise to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -178,9 +190,11 @@ stopSharing(type: SharingIfaceType, callback: AsyncCallback\): void Stops network sharing of a specified type. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -204,9 +218,11 @@ stopSharing(type: SharingIfaceType): Promise\ Stops network sharing of a specified type. This API uses a promise to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -237,9 +253,11 @@ getStatsRxBytes(callback: AsyncCallback\): void Obtains the volume of mobile data traffic received via network sharing. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -262,9 +280,11 @@ getStatsRxBytes(): Promise\ Obtains the volume of mobile data traffic received via network sharing. This API uses a promise to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Return value** @@ -288,9 +308,11 @@ getStatsTxBytes(callback: AsyncCallback\): void Obtains the volume of mobile data traffic sent via network sharing. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -313,9 +335,11 @@ getStatsTxBytes(): Promise\ Obtains the volume of mobile data traffic sent via network sharing. This API uses a promise to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Return value** @@ -339,9 +363,11 @@ getStatsTotalBytes(callback: AsyncCallback\): void Obtains the volume of mobile data traffic sent and received via network sharing. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -364,9 +390,11 @@ getStatsTotalBytes(): Promise\ Obtains the volume of mobile data traffic sent and received via network sharing. This API uses a promise to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Return value** @@ -390,21 +418,23 @@ getSharingIfaces(state: SharingIfaceState, callback: AsyncCallback\> | Yes | Callback used to return an array of NIC names.| **Example** ```js -import SharingIfaceState from '@ohos.net.sharing' +import SharingIfaceType from '@ohos.net.sharing' sharing.getSharingIfaces(SharingIfaceState.SHARING_NIC_CAN_SERVER, (error, data) => { console.log(JSON.stringify(error)); console.log(JSON.stringify(data)); @@ -417,15 +447,17 @@ getSharingIfaces(state: SharingIfaceState): Promise\> Obtains the names of NICs in the specified network sharing state. This API uses a promise to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------- | ---- | ---------- | -| state | state: [SharingIfaceState](#sharingifacestate) | Yes | Network sharing state.| +| state | [SharingIfaceState](#sharingifacestate) | Yes | Network sharing state.| **Return value** @@ -450,9 +482,11 @@ getSharingState(type: SharingIfaceType, callback: AsyncCallback\ Obtains the network sharing state of the specified type. This API uses a promise to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -497,7 +533,7 @@ Obtains the network sharing state of the specified type. This API uses a promise ```js import SharingIfaceType from '@ohos.net.sharing' -sharing.getSharingIfaces(SharingIfaceType.SHARING_WIFI).then(data => { +sharing.getSharingState(SharingIfaceType.SHARING_WIFI).then(data => { console.log(JSON.stringify(data)); }).catch(error => { console.log(JSON.stringify(error)); @@ -510,9 +546,11 @@ getSharableRegexes(type: SharingIfaceType, callback: AsyncCallback\ { +import SharingIfaceType from '@ohos.net.sharing' +sharing.getSharableRegexes(SharingIfaceType.SHARING_WIFI, (error, data) => { console.log(JSON.stringify(error)); console.log(JSON.stringify(data)); }); @@ -537,9 +575,11 @@ getSharableRegexes(type: SharingIfaceType): Promise\> Obtains regular expressions of NICs of a specified type. This API uses a promise to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -564,15 +604,17 @@ sharing.getSharableRegexes(SharingIfaceType.SHARING_WIFI).then(data => { }); ``` -## on('sharingStateChange') +## sharing.on('sharingStateChange') on(type: 'sharingStateChange', callback: Callback\): void Subscribes to network sharing state changes. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -590,15 +632,17 @@ sharing.on('sharingStateChange', (error, data) => { }); ``` -## off('sharingStateChange') +## sharing.off('sharingStateChange') off(type: 'sharingStateChange', callback?: Callback\): void Unsubscribes from network sharing state changes. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -616,15 +660,17 @@ sharing.off('sharingStateChange', (error, data) => { }); ``` -## on('interfaceSharingStateChange') +## sharing.on('interfaceSharingStateChange') on(type: 'interfaceSharingStateChange', callback: Callback\<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void Subscribes to network sharing state changes of a specified NIC. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -642,21 +688,23 @@ sharing.on('interfaceSharingStateChange', (error, data) => { }); ``` -## off('interfaceSharingStateChange') +## sharing.off('interfaceSharingStateChange') off(type: 'interfaceSharingStateChange', callback?: Callback\<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void Unsubscribes from network sharing status changes of a specified NIC. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------- | ---- | ---------- | -| type | string | No | Event name.| +| type | string | Yes | Event name.| | callback | AsyncCallback\<{ type: [SharingIfaceType](#sharingifacetype), iface: string, state: SharingIfaceState(#sharingifacestate) }> | No | Callback used for unsubscription.| **Example** @@ -668,15 +716,17 @@ sharing.off('interfaceSharingStateChange', (error, data) => { }); ``` -## on('sharingUpstreamChange') +## sharing.on('sharingUpstreamChange') on(type: 'sharingUpstreamChange', callback: Callback\): void Subscribes to upstream network changes. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -694,15 +744,17 @@ sharing.on('sharingUpstreamChange', (error, data) => { }); ``` -## off('sharingUpstreamChange') +## sharing.off('sharingUpstreamChange') off(type: 'sharingUpstreamChange', callback?: Callback\): void Unsubscribes from upstream network changes. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing **Parameters** @@ -724,7 +776,9 @@ sharing.off('sharingUpstreamChange', (error, data) => { Enumerates the network sharing states of an NIC. -**System capability**: SystemCapability.Communication.NetManager.Core +**System API**: This is a system API. + +**System capability**: SystemCapability.Communication.NetManager.NetSharing | Name | Value | Description | | ------------------------ | ---- | ---------------------- | @@ -734,12 +788,14 @@ Enumerates the network sharing states of an NIC. ## SharingIfaceType -Enumerates the network sharing types of an NIC. +Enumerates the network sharing types of an NIC. + +**System API**: This is a system API. -**System capability**: SystemCapability.Communication.NetManager.Core +**System capability**: SystemCapability.Communication.NetManager.NetSharing | Name | Value | Description | | ------------------------ | ---- | ---------------------- | | SHARING_WIFI | 0 | Wi-Fi hotspot sharing.| -| SHARING_USB | 1 | USB sharing.| +| SHARING_USB | 1 | USB sharing (not supported currently).| | SHARING_BLUETOOTH | 2 | Bluetooth sharing.| diff --git a/en/application-dev/reference/apis/js-apis-notification.md b/en/application-dev/reference/apis/js-apis-notification.md index 99dd6551d098ddf0d6f58a69bde92191e38d083d..9fdf5e1f345b68fcd99e6e027cfb0c44d5da29d8 100644 --- a/en/application-dev/reference/apis/js-apis-notification.md +++ b/en/application-dev/reference/apis/js-apis-notification.md @@ -2,11 +2,11 @@ The **Notification** module provides notification management capabilities, covering notifications, notification slots, notification subscription, notification enabled status, and notification badge status. -Generally, only system applications have the permission to subscribe to and unsubscribe from notifications. - > **NOTE** > > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> +> Notification subscription and unsubscription APIs are available only to system applications. ## Modules to Import @@ -26,8 +26,8 @@ Publishes a notification. This API uses an asynchronous callback to return the r | Name | Type | Mandatory| Description | | -------- | ------------------------------------------- | ---- | ------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| -| callback | AsyncCallback\ | Yes | Callback used to return the result. | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. | **Example** @@ -69,7 +69,7 @@ Publishes a notification. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | -------- | ------------------------------------------- | ---- | ------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| **Example** @@ -87,7 +87,7 @@ var notificationRequest = { } } Notification.publish(notificationRequest).then(() => { - console.info("publish sucess"); + console.info("publish success"); }); ``` @@ -96,7 +96,7 @@ Notification.publish(notificationRequest).then(() => { publish(request: NotificationRequest, userId: number, callback: AsyncCallback\): void -Publishes a notification. This API uses an asynchronous callback to return the result. +Publishes a notification to a specified user. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -108,8 +108,8 @@ Publishes a notification. This API uses an asynchronous callback to return the r | Name | Type | Mandatory| Description | | -------- | ----------------------------------------- | ---- | ------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| -| userId | number | Yes | ID of the user who receives the notification. | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| userId | number | Yes | User ID. | | callback | AsyncCallback\ | Yes | Callback used to return the result. | **Example** @@ -123,7 +123,7 @@ function publishCallback(err) { console.info("publish success"); } } -// ID of the user who receives the notification +// User ID var userId = 1 // NotificationRequest object var notificationRequest = { @@ -144,7 +144,7 @@ Notification.publish(notificationRequest, userId, publishCallback); publish(request: NotificationRequest, userId: number): Promise\ -Publishes a notification. This API uses a promise to return the result. +Publishes a notification to a specified user. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -156,8 +156,8 @@ Publishes a notification. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | -------- | ----------------------------------------- | ---- | ------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| -| userId | number | Yes | ID of the user who receives the notification. | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| userId | number | Yes | User ID. | **Example** @@ -177,7 +177,7 @@ var notificationRequest = { var userId = 1 Notification.publish(notificationRequest, userId).then(() => { - console.info("publish sucess"); + console.info("publish success"); }); ``` @@ -218,7 +218,7 @@ Notification.cancel(0, "label", cancelCallback) cancel(id: number, label?: string): Promise\ -Cancels a notification with the specified ID and label. This API uses a promise to return the result. +Cancels a notification with the specified ID and optional label. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -233,7 +233,7 @@ Cancels a notification with the specified ID and label. This API uses a promise ```js Notification.cancel(0).then(() => { - console.info("cancel sucess"); + console.info("cancel success"); }); ``` @@ -312,7 +312,7 @@ Cancels all notifications. This API uses a promise to return the result. ```js Notification.cancelAll().then(() => { - console.info("cancelAll sucess"); + console.info("cancelAll success"); }); ``` @@ -383,7 +383,7 @@ var notificationSlot = { type: Notification.SlotType.SOCIAL_COMMUNICATION } Notification.addSlot(notificationSlot).then(() => { - console.info("addSlot sucess"); + console.info("addSlot success"); }); ``` @@ -393,7 +393,7 @@ Notification.addSlot(notificationSlot).then(() => { addSlot(type: SlotType, callback: AsyncCallback\): void -Adds a notification slot. This API uses an asynchronous callback to return the result. +Adds a notification slot of a specified type. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -424,7 +424,7 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack addSlot(type: SlotType): Promise\ -Adds a notification slot. This API uses a promise to return the result. +Adds a notification slot of a specified type. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -438,7 +438,7 @@ Adds a notification slot. This API uses a promise to return the result. ```js Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => { - console.info("addSlot sucess"); + console.info("addSlot success"); }); ``` @@ -448,7 +448,7 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => { addSlots(slots: Array\, callback: AsyncCallback\): void -Adds multiple notification slots. This API uses an asynchronous callback to return the result. +Adds an array of notification slots. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -491,7 +491,7 @@ Notification.addSlots(notificationSlotArray, addSlotsCallBack) addSlots(slots: Array\): Promise\ -Adds multiple notification slots. This API uses a promise to return the result. +Adds an array of notification slots. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -517,7 +517,7 @@ var notificationSlotArray = new Array(); notificationSlotArray[0] = notificationSlot; Notification.addSlots(notificationSlotArray).then(() => { - console.info("addSlots sucess"); + console.info("addSlots success"); }); ``` @@ -527,7 +527,7 @@ Notification.addSlots(notificationSlotArray).then(() => { getSlot(slotType: SlotType, callback: AsyncCallback\): void -Obtains a notification slot of the specified type. This API uses an asynchronous callback to return the result. +Obtains a notification slot of a specified type. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -542,7 +542,7 @@ Obtains a notification slot of the specified type. This API uses an asynchronous ```js // getSlot callback -function getSlotCallback(err,data) { +function getSlotCallback(err, data) { if (err.code) { console.info("getSlot failed " + JSON.stringify(err)); } else { @@ -559,7 +559,7 @@ Notification.getSlot(slotType, getSlotCallback) getSlot(slotType: SlotType): Promise\ -Obtains a notification slot of the specified type. This API uses a promise to return the result. +Obtains a notification slot of a specified type. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -580,7 +580,7 @@ Obtains a notification slot of the specified type. This API uses a promise to re ```js var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; Notification.getSlot(slotType).then((data) => { - console.info("getSlot sucess, data: " + JSON.stringify(data)); + console.info("getSlot success, data: " + JSON.stringify(data)); }); ``` @@ -604,7 +604,7 @@ Obtains all notification slots. This API uses an asynchronous callback to return ```js // getSlots callback -function getSlotsCallback(err,data) { +function getSlotsCallback(err, data) { if (err.code) { console.info("getSlots failed " + JSON.stringify(err)); } else { @@ -634,7 +634,7 @@ Obtains all notification slots of this application. This API uses a promise to r ```js Notification.getSlots().then((data) => { - console.info("getSlots sucess, data: " + JSON.stringify(data)); + console.info("getSlots success, data: " + JSON.stringify(data)); }); ``` @@ -644,7 +644,7 @@ Notification.getSlots().then((data) => { removeSlot(slotType: SlotType, callback: AsyncCallback\): void -Removes a notification slot of the specified type. This API uses an asynchronous callback to return the result. +Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -676,7 +676,7 @@ Notification.removeSlot(slotType,removeSlotCallback) removeSlot(slotType: SlotType): Promise\ -Removes a notification slot of the specified type. This API uses a promise to return the result. +Removes a notification slot of a specified type. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -691,7 +691,7 @@ Removes a notification slot of the specified type. This API uses a promise to re ```js var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; Notification.removeSlot(slotType).then(() => { - console.info("removeSlot sucess"); + console.info("removeSlot success"); }); ``` @@ -738,7 +738,7 @@ Removes all notification slots. This API uses a promise to return the result. ```js Notification.removeAllSlots().then(() => { - console.info("removeAllSlots sucess"); + console.info("removeAllSlots success"); }); ``` @@ -761,7 +761,7 @@ Subscribes to a notification with the subscription information specified. This A | Name | Type | Mandatory| Description | | ---------- | ------------------------- | ---- | ---------------- | | subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | -| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Subscription information. | +| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Notification subscription information.| | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -782,7 +782,7 @@ var subscriber = { onConsume: onConsumeCallback } var info = { - bundleNames: ["bundleName1","bundleName2"] + bundleNames: ["bundleName1", "bundleName2"] } Notification.subscribe(subscriber, info, subscribeCallback); ``` @@ -793,7 +793,7 @@ Notification.subscribe(subscriber, info, subscribeCallback); subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\): void -Subscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result. +Subscribes to notifications of all applications under this user. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -846,7 +846,7 @@ Subscribes to a notification with the subscription information specified. This A | Name | Type | Mandatory| Description | | ---------- | ------------------------- | ---- | ------------ | | subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.| -| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | No | Subscription information. | +| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | No | Notification subscription information. | **Example** @@ -858,7 +858,7 @@ var subscriber = { onConsume: onConsumeCallback }; Notification.subscribe(subscriber).then(() => { - console.info("subscribe sucess"); + console.info("subscribe success"); }); ``` @@ -893,11 +893,11 @@ function unsubscribeCallback(err) { console.info("unsubscribe success"); } } -function onCancelCallback(data) { +function onDisconnectCallback(data) { console.info("Cancel callback: " + JSON.stringify(data)); } var subscriber = { - onCancel: onCancelCallback + onDisconnect: onDisconnectCallback } Notification.unsubscribe(subscriber, unsubscribeCallback); ``` @@ -925,14 +925,14 @@ Unsubscribes from a notification. This API uses a promise to return the result. **Example** ```js -function onCancelCallback(data) { +function onDisconnectCallback(data) { console.info("Cancel callback: " + JSON.stringify(data)); } var subscriber = { - onCancel: onCancelCallback + onDisconnect: onDisconnectCallback }; Notification.unsubscribe(subscriber).then(() => { - console.info("unsubscribe sucess"); + console.info("unsubscribe success"); }); ``` @@ -942,7 +942,7 @@ Notification.unsubscribe(subscriber).then(() => { enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void -Sets whether to enable notification for a specified bundle. This API uses an asynchronous callback to return the result. +Sets whether to enable notification for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -954,7 +954,7 @@ Sets whether to enable notification for a specified bundle. This API uses an asy | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | -------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | enable | boolean | Yes | Whether to enable notification. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -980,7 +980,7 @@ Notification.enableNotification(bundle, false, enableNotificationCallback); enableNotification(bundle: BundleOption, enable: boolean): Promise\ -Sets whether to enable notification for a specified bundle. This API uses a promise to return the result. +Sets whether to enable notification for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -992,7 +992,7 @@ Sets whether to enable notification for a specified bundle. This API uses a prom | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| | enable | boolean | Yes | Whether to enable notification. | **Example** @@ -1002,7 +1002,7 @@ var bundle = { bundle: "bundleName1", } Notification.enableNotification(bundle, false).then(() => { - console.info("enableNotification sucess"); + console.info("enableNotification success"); }); ``` @@ -1012,7 +1012,7 @@ Notification.enableNotification(bundle, false).then(() => { isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\): void -Checks whether notification is enabled for a specified bundle. This API uses an asynchronous callback to return the result. +Checks whether notification is enabled for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1024,7 +1024,7 @@ Checks whether notification is enabled for a specified bundle. This API uses an | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | ------------------------ | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -1049,7 +1049,7 @@ Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback); isNotificationEnabled(bundle: BundleOption): Promise\ -Checks whether notification is enabled for a specified bundle. This API uses a promise to return the result. +Checks whether notification is enabled for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1061,12 +1061,12 @@ Checks whether notification is enabled for a specified bundle. This API uses a p | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Type | Description | +| ------------------ | --------------------------------------------------- | | Promise\ | Promise used to return the result.| **Example** @@ -1076,7 +1076,7 @@ var bundle = { bundle: "bundleName1", } Notification.isNotificationEnabled(bundle).then((data) => { - console.info("isNotificationEnabled sucess, data: " + JSON.stringify(data)); + console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); }); ``` @@ -1132,7 +1132,7 @@ Checks whether notification is enabled for this application. This API uses a pro | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| **Return value** @@ -1144,7 +1144,7 @@ Checks whether notification is enabled for this application. This API uses a pro ```js Notification.isNotificationEnabled().then((data) => { - console.info("isNotificationEnabled sucess, data: " + JSON.stringify(data)); + console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); }); ``` @@ -1154,7 +1154,7 @@ Notification.isNotificationEnabled().then((data) => { displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void -Sets whether to enable the notification badge for a specified bundle. This API uses an asynchronous callback to return the result. +Sets whether to enable the notification badge for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1166,7 +1166,7 @@ Sets whether to enable the notification badge for a specified bundle. This API u | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | -------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | enable | boolean | Yes | Whether to enable notification. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -1192,7 +1192,7 @@ Notification.displayBadge(bundle, false, displayBadgeCallback); displayBadge(bundle: BundleOption, enable: boolean): Promise\ -Sets the notification slot for a specified bundle. This API uses a promise to return the result. +Sets whether to enable the notification badge for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1204,7 +1204,7 @@ Sets the notification slot for a specified bundle. This API uses a promise to re | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| | enable | boolean | Yes | Whether to enable notification. | **Example** @@ -1214,7 +1214,7 @@ var bundle = { bundle: "bundleName1", } Notification.displayBadge(bundle, false).then(() => { - console.info("displayBadge sucess"); + console.info("displayBadge success"); }); ``` @@ -1224,7 +1224,7 @@ Notification.displayBadge(bundle, false).then(() => { isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\): void -Checks whether the notification badge is enabled for a specified bundle. This API uses an asynchronous callback to return the result. +Checks whether the notification badge is enabled for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1236,7 +1236,7 @@ Checks whether the notification badge is enabled for a specified bundle. This AP | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | ------------------------ | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -1261,7 +1261,7 @@ Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); isBadgeDisplayed(bundle: BundleOption): Promise\ -Checks whether the notification badge is enabled for a specified bundle. This API uses a promise to return the result. +Checks whether the notification badge is enabled for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1273,7 +1273,7 @@ Checks whether the notification badge is enabled for a specified bundle. This AP | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| **Return value** @@ -1288,7 +1288,7 @@ var bundle = { bundle: "bundleName1", } Notification.isBadgeDisplayed(bundle).then((data) => { - console.info("isBadgeDisplayed sucess, data: " + JSON.stringify(data)); + console.info("isBadgeDisplayed success, data: " + JSON.stringify(data)); }); ``` @@ -1298,7 +1298,7 @@ Notification.isBadgeDisplayed(bundle).then((data) => { setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\): void -Sets the notification slot for a specified bundle. This API uses an asynchronous callback to return the result. +Sets the notification slot for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1310,7 +1310,7 @@ Sets the notification slot for a specified bundle. This API uses an asynchronous | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | -------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | slot | [NotificationSlot](#notificationslot) | Yes | Notification slot. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -1339,7 +1339,7 @@ Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\ -Sets the notification slot for a specified bundle. This API uses a promise to return the result. +Sets the notification slot for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1351,8 +1351,8 @@ Sets the notification slot for a specified bundle. This API uses a promise to re | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| -| slot | [NotificationSlot](#notificationslot) | Yes | Whether to enable notification. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| +| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot.| **Example** @@ -1364,7 +1364,7 @@ var notificationSlot = { type: Notification.SlotType.SOCIAL_COMMUNICATION } Notification.setSlotByBundle(bundle, notificationSlot).then(() => { - console.info("setSlotByBundle sucess"); + console.info("setSlotByBundle success"); }); ``` @@ -1374,7 +1374,7 @@ Notification.setSlotByBundle(bundle, notificationSlot).then(() => { getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>): void -Obtains the notification slots of a specified bundle. This API uses an asynchronous callback to return the result. +Obtains the notification slots of a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1386,7 +1386,7 @@ Obtains the notification slots of a specified bundle. This API uses an asynchron | Name | Type | Mandatory| Description | | -------- | ---------------------------------------- | ---- | -------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | callback | AsyncCallback> | Yes | Callback used to return the result.| **Example** @@ -1411,7 +1411,7 @@ Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback); getSlotsByBundle(bundle: BundleOption): Promise> -Obtains the notification slots of a specified bundle. This API uses a promise to return the result. +Obtains the notification slots of a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1423,7 +1423,7 @@ Obtains the notification slots of a specified bundle. This API uses a promise to | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| **Return value** @@ -1438,7 +1438,7 @@ var bundle = { bundle: "bundleName1", } Notification.getSlotsByBundle(bundle).then((data) => { - console.info("getSlotsByBundle sucess, data: " + JSON.stringify(data)); + console.info("getSlotsByBundle success, data: " + JSON.stringify(data)); }); ``` @@ -1448,7 +1448,7 @@ Notification.getSlotsByBundle(bundle).then((data) => { getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\): void -Obtains the number of notification slots of a specified bundle. This API uses an asynchronous callback to return the result. +Obtains the number of notification slots of a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1460,7 +1460,7 @@ Obtains the number of notification slots of a specified bundle. This API uses an | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -1485,7 +1485,7 @@ Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); getSlotNumByBundle(bundle: BundleOption): Promise\ -Obtains the number of notification slots of a specified bundle. This API uses a promise to return the result. +Obtains the number of notification slots of a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1497,7 +1497,7 @@ Obtains the number of notification slots of a specified bundle. This API uses a | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| **Return value** @@ -1512,7 +1512,7 @@ var bundle = { bundle: "bundleName1", } Notification.getSlotNumByBundle(bundle).then((data) => { - console.info("getSlotNumByBundle sucess, data: " + JSON.stringify(data)); + console.info("getSlotNumByBundle success, data: " + JSON.stringify(data)); }); ``` @@ -1534,7 +1534,7 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal | Name | Type | Mandatory| Description | | --------------- | ----------------------------------| ---- | -------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | | reason | [RemoveReason](#removereason9) | Yes | Indicates the reason for deleting a notification. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -1578,7 +1578,7 @@ Removes a notification for a specified bundle. This API uses a promise to return | Name | Type | Mandatory| Description | | --------------- | --------------- | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| | notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | | reason | [RemoveReason](#removereason9) | Yes | Reason for deleting the notification. | @@ -1594,7 +1594,7 @@ var notificationKey = { } var reason = Notification.RemoveReason.CLICK_REASON_REMOVE; Notification.remove(bundle, notificationKey, reason).then(() => { - console.info("remove sucess"); + console.info("remove success"); }); ``` @@ -1616,7 +1616,7 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | -------------------- | -| hashCode | string | Yes | Unique notification ID. | +| hashCode | string | Yes | Unique notification ID. It is the **hashCode** in the [NotificationRequest](#notificationrequest) object of [SubscribeCallbackData](#subscribecallbackdata) of the [onConsume](#onconsume) callback.| | reason | [RemoveReason](#removereason9) | Yes | Indicates the reason for deleting a notification. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -1663,7 +1663,7 @@ Removes a notification for a specified bundle. This API uses a promise to return var hashCode = 'hashCode' var reason = Notification.RemoveReason.CLICK_REASON_REMOVE; Notification.remove(hashCode, reason).then(() => { - console.info("remove sucess"); + console.info("remove success"); }); ``` @@ -1673,7 +1673,7 @@ Notification.remove(hashCode, reason).then(() => { removeAll(bundle: BundleOption, callback: AsyncCallback\): void -Removes all notifications for a specified bundle. This API uses an asynchronous callback to return the result. +Removes all notifications for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1685,7 +1685,7 @@ Removes all notifications for a specified bundle. This API uses an asynchronous | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | ---------------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -1744,7 +1744,7 @@ Notification.removeAll(removeAllCallback); removeAll(bundle?: BundleOption): Promise\ -Removes all notifications for a specified user. This API uses a promise to return the result. +Removes all notifications for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1756,13 +1756,14 @@ Removes all notifications for a specified user. This API uses a promise to retur | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | No | Bundle information.| +| bundle | [BundleOption](#bundleoption) | No | Bundle information of the application.| **Example** ```js +// If no application is specified, notifications of all applications are deleted. Notification.removeAll().then(() => { - console.info("removeAll sucess"); + console.info("removeAll success"); }); ``` @@ -1782,7 +1783,7 @@ Removes all notifications for a specified user. This API uses an asynchronous ca | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| userId | number | Yes | ID of the user who receives the notification.| +| userId | number | Yes | User ID.| | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -1797,7 +1798,6 @@ function removeAllCallback(err) { } var userId = 1 - Notification.removeAll(userId, removeAllCallback); ``` @@ -1817,22 +1817,15 @@ Removes all notifications for a specified user. This API uses a promise to retur | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| userId | number | Yes | ID of the user who receives the notification.| +| userId | number | Yes | User ID.| **Example** ```js -function removeAllCallback(err) { - if (err.code) { - console.info("removeAll failed " + JSON.stringify(err)); - } else { - console.info("removeAll success"); - } -} - var userId = 1 - -Notification.removeAll(userId, removeAllCallback); +Notification.removeAll(userId).then(() => { + console.info("removeAll success"); +}); ``` @@ -1892,7 +1885,7 @@ Obtains all active notifications. This API uses a promise to return the result. ```js Notification.getAllActiveNotifications().then((data) => { - console.info("getAllActiveNotifications sucess, data: " + JSON.stringify(data)); + console.info("getAllActiveNotifications success, data: " + JSON.stringify(data)); }); ``` @@ -1902,7 +1895,7 @@ Notification.getAllActiveNotifications().then((data) => { getActiveNotificationCount(callback: AsyncCallback\): void -Obtains the number of active notifications. This API uses an asynchronous callback to return the result. +Obtains the number of active notifications of this application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1932,21 +1925,21 @@ Notification.getActiveNotificationCount(getActiveNotificationCountCallback); getActiveNotificationCount(): Promise\ -Obtains the number of active notifications. This API uses a promise to return the result. +Obtains the number of active notifications of this application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Type | Description | +| ----------------- | ------------------------------------------- | | Promise\ | Promise used to return the result.| **Example** ```js Notification.getActiveNotificationCount().then((data) => { - console.info("getActiveNotificationCount sucess, data: " + JSON.stringify(data)); + console.info("getActiveNotificationCount success, data: " + JSON.stringify(data)); }); ``` @@ -1992,15 +1985,15 @@ Obtains active notifications of this application. This API uses a promise to ret **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Type | Description | +| ------------------------------------------------------------ | --------------------------------------- | | Promise\\> | Promise used to return the result.| **Example** ```js Notification.getActiveNotifications().then((data) => { - console.info("removeGroupByBundle sucess, data: " + JSON.stringify(data)); + console.info("removeGroupByBundle success, data: " + JSON.stringify(data)); }); ``` @@ -2010,7 +2003,7 @@ Notification.getActiveNotifications().then((data) => { cancelGroup(groupName: string, callback: AsyncCallback\): void -Cancels a notification group of this application. This API uses an asynchronous callback to return the result. +Cancels notifications under a notification group of this application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2018,7 +2011,7 @@ Cancels a notification group of this application. This API uses an asynchronous | Name | Type | Mandatory| Description | | --------- | --------------------- | ---- | ---------------------------- | -| groupName | string | Yes | Name of the notification group. | +| groupName | string | Yes | Name of the notification group, which is specified through [NotificationRequest](#notificationrequest) when the notification is published.| | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -2043,7 +2036,7 @@ Notification.cancelGroup(groupName, cancelGroupCallback); cancelGroup(groupName: string): Promise\ -Cancels a notification group of this application. This API uses a promise to return the result. +Cancels notifications under a notification group of this application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2058,7 +2051,7 @@ Cancels a notification group of this application. This API uses a promise to ret ```js var groupName = "GroupName"; Notification.cancelGroup(groupName).then(() => { - console.info("cancelGroup sucess"); + console.info("cancelGroup success"); }); ``` @@ -2068,7 +2061,7 @@ Notification.cancelGroup(groupName).then(() => { removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\): void -Removes a notification group for a specified bundle. This API uses an asynchronous callback to return the result. +Removes notifications under a notification group of a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2080,7 +2073,7 @@ Removes a notification group for a specified bundle. This API uses an asynchrono | Name | Type | Mandatory| Description | | --------- | --------------------- | ---- | ---------------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | groupName | string | Yes | Name of the notification group. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -2107,7 +2100,7 @@ Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCal removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\ -Removes a notification group for a specified bundle. This API uses a promise to return the result. +Removes notifications under a notification group of a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2119,7 +2112,7 @@ Removes a notification group for a specified bundle. This API uses a promise to | Name | Type | Mandatory| Description | | --------- | ------------ | ---- | -------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | groupName | string | Yes | Name of the notification group.| **Example** @@ -2128,7 +2121,7 @@ Removes a notification group for a specified bundle. This API uses a promise to var bundleOption = {bundle: "Bundle"}; var groupName = "GroupName"; Notification.removeGroupByBundle(bundleOption, groupName).then(() => { - console.info("removeGroupByBundle sucess"); + console.info("removeGroupByBundle success"); }); ``` @@ -2202,7 +2195,7 @@ var doNotDisturbDate = { end: new Date(2021, 11, 15, 18, 0) } Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { - console.info("setDoNotDisturbDate sucess"); + console.info("setDoNotDisturbDate success"); }); ``` @@ -2224,7 +2217,7 @@ Sets the DND time for a specified user. This API uses an asynchronous callback t | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | ---------------------- | | date | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set. | -| userId | number | Yes | User ID.| +| userId | number | Yes | ID of the user for whom you want to set the DND time.| | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -2245,7 +2238,6 @@ var doNotDisturbDate = { } var userId = 1 - Notification.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback); ``` @@ -2268,7 +2260,7 @@ Sets the DND time for a specified user. This API uses a promise to return the re | Name | Type | Mandatory| Description | | ------ | ---------------- | ---- | -------------- | | date | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set.| -| userId | number | Yes | User ID.| +| userId | number | Yes | ID of the user for whom you want to set the DND time.| **Example** @@ -2282,7 +2274,7 @@ var doNotDisturbDate = { var userId = 1 Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => { - console.info("setDoNotDisturbDate sucess"); + console.info("setDoNotDisturbDate success"); }); ``` @@ -2308,7 +2300,7 @@ Obtains the DND time. This API uses an asynchronous callback to return the resul **Example** ```js -function getDoNotDisturbDateCallback(err,data) { +function getDoNotDisturbDateCallback(err, data) { if (err.code) { console.info("getDoNotDisturbDate failed " + JSON.stringify(err)); } else { @@ -2335,15 +2327,15 @@ Obtains the DND time. This API uses a promise to return the result. **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Type | Description | +| ------------------------------------------------- | ----------------------------------------- | | Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | Promise used to return the result.| **Example** ```js Notification.getDoNotDisturbDate().then((data) => { - console.info("getDoNotDisturbDate sucess, data: " + JSON.stringify(data)); + console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); }); ``` @@ -2405,8 +2397,8 @@ Obtains the DND time of a specified user. This API uses a promise to return the **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Type | Description | +| ------------------------------------------------- | ----------------------------------------- | | Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | Promise used to return the result.| **Example** @@ -2415,7 +2407,7 @@ Obtains the DND time of a specified user. This API uses a promise to return the var userId = 1 Notification.getDoNotDisturbDate(userId).then((data) => { - console.info("getDoNotDisturbDate sucess, data: " + JSON.stringify(data)); + console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); }); ``` @@ -2424,7 +2416,7 @@ Notification.getDoNotDisturbDate(userId).then((data) => { supportDoNotDisturbMode(callback: AsyncCallback\): void -Checks whether the DND mode is supported. This API uses an asynchronous callback to return the result. +Checks whether DND mode is supported. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2458,7 +2450,7 @@ Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback); supportDoNotDisturbMode(): Promise\ -Checks whether the DND mode is supported. This API uses a promise to return the result. +Checks whether DND mode is supported. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2476,7 +2468,7 @@ Checks whether the DND mode is supported. This API uses a promise to return the ```js Notification.supportDoNotDisturbMode().then((data) => { - console.info("supportDoNotDisturbMode sucess, data: " + JSON.stringify(data)); + console.info("supportDoNotDisturbMode success, data: " + JSON.stringify(data)); }); ``` @@ -2567,7 +2559,7 @@ function requestEnableNotificationCallback(err) { if (err.code) { console.info("requestEnableNotification failed " + JSON.stringify(err)); } else { - + console.info("requestEnableNotification success"); } }; @@ -2587,10 +2579,9 @@ Requests notification to be enabled for this application. This API uses a promis **Example** ```javascript -Notification.requestEnableNotification() - .then(() => { - console.info("requestEnableNotification sucess"); - }); +Notification.requestEnableNotification().then(() => { + console.info("requestEnableNotification success"); +}); ``` @@ -2610,7 +2601,7 @@ Sets whether this device supports distributed notifications. This API uses an as | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | -------------------------- | -| enable | boolean | Yes | Whether the device supports distributed notifications.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| +| enable | boolean | Yes | Whether the device supports distributed notifications.| | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -2647,17 +2638,15 @@ Sets whether this device supports distributed notifications. This API uses a pro | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | -------------------------- | -| enable | boolean | Yes | Whether the device supports distributed notifications.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| +| enable | boolean | Yes | Whether the device supports distributed notifications.| **Example** ```javascript var enable = true - -Notification.enableDistributed(enable) - .then(() => { - console.info("enableDistributed sucess"); - }); +Notification.enableDistributed(enable).then(() => { + console.info("enableDistributed success"); +}); ``` @@ -2665,7 +2654,7 @@ Notification.enableDistributed(enable) isDistributedEnabled(callback: AsyncCallback\): void -Obtains whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. +Checks whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2695,23 +2684,22 @@ Notification.isDistributedEnabled(isDistributedEnabledCallback); isDistributedEnabled(): Promise\ -Obtains whether this device supports distributed notifications. This API uses a promise to return the result. +Checks whether this device supports distributed notifications. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification **Return value** -| Type | Description | -| ------------------ | --------------- | -| Promise\ | Promise used to return the result.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| +| Type | Description | +| ------------------ | --------------------------------------------- | +| Promise\ | Promise used to return the result.| **Example** ```javascript -Notification.isDistributedEnabled() - .then((data) => { - console.info("isDistributedEnabled sucess, data: " + JSON.stringify(data)); - }); +Notification.isDistributedEnabled().then((data) => { + console.info("isDistributedEnabled success, data: " + JSON.stringify(data)); +}); ``` @@ -2719,7 +2707,7 @@ Notification.isDistributedEnabled() enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void -Sets whether an application supports distributed notifications based on the bundle. This API uses an asynchronous callback to return the result. +Sets whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2731,7 +2719,7 @@ Sets whether an application supports distributed notifications based on the bund | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | -------------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Application bundle. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | enable | boolean | Yes | Whether the device supports distributed notifications. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -2761,7 +2749,7 @@ Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundle enableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise\ -Sets whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result. +Sets whether a specified application supports distributed notifications. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2784,11 +2772,9 @@ var bundle = { } var enable = true - -Notification.enableDistributedByBundle(bundle, enable) - .then(() => { - console.info("enableDistributedByBundle sucess"); - }); +Notification.enableDistributedByBundle(bundle, enable).then(() => { + console.info("enableDistributedByBundle success"); +}); ``` ## Notification.isDistributedEnabledByBundle8+ @@ -2834,7 +2820,7 @@ Notification.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCa isDistributedEnabledByBundle(bundle: BundleOption): Promise\ -Obtains whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result. +Checks whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2850,9 +2836,9 @@ Obtains whether an application supports distributed notifications based on the b **Return value** -| Type | Description | -| ------------------ | --------------- | -| Promise\ | Promise used to return the result.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| +| Type | Description | +| ------------------ | ------------------------------------------------- | +| Promise\ | Promise used to return the result.| **Example** @@ -2861,10 +2847,9 @@ var bundle = { bundle: "bundleName1", } -Notification.isDistributedEnabledByBundle(bundle) - .then((data) => { - console.info("isDistributedEnabledByBundle sucess, data: " + JSON.stringify(data)); - }); +Notification.isDistributedEnabledByBundle(bundle).then((data) => { + console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data)); +}); ``` @@ -2923,10 +2908,9 @@ Obtains the notification reminder type. This API uses a promise to return the re **Example** ```javascript -Notification.getDeviceRemindType() - .then((data) => { - console.info("getDeviceRemindType sucess, data: " + JSON.stringify(data)); - }); +Notification.getDeviceRemindType().then((data) => { + console.info("getDeviceRemindType success, data: " + JSON.stringify(data)); +}); ``` @@ -2944,18 +2928,18 @@ Publishes an agent-powered notification. This API uses an asynchronous callback **Parameters** -| Name | Type | Mandatory| Description | -| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| -| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | -| userId | number | Yes | ID of the user who receives the notification. | -| callback | AsyncCallback | Yes | Callback used to return the result. | +| Name | Type | Mandatory| Description | +| -------------------- | ------------------------------------------- | ---- | ---------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | +| userId | number | Yes | User ID. | +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -// Callback for publishAsBundle -function publishAsBundleCallback(err) { +// publishAsBundle callback +function callback(err) { if (err.code) { console.info("publishAsBundle failed " + JSON.stringify(err)); } else { @@ -2964,10 +2948,10 @@ function publishAsBundleCallback(err) { } // Bundle name of the application whose notification function is taken over by the reminder agent let representativeBundle = "com.example.demo" -// ID of the user who receives the notification +// User ID let userId = 100 // NotificationRequest object -let notificationRequest = { +let request = { id: 1, content: { contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, @@ -2979,7 +2963,7 @@ let notificationRequest = { } } -Notification.publishAsBundle(notificationRequest, representativeBundle, userId, publishAsBundleCallback); +Notification.publishAsBundle(request, representativeBundle, userId, callback); ``` ## Notification.publishAsBundle9+ @@ -2999,19 +2983,19 @@ Publishes a notification through the reminder agent. This API uses a promise to | Name | Type | Mandatory| Description | | -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | -| userId | number | Yes | ID of the user who receives the notification. | +| userId | number | Yes | User ID. | **Example** ```js // Bundle name of the application whose notification function is taken over by the reminder agent let representativeBundle = "com.example.demo" -// ID of the user who receives the notification +// User ID let userId = 100 // NotificationRequest object -var notificationRequest = { +var request = { id: 1, content: { contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, @@ -3023,8 +3007,8 @@ var notificationRequest = { } } -Notification.publishAsBundle(notificationRequest, representativeBundle, userId).then(() => { - console.info("publishAsBundle sucess"); +Notification.publishAsBundle(request, representativeBundle, userId).then(() => { + console.info("publishAsBundle success"); }); ``` @@ -3048,13 +3032,13 @@ Cancels a notification published by the reminder agent. This API uses an asynchr | -------------------- | ------------- | ---- | ------------------------ | | id | number | Yes | Notification ID. | | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | -| userId | number | Yes | ID of the user who receives the notification. | +| userId | number | Yes | User ID. | | callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -//cancelAsBundle +// cancelAsBundle function cancelAsBundleCallback(err) { if (err.code) { console.info("cancelAsBundle failed " + JSON.stringify(err)); @@ -3064,7 +3048,7 @@ function cancelAsBundleCallback(err) { } // Bundle name of the application whose notification function is taken over by the reminder agent let representativeBundle = "com.example.demo" -// ID of the user who receives the notification +// User ID let userId = 100 Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback); @@ -3074,7 +3058,7 @@ Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallb cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\ -Publishes a notification through the reminder agent. This API uses a promise to return the result. +Cancels a notification published by the reminder agent. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3090,14 +3074,14 @@ Publishes a notification through the reminder agent. This API uses a promise to | -------------------- | ------ | ---- | ------------------ | | id | number | Yes | Notification ID. | | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent.| -| userId | number | Yes | ID of the user who receives the notification.| +| userId | number | Yes | User ID.| **Example** ```js // Bundle name of the application whose notification function is taken over by the reminder agent let representativeBundle = "com.example.demo" -// ID of the user who receives the notification +// User ID let userId = 100 Notification.cancelAsBundle(0, representativeBundle, userId).then(() => { @@ -3109,7 +3093,7 @@ Notification.cancelAsBundle(0, representativeBundle, userId).then(() => { enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\): void -Sets the enabled status for a notification slot of a specified type. This API uses an asynchronous callback to return the result. +Sets the enabled status of a notification slot type for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3121,7 +3105,7 @@ Sets the enabled status for a notification slot of a specified type. This API us | Name | Type | Mandatory| Description | | -------- | ----------------------------- | ---- | ---------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | type | [SlotType](#slottype) | Yes | Notification slot type. | | enable | boolean | Yes | Whether to enable notification. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -3129,7 +3113,7 @@ Sets the enabled status for a notification slot of a specified type. This API us **Example** ```js -//enableNotificationSlot +// enableNotificationSlot function enableSlotCallback(err) { if (err.code) { console.info("enableNotificationSlot failed " + JSON.stringify(err)); @@ -3149,7 +3133,7 @@ Notification.enableNotificationSlot( enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise\ -Sets the enabled status for a notification slot of a specified type. This API uses a promise to return the result. +Sets the enabled status of a notification slot type for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3161,27 +3145,25 @@ Sets the enabled status for a notification slot of a specified type. This API us | Name| Type | Mandatory| Description | | ------ | ----------------------------- | ---- | -------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | type | [SlotType](#slottype) | Yes | Notification slot type.| | enable | boolean | Yes | Whether to enable notification. | **Example** ```js -//enableNotificationSlot -Notification.enableNotificationSlot( - { bundle: "ohos.samples.notification", }, - Notification.SlotType.SOCIAL_COMMUNICATION, - true).then(() => { - console.info("enableNotificationSlot sucess"); - }); +// enableNotificationSlot +Notification.enableNotificationSlot({ bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION,true).then(() => { + console.info("enableNotificationSlot success"); +}); ``` ## Notification.isNotificationSlotEnabled 9+ isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\): void -Obtains the enabled status of the notification slot of a specified type. This API uses an asynchronous callback to return the result. +Checks whether a specified notification slot type is enabled for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3193,14 +3175,14 @@ Obtains the enabled status of the notification slot of a specified type. This AP | Name | Type | Mandatory| Description | | -------- | ----------------------------- | ---- | ---------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | type | [SlotType](#slottype) | Yes | Notification slot type. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** ```js -//isNotificationSlotEnabled +// isNotificationSlotEnabled function getEnableSlotCallback(err, data) { if (err.code) { console.info("isNotificationSlotEnabled failed " + JSON.stringify(err)); @@ -3219,7 +3201,7 @@ Notification.isNotificationSlotEnabled( isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\ -Obtains the enabled status of the notification slot of a specified type. This API uses a promise to return the result. +Checks whether a specified notification slot type is enabled for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3231,25 +3213,23 @@ Obtains the enabled status of the notification slot of a specified type. This AP | Name| Type | Mandatory| Description | | ------ | ----------------------------- | ---- | -------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | type | [SlotType](#slottype) | Yes | Notification slot type.| **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | -| Promise\ | Promise used to return the enabled status of the notification slot of the specified type.| +| Type | Description | +| ------------------ | ------------------------------- | +| Promise\ | Promise used to return the result.| **Example** ```js -//isNotificationSlotEnabled -Notification.isNotificationSlotEnabled( - { bundle: "ohos.samples.notification", }, - Notification.SlotType.SOCIAL_COMMUNICATION - ).then((data) => { - console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data)); - }); +// isNotificationSlotEnabled +Notification.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION).then((data) => { + console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data)); +}); ``` @@ -3257,7 +3237,7 @@ Notification.isNotificationSlotEnabled( setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\): void -Sets whether to sync notifications to devices where the application is not installed. This API uses an asynchronous callback to return the result. +Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3270,7 +3250,7 @@ Sets whether to sync notifications to devices where the application is not insta | Name| Type | Mandatory| Description | | ------ | ----------------------------- | ---- | -------------- | | userId | number | Yes | User ID. | -| enable | boolean | Yes | Whether the feature is enabled.
**true**: enabled
**false**: disabled | +| enable | boolean | Yes | Whether the feature is enabled. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -3279,7 +3259,7 @@ Sets whether to sync notifications to devices where the application is not insta let userId = 100; let enable = true; -function setSyncNotificationEnabledWithoutAppCallback(err) { +function callback(err) { if (err.code) { console.info("setSyncNotificationEnabledWithoutApp failed " + JSON.stringify(err)); } else { @@ -3287,7 +3267,7 @@ function setSyncNotificationEnabledWithoutAppCallback(err) { } } -Notification.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotificationEnabledWithoutAppCallback); +Notification.setSyncNotificationEnabledWithoutApp(userId, enable, callback); ``` @@ -3295,7 +3275,7 @@ Notification.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotific setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\ -Sets whether to sync notifications to devices where the application is not installed. This API uses a promise to return the result. +Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3308,7 +3288,7 @@ Sets whether to sync notifications to devices where the application is not insta | Name| Type | Mandatory| Description | | ------ | ----------------------------- | ---- | -------------- | | userId | number | Yes | User ID. | -| enable | boolean | Yes | Whether the feature is enabled.
**true**: enabled
**false**: disabled | +| enable | boolean | Yes | Whether the feature is enabled. | **Return value** @@ -3322,13 +3302,11 @@ Sets whether to sync notifications to devices where the application is not insta let userId = 100; let enable = true; -Notification.setSyncNotificationEnabledWithoutApp(userId, enable) - .then(() => { - console.info('setSyncNotificationEnabledWithoutApp'); - }) - .catch((err) => { - console.info('setSyncNotificationEnabledWithoutApp, err:', err); - }); +Notification.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => { + console.info('setSyncNotificationEnabledWithoutApp success'); +}).catch((err) => { + console.info('setSyncNotificationEnabledWithoutApp, err:' + JSON.stringify(err)); +}); ``` @@ -3336,7 +3314,7 @@ Notification.setSyncNotificationEnabledWithoutApp(userId, enable) getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\): void -Obtains whether notifications are synced to devices where the application is not installed. This API uses an asynchronous callback to return the result. +Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3349,18 +3327,18 @@ Obtains whether notifications are synced to devices where the application is not | Name| Type | Mandatory| Description | | ------ | ----------------------------- | ---- | -------------- | | userId | number | Yes | User ID. | -| callback | AsyncCallback\ | Yes | Callback used to return the result.
**true**: Notifications are synced to devices where the application is not installed.
**false**: Notifications are not synced to devices where the application is not installed.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** ```js let userId = 100; -function getSyncNotificationEnabledWithoutAppCallback(data, err) { +function getSyncNotificationEnabledWithoutAppCallback(err, data) { if (err) { - console.info('getSyncNotificationEnabledWithoutAppCallback, err' + err); + console.info('getSyncNotificationEnabledWithoutAppCallback, err:' + err); } else { - console.info('getSyncNotificationEnabledWithoutAppCallback, data' + data); + console.info('getSyncNotificationEnabledWithoutAppCallback, data:' + data); } } @@ -3372,7 +3350,7 @@ Notification.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEna getSyncNotificationEnabledWithoutApp(userId: number): Promise\ -Obtains whether notifications are synced to devices where the application is not installed. This API uses a promise to return the result. +Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3388,29 +3366,26 @@ Obtains whether notifications are synced to devices where the application is not **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | -| Promise\ | Promise used to return the result.
**true**: Notifications are synced to devices where the application is not installed.
**false**: Notifications are not synced to devices where the application is not installed.| +| Type | Description | +| ------------------ | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| **Example** ```js let userId = 100; - -Notification.getSyncNotificationEnabledWithoutApp(userId) - .then((data) => { - console.info('getSyncNotificationEnabledWithoutApp, data:', data); - }) - .catch((err) => { - console.info('getSyncNotificationEnabledWithoutApp, err:', err); - }); +Notification.getSyncNotificationEnabledWithoutApp(userId).then((data) => { + console.info('getSyncNotificationEnabledWithoutApp, data:' + data); +}).catch((err) => { + console.info('getSyncNotificationEnabledWithoutApp, err:' + err); +}); ``` ## NotificationSubscriber -Provides callbacks for receiving or removing notifications. +Provides callbacks for receiving or removing notifications and serves as the input parameter of [subscribe](#notificationsubscribe). **System API**: This is a system API and cannot be called by third-party applications. @@ -3428,7 +3403,7 @@ Callback for receiving notifications. | Name| Type| Mandatory| Description| | ------------ | ------------------------ | ---- | -------------------------- | -| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Notification information returned.| +| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification received.| **Example** @@ -3442,7 +3417,6 @@ function subscribeCallback(err) { }; function onConsumeCallback(data) { - console.info('===> onConsume in test'); let req = data.request; console.info('===> onConsume callback req.id:' + req.id); }; @@ -3458,7 +3432,7 @@ Notification.subscribe(subscriber, subscribeCallback); onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) => void -Callback for removing notifications. +Callback for canceling notifications. **System capability**: SystemCapability.Notification.Notification @@ -3468,7 +3442,7 @@ Callback for removing notifications. | Name| Type| Mandatory| Description| | ------------ | ------------------------ | ---- | -------------------------- | -| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Notification information returned.| +| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification to cancel.| **Example** @@ -3482,7 +3456,6 @@ function subscribeCallback(err) { }; function onCancelCallback(data) { - console.info('===> onCancel in test'); let req = data.request; console.info('===> onCancel callback req.id:' + req.id); } @@ -3508,7 +3481,7 @@ Callback for notification sorting updates. | Name| Type| Mandatory| Description| | ------------ | ------------------------ | ---- | -------------------------- | -| data | [NotificationSortingMap](#notificationsortingmap) | Yes| Notification information returned.| +| data | [NotificationSortingMap](#notificationsortingmap) | Yes| Latest notification sorting list.| **Example** @@ -3521,8 +3494,8 @@ function subscribeCallback(err) { } }; -function onUpdateCallback() { - console.info('===> onUpdate in test'); +function onUpdateCallback(map) { + console.info('===> onUpdateCallback map:' + JSON.stringify(map)); } var subscriber = { @@ -3584,16 +3557,30 @@ function subscribeCallback(err) { console.info("subscribeCallback"); } }; +function unsubscribeCallback(err) { + if (err.code) { + console.info("unsubscribe failed " + JSON.stringify(err)); + } else { + console.info("unsubscribeCallback"); + } +}; +function onConnectCallback() { + console.info('===> onConnect in test'); +} function onDisconnectCallback() { console.info('===> onDisconnect in test'); } var subscriber = { + onConnect: onConnectCallback, onDisconnect: onDisconnectCallback }; +// The onConnect callback is invoked when subscription to the notification is complete. Notification.subscribe(subscriber, subscribeCallback); +// The onDisconnect callback is invoked when unsubscription to the notification is complete. +Notification.unsubscribe(subscriber, unsubscribeCallback); ``` ### onDestroy @@ -3654,15 +3641,24 @@ function subscribeCallback(err) { } }; -function onDoNotDisturbDateChangeCallback() { - console.info('===> onDoNotDisturbDateChange in test'); +function onDoNotDisturbDateChangeCallback(mode) { + console.info('===> onDoNotDisturbDateChange:' + mode); } var subscriber = { onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback }; - Notification.subscribe(subscriber, subscribeCallback); + +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} +// Set the onDoNotDisturbDateChange callback for DND time setting updates. +Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { + console.info("setDoNotDisturbDate sucess"); +}); ``` @@ -3670,7 +3666,7 @@ Notification.subscribe(subscriber, subscribeCallback); onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata8)) => void -Listens for the notification enable status changes. This API uses an asynchronous callback to return the result. +Listens for the notification enabled status changes. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3694,16 +3690,23 @@ function subscribeCallback(err) { }; function onEnabledNotificationChangedCallback(callbackData) { - console.info("bundle: ", callbackData.bundle); - console.info("uid: ", callbackData.uid); - console.info("enable: ", callbackData.enable); + console.info("bundle: " + callbackData.bundle); + console.info("uid: " + callbackData.uid); + console.info("enable: " + callbackData.enable); }; var subscriber = { onEnabledNotificationChanged: onEnabledNotificationChangedCallback }; - Notification.subscribe(subscriber, subscribeCallback); + +var bundle = { + bundle: "bundleName1", +} +// Set the onEnabledNotificationChanged callback that is triggered when the notification enabled status changes. +Notification.enableNotification(bundle, false).then(() => { + console.info("enableNotification sucess"); +}); ``` ## SubscribeCallbackData @@ -3740,13 +3743,11 @@ Notification.subscribe(subscriber, subscribeCallback); **System API**: This is a system API and cannot be called by third-party applications. -| Name | Type | Readable| Writable| Description | -| ----- ------------------------------------- || ---- | --- | ------------------------ | -| type | [DoNotDisturbType](#donotdisturbtype8) | Yes | No | DND time type.| -| begin | Date | Yes | No | DND start time.| -| end | Date | Yes | No | DND end time.| - - +| Name | Type | Readable| Writable| Description | +| ----- | -------------------------------------- | ---- | ---- | ---------------------- | +| type | [DoNotDisturbType](#donotdisturbtype8) | Yes | Yes | DND time type.| +| begin | Date | Yes | Yes | DND start time.| +| end | Date | Yes | Yes | DND end time.| ## DoNotDisturbType8+ @@ -3793,7 +3794,7 @@ Notification.subscribe(subscriber, subscribeCallback); | Name | Type | Readable| Writable| Description | | ------ | ------ |---- | --- | ------ | -| bundle | string | Yes | Yes | Bundle name. | +| bundle | string | Yes | Yes | Bundle information of the application.| | uid | number | Yes | Yes | User ID.| @@ -3823,14 +3824,14 @@ Notification.subscribe(subscriber, subscribeCallback); ## NotificationActionButton -Enumerates the buttons in the notification. +Describes the button displayed in the notification. **System capability**: SystemCapability.Notification.Notification | Name | Type | Readable| Writable| Description | | --------- | ----------------------------------------------- | --- | ---- | ------------------------- | | title | string | Yes | Yes | Button title. | -| wantAgent | WantAgent | Yes | Yes | **WantAgent** of the button.| +| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** of the button.| | extras | { [key: string]: any } | Yes | Yes | Extra information of the button. | | userInput8+ | [NotificationUserInput](#notificationuserinput8) | Yes | Yes | User input object. | @@ -3893,7 +3894,7 @@ Describes the picture-attached notification. | additionalText | string | Yes | Yes | Additional information of the notification.| | briefText | string | Yes | Yes | Brief text of the notification.| | expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. | -| picture | image.PixelMap | Yes | Yes | Picture attached to the notification. | +| picture | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Picture attached to the notification. | ## NotificationContent @@ -3934,8 +3935,8 @@ Enumerates notification flags. | Name | Type | Readable| Writable| Description | | ---------------- | ---------------------- | ---- | ---- | --------------------------------- | -| soundEnabled | NotificationFlagStatus | Yes | No | Whether to enable the sound alert for the notification. | -| vibrationEnabled | NotificationFlagStatus | Yes | No | Whether to enable vibration for the notification. | +| soundEnabled | [NotificationFlagStatus](#notificationflagstatus8) | Yes | No | Whether to enable the sound alert for the notification. | +| vibrationEnabled | [NotificationFlagStatus](#notificationflagstatus8) | Yes | No | Whether to enable vibration for the notification. | ## NotificationRequest @@ -3954,48 +3955,47 @@ Describes the notification request. | deliveryTime | number | Yes | Yes | Time when the notification is sent. | | tapDismissed | boolean | Yes | Yes | Whether the notification is automatically cleared. | | autoDeletedTime | number | Yes | Yes | Time when the notification is automatically cleared. | -| wantAgent | WantAgent | Yes | Yes | **WantAgent** instance to which the notification will be redirected after being clicked. | +| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected after being clicked. | | extraInfo | {[key: string]: any} | Yes | Yes | Extended parameters. | -| color | number | Yes | Yes | Background color of the notification. Not supported currently. | -| colorEnabled | boolean | Yes | Yes | Whether the notification background color is enabled. Not supported currently. | +| color | number | Yes | Yes | Background color of the notification. Not supported currently.| +| colorEnabled | boolean | Yes | Yes | Whether the notification background color is enabled. Not supported currently.| | isAlertOnce | boolean | Yes | Yes | Whether the notification triggers an alert only once.| | isStopwatch | boolean | Yes | Yes | Whether to display the stopwatch. | | isCountDown | boolean | Yes | Yes | Whether to display the countdown time. | -| isFloatingIcon | boolean | Yes | Yes | Whether the notification is displayed as a floating icon. | +| isFloatingIcon | boolean | Yes | Yes | Whether the notification is displayed as a floating icon in the status bar. | | label | string | Yes | Yes | Notification label. | | badgeIconStyle | number | Yes | Yes | Notification badge type. | | showDeliveryTime | boolean | Yes | Yes | Whether to display the time when the notification is delivered. | | actionButtons | Array\<[NotificationActionButton](#notificationactionbutton)\> | Yes | Yes | Buttons in the notification. Up to two buttons are allowed. | -| smallIcon | PixelMap | Yes | Yes | Small notification icon. | -| largeIcon | PixelMap | Yes | Yes | Large notification icon. | +| smallIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Small notification icon. This field is optional, and the icon size cannot exceed 30 KB.| +| largeIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Large notification icon. This field is optional, and the icon size cannot exceed 30 KB.| | creatorBundleName | string | Yes | No | Name of the bundle that creates the notification. | | creatorUid | number | Yes | No | UID used for creating the notification. | | creatorPid | number | Yes | No | PID used for creating the notification. | | creatorUserId8+| number | Yes | No | ID of the user who creates the notification. | | hashCode | string | Yes | No | Unique ID of the notification. | | classification | string | Yes | Yes | Notification category.
**System API**: This is a system API and cannot be called by third-party applications. | -| groupName8+| string | Yes | Yes | Group notification name. | +| groupName8+| string | Yes | Yes | Notification group name. | | template8+ | [NotificationTemplate](#notificationtemplate8) | Yes | Yes | Notification template. | | isRemoveAllowed8+ | boolean | Yes | No | Whether the notification can be removed.
**System API**: This is a system API and cannot be called by third-party applications. | | source8+ | number | Yes | No | Notification source.
**System API**: This is a system API and cannot be called by third-party applications. | -| distributedOption8+ | [DistributedOptions](#distributedoptions8) | Yes | Yes | Option of distributed notification. | +| distributedOption8+ | [DistributedOptions](#distributedoptions8) | Yes | Yes | Distributed notification options. | | deviceId8+ | string | Yes | No | Device ID of the notification source.
**System API**: This is a system API and cannot be called by third-party applications. | | notificationFlags8+ | [NotificationFlags](#notificationflags8) | Yes | No | Notification flags. | -| removalWantAgent9+ | WantAgent | Yes | Yes | **WantAgent** instance to which the notification will be redirected when it is removed. | +| removalWantAgent9+ | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected when it is removed. | | badgeNumber9+ | number | Yes | Yes | Number of notifications displayed on the application icon. | - ## DistributedOptions8+ -Describes distributed options. +Describes distributed notifications options. **System capability**: SystemCapability.Notification.Notification | Name | Type | Readable| Writable| Description | | ---------------------- | -------------- | ---- | ---- | ---------------------------------- | | isDistributed | boolean | Yes | Yes | Whether the notification is a distributed notification. | -| supportDisplayDevices | Array\ | Yes | Yes | Types of the devices to which the notification can be synchronized. | -| supportOperateDevices | Array\ | Yes | Yes | Devices on which notification can be enabled. | +| supportDisplayDevices | Array\ | Yes | Yes | List of the devices to which the notification can be synchronized. | +| supportOperateDevices | Array\ | Yes | Yes | List of the devices on which the notification can be opened. | | remindType | number | Yes | No | Notification reminder type.
**System API**: This is a system API and cannot be called by third-party applications. | @@ -4011,14 +4011,14 @@ Describes the notification slot. | level | number | Yes | Yes | Notification level. If this parameter is not set, the default value is used based on the notification slot type.| | desc | string | Yes | Yes | Notification slot description. | | badgeFlag | boolean | Yes | Yes | Whether to display the badge. | -| bypassDnd | boolean | Yes | Yes | Whether to bypass the DND mode in the system. | +| bypassDnd | boolean | Yes | Yes | Whether to bypass DND mode in the system. | | lockscreenVisibility | number | Yes | Yes | Mode for displaying the notification on the lock screen. | -| vibrationEnabled | boolean | Yes | Yes | Whether vibration is supported for the notification. | +| vibrationEnabled | boolean | Yes | Yes | Whether vibration is enabled for the notification. | | sound | string | Yes | Yes | Notification alert tone. | | lightEnabled | boolean | Yes | Yes | Whether the indicator blinks for the notification. | | lightColor | number | Yes | Yes | Indicator color of the notification. | | vibrationValues | Array\ | Yes | Yes | Vibration mode of the notification. | -| enabled9+ | boolean | Yes | No | Enabled status of the notification slot. | +| enabled9+ | boolean | Yes | No | Whether the notification slot is enabled. | ## NotificationSorting @@ -4066,7 +4066,7 @@ Provides the information about the publisher for notification subscription. ## NotificationTemplate8+ -Notification template. +Describes the notification template. **System capability**: SystemCapability.Notification.Notification @@ -4121,5 +4121,5 @@ Provides the notification user input. | Name | Value | Description | | -------------------- | --- | -------------------- | -| CLICK_REASON_REMOVE | 1 | The notification is removed due to a click on it. | +| CLICK_REASON_REMOVE | 1 | The notification is removed after a click on it. | | CANCEL_REASON_REMOVE | 2 | The notification is removed by the user. | diff --git a/en/application-dev/reference/apis/js-apis-notificationManager.md b/en/application-dev/reference/apis/js-apis-notificationManager.md new file mode 100644 index 0000000000000000000000000000000000000000..2d8f497bede97cc9c6d1a8d408b6e80770a2396f --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-notificationManager.md @@ -0,0 +1,3968 @@ +# @ohos.notificationManager + +The **notificationManager** module provides notification management capabilities, covering notifications, notification slots, notification enabled status, and notification badge status. + +> **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 Notification from '@ohos.notificationManager'; +``` + +## Notification.publish + +publish(request: NotificationRequest, callback: AsyncCallback\): void + +Publishes a notification. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------- | ---- | ------------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +// publish callback +function publishCallback(err) { + if (err) { + console.info("publish failed " + JSON.stringify(err)); + } else { + console.info("publish success"); + } +} +// NotificationRequest object +var notificationRequest = { + id: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} +Notification.publish(notificationRequest, publishCallback) +``` + + + +## Notification.publish + +publish(request: NotificationRequest): Promise\ + +Publishes a notification. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------- | ---- | ------------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +// NotificationRequest object +var notificationRequest = { + notificationId: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} +Notification.publish(notificationRequest).then(() => { + console.info("publish success"); +}); + +``` + +## Notification.publish + +publish(request: NotificationRequest, userId: number, callback: AsyncCallback\): void + +Publishes a notification to a specified user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------- | ---- | ------------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| userId | number | Yes | User ID. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600008 | The user is not exist. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +// publish callback +function publishCallback(err) { + if (err) { + console.info("publish failed " + JSON.stringify(err)); + } else { + console.info("publish success"); + } +} +// User ID +var userId = 1 +// NotificationRequest object +var notificationRequest = { + id: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} +Notification.publish(notificationRequest, userId, publishCallback); +``` + +## Notification.publish + +publish(request: NotificationRequest, userId: number): Promise\ + +Publishes a notification to a specified user. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------- | ---- | ------------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| userId | number | Yes | User ID. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600008 | The user is not exist. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +var notificationRequest = { + notificationId: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} + +var userId = 1 + +Notification.publish(notificationRequest, userId).then(() => { + console.info("publish success"); +}); +``` + + +## Notification.cancel + +cancel(id: number, label: string, callback: AsyncCallback\): void + +Cancels a notification with the specified ID and label. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| id | number | Yes | Notification ID. | +| label | string | Yes | Notification label. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | + +**Example** + +```js +// cancel callback +function cancelCallback(err) { + if (err) { + console.info("cancel failed " + JSON.stringify(err)); + } else { + console.info("cancel success"); + } +} +Notification.cancel(0, "label", cancelCallback) +``` + + + +## Notification.cancel + +cancel(id: number, label?: string): Promise\ + +Cancels a notification with the specified ID and optional label. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| ----- | ------ | ---- | -------- | +| id | number | Yes | Notification ID. | +| label | string | No | Notification label.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | + +**Example** + +```js +Notification.cancel(0).then(() => { + console.info("cancel success"); +}); +``` + + + +## Notification.cancel + +cancel(id: number, callback: AsyncCallback\): void + +Cancels a notification with the specified ID. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| id | number | Yes | Notification ID. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | + +**Example** + +```js +// cancel callback +function cancelCallback(err) { + if (err) { + console.info("cancel failed " + JSON.stringify(err)); + } else { + console.info("cancel success"); + } +} +Notification.cancel(0, cancelCallback) +``` + + + +## Notification.cancelAll + +cancelAll(callback: AsyncCallback\): void + +Cancels all notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +// cancel callback +function cancelAllCallback(err) { + if (err) { + console.info("cancelAll failed " + JSON.stringify(err)); + } else { + console.info("cancelAll success"); + } +} +Notification.cancelAll(cancelAllCallback) +``` + + + +## Notification.cancelAll + +cancelAll(): Promise\ + +Cancels all notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.cancelAll().then(() => { + console.info("cancelAll success"); +}); +``` + + + +## Notification.addSlot + +addSlot(slot: NotificationSlot, callback: AsyncCallback\): void + +Adds a notification slot. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// addSlot callback +function addSlotCallBack(err) { + if (err) { + console.info("addSlot failed " + JSON.stringify(err)); + } else { + console.info("addSlot success"); + } +} +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.addSlot(notificationSlot, addSlotCallBack) +``` + + + +## Notification.addSlot + +addSlot(slot: NotificationSlot): Promise\ + +Adds a notification slot. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type | Mandatory| Description | +| ---- | ---------------- | ---- | -------------------- | +| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.addSlot(notificationSlot).then(() => { + console.info("addSlot success"); +}); +``` + + + +## Notification.addSlot + +addSlot(type: SlotType, callback: AsyncCallback\): void + +Adds a notification slot of a specified type. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ---------------------- | +| type | [SlotType](#slottype) | Yes | Type of the notification slot to add.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// addSlot callback +function addSlotCallBack(err) { + if (err) { + console.info("addSlot failed " + JSON.stringify(err)); + } else { + console.info("addSlot success"); + } +} +Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack) +``` + + + +## Notification.addSlot + +addSlot(type: SlotType): Promise\ + +Adds a notification slot of a specified type. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name| Type | Mandatory| Description | +| ---- | -------- | ---- | ---------------------- | +| type | [SlotType](#slottype) | Yes | Type of the notification slot to add.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => { + console.info("addSlot success"); +}); +``` + + + +## Notification.addSlots + +addSlots(slots: Array\, callback: AsyncCallback\): void + +Adds an array of notification slots. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ------------------------ | +| slots | Array\<[NotificationSlot](#notificationslot)\> | Yes | Notification slots to add.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// addSlots callback +function addSlotsCallBack(err) { + if (err) { + console.info("addSlots failed " + JSON.stringify(err)); + } else { + console.info("addSlots success"); + } +} +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +// NotificationSlotArray object +var notificationSlotArray = new Array(); +notificationSlotArray[0] = notificationSlot; + +Notification.addSlots(notificationSlotArray, addSlotsCallBack) +``` + + + +## Notification.addSlots + +addSlots(slots: Array\): Promise\ + +Adds an array of notification slots. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ----- | ------------------------- | ---- | ------------------------ | +| slots | Array\<[NotificationSlot](#notificationslot)\> | Yes | Notification slots to add.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +// NotificationSlotArray object +var notificationSlotArray = new Array(); +notificationSlotArray[0] = notificationSlot; + +Notification.addSlots(notificationSlotArray).then(() => { + console.info("addSlots success"); +}); +``` + + + +## Notification.getSlot + +getSlot(slotType: SlotType, callback: AsyncCallback\): void + +Obtains a notification slot of a specified type. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ----------------------------------------------------------- | +| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| +| callback | AsyncCallback\<[NotificationSlot](#notificationslot)\> | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// getSlot callback +function getSlotCallback(err,data) { + if (err) { + console.info("getSlot failed " + JSON.stringify(err)); + } else { + console.info("getSlot success"); + } +} +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.getSlot(slotType, getSlotCallback) +``` + + + +## Notification.getSlot + +getSlot(slotType: SlotType): Promise\ + +Obtains a notification slot of a specified type. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------- | ---- | ----------------------------------------------------------- | +| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.getSlot(slotType).then((data) => { + console.info("getSlot success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.getSlots + +getSlots(callback: AsyncCallback>): void + +Obtains all notification slots of this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | -------------------- | +| callback | AsyncCallback\\> | Yes | Callback used to return all notification slots of the current application.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// getSlots callback +function getSlotsCallback(err,data) { + if (err) { + console.info("getSlots failed " + JSON.stringify(err)); + } else { + console.info("getSlots success"); + } +} +Notification.getSlots(getSlotsCallback) +``` + + + +## Notification.getSlots + +getSlots(): Promise\> + +Obtains all notification slots of this application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\\> | Promise used to return all notification slots of the current application.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.getSlots().then((data) => { + console.info("getSlots success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.removeSlot + +removeSlot(slotType: SlotType, callback: AsyncCallback\): void + +Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ----------------------------------------------------------- | +| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// removeSlot callback +function removeSlotCallback(err) { + if (err) { + console.info("removeSlot failed " + JSON.stringify(err)); + } else { + console.info("removeSlot success"); + } +} +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.removeSlot(slotType,removeSlotCallback) +``` + + + +## Notification.removeSlot + +removeSlot(slotType: SlotType): Promise\ + +Removes a notification slot of a specified type. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------- | ---- | ----------------------------------------------------------- | +| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.removeSlot(slotType).then(() => { + console.info("removeSlot success"); +}); +``` + + + +## Notification.removeAllSlots + +removeAllSlots(callback: AsyncCallback\): void + +Removes all notification slots. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function removeAllCallBack(err) { + if (err) { + console.info("removeAllSlots failed " + JSON.stringify(err)); + } else { + console.info("removeAllSlots success"); + } +} +Notification.removeAllSlots(removeAllCallBack) +``` + + + +## Notification.removeAllSlots + +removeAllSlots(): Promise\ + +Removes all notification slots. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.removeAllSlots().then(() => { + console.info("removeAllSlots success"); +}); +``` + + + +## Notification.setNotificationEnable + +setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void + +Sets whether to enable notification for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| enable | boolean | Yes | Whether to enable notification. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function setNotificationEnablenCallback(err) { + if (err) { + console.info("setNotificationEnablenCallback failed " + JSON.stringify(err)); + } else { + console.info("setNotificationEnablenCallback success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.setNotificationEnable(bundle, false, setNotificationEnablenCallback); +``` + + + +## Notification.setNotificationEnable + +setNotificationEnable(bundle: BundleOption, enable: boolean): Promise\ + +Sets whether to enable notification for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| +| enable | boolean | Yes | Whether to enable notification. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.setNotificationEnable(bundle, false).then(() => { + console.info("setNotificationEnable success"); +}); +``` + + + +## Notification.isNotificationEnabled + +isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\): void + +Checks whether notification is enabled for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ------------------------ | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function isNotificationEnabledCallback(err, data) { + if (err) { + console.info("isNotificationEnabled failed " + JSON.stringify(err)); + } else { + console.info("isNotificationEnabled success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback); +``` + + + +## Notification.isNotificationEnabled + +isNotificationEnabled(bundle: BundleOption): Promise\ + +Checks whether notification is enabled for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| + +**Return value** + +| Type | Description | +| ------------------ | --------------------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.isNotificationEnabled(bundle).then((data) => { + console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.isNotificationEnabled + +isNotificationEnabled(callback: AsyncCallback\): void + +Checks whether notification is enabled for this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ------------------------ | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function isNotificationEnabledCallback(err, data) { + if (err) { + console.info("isNotificationEnabled failed " + JSON.stringify(err)); + } else { + console.info("isNotificationEnabled success"); + } +} + +Notification.isNotificationEnabled(isNotificationEnabledCallback); +``` + + + +## Notification.isNotificationEnabled + +isNotificationEnabled(): Promise\ + +Checks whether notification is enabled for the current application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +Notification.isNotificationEnabled().then((data) => { + console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.displayBadge + +displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void + +Sets whether to enable the notification badge for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| enable | boolean | Yes | Whether to enable notification. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function displayBadgeCallback(err) { + if (err) { + console.info("displayBadge failed " + JSON.stringify(err)); + } else { + console.info("displayBadge success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.displayBadge(bundle, false, displayBadgeCallback); +``` + + + +## Notification.displayBadge + +displayBadge(bundle: BundleOption, enable: boolean): Promise\ + +Sets whether to enable the notification badge for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| +| enable | boolean | Yes | Whether to enable notification. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.displayBadge(bundle, false).then(() => { + console.info("displayBadge success"); +}); +``` + + + +## Notification.isBadgeDisplayed + +isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\): void + +Checks whether the notification badge is enabled for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ------------------------ | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function isBadgeDisplayedCallback(err, data) { + if (err) { + console.info("isBadgeDisplayed failed " + JSON.stringify(err)); + } else { + console.info("isBadgeDisplayed success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); +``` + + + +## Notification.isBadgeDisplayed + +isBadgeDisplayed(bundle: BundleOption): Promise\ + +Checks whether the notification badge is enabled for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.isBadgeDisplayed(bundle).then((data) => { + console.info("isBadgeDisplayed success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.setSlotByBundle + +setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\): void + +Sets the notification slot for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + + + +**Example** + +```js +function setSlotByBundleCallback(err) { + if (err) { + console.info("setSlotByBundle failed " + JSON.stringify(err)); + } else { + console.info("setSlotByBundle success"); + } +} +var bundle = { + bundle: "bundleName1", +} +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); +``` + + + +## Notification.setSlotByBundle + +setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\ + +Sets the notification slot for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| +| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.setSlotByBundle(bundle, notificationSlot).then(() => { + console.info("setSlotByBundle success"); +}); +``` + + + +## Notification.getSlotsByBundle + +getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>): void + +Obtains the notification slots of a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------------- | ---- | -------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| callback | AsyncCallback> | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function getSlotsByBundleCallback(err, data) { + if (err) { + console.info("getSlotsByBundle failed " + JSON.stringify(err)); + } else { + console.info("getSlotsByBundle success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback); +``` + + + +## Notification.getSlotsByBundle + +getSlotsByBundle(bundle: BundleOption): Promise> + +Obtains the notification slots of a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.getSlotsByBundle(bundle).then((data) => { + console.info("getSlotsByBundle success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.getSlotNumByBundle + +getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\): void + +Obtains the number of notification slots of a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function getSlotNumByBundleCallback(err, data) { + if (err) { + console.info("getSlotNumByBundle failed " + JSON.stringify(err)); + } else { + console.info("getSlotNumByBundle success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); +``` + + + +## Notification.getSlotNumByBundle + +getSlotNumByBundle(bundle: BundleOption): Promise\ + +Obtains the number of notification slots of a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.getSlotNumByBundle(bundle).then((data) => { + console.info("getSlotNumByBundle success, data: " + JSON.stringify(data)); +}); +``` + + + + +## Notification.getAllActiveNotifications + +getAllActiveNotifications(callback: AsyncCallback>): void + +Obtains all active notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | -------------------- | +| callback | AsyncCallback> | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function getAllActiveNotificationsCallback(err, data) { + if (err) { + console.info("getAllActiveNotifications failed " + JSON.stringify(err)); + } else { + console.info("getAllActiveNotifications success"); + } +} + +Notification.getAllActiveNotifications(getAllActiveNotificationsCallback); +``` + + + +## Notification.getAllActiveNotifications + +getAllActiveNotifications(): Promise\\> + +Obtains all active notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\\> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.getAllActiveNotifications().then((data) => { + console.info("getAllActiveNotifications success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.getActiveNotificationCount + +getActiveNotificationCount(callback: AsyncCallback\): void + +Obtains the number of active notifications of this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ---------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function getActiveNotificationCountCallback(err, data) { + if (err) { + console.info("getActiveNotificationCount failed " + JSON.stringify(err)); + } else { + console.info("getActiveNotificationCount success"); + } +} + +Notification.getActiveNotificationCount(getActiveNotificationCountCallback); +``` + + + +## Notification.getActiveNotificationCount + +getActiveNotificationCount(): Promise\ + +Obtains the number of active notifications of this application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Return value** + +| Type | Description | +| ----------------- | ------------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.getActiveNotificationCount().then((data) => { + console.info("getActiveNotificationCount success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.getActiveNotifications + +getActiveNotifications(callback: AsyncCallback>): void + +Obtains active notifications of this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | +| callback | AsyncCallback> | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function getActiveNotificationsCallback(err, data) { + if (err) { + console.info("getActiveNotifications failed " + JSON.stringify(err)); + } else { + console.info("getActiveNotifications success"); + } +} + +Notification.getActiveNotifications(getActiveNotificationsCallback); +``` + + + +## Notification.getActiveNotifications + +getActiveNotifications(): Promise\\> + +Obtains active notifications of this application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Return value** + +| Type | Description | +| ------------------------------------------------------------ | --------------------------------------- | +| Promise\\> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.getActiveNotifications().then((data) => { + console.info("removeGroupByBundle success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.cancelGroup + +cancelGroup(groupName: string, callback: AsyncCallback\): void + +Cancels notifications under a notification group of this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | --------------------- | ---- | ---------------------------- | +| groupName | string | Yes | Name of the notification group, which is specified through [NotificationRequest](#notificationrequest) when the notification is published.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function cancelGroupCallback(err) { + if (err) { + console.info("cancelGroup failed " + JSON.stringify(err)); + } else { + console.info("cancelGroup success"); + } +} + +var groupName = "GroupName"; + +Notification.cancelGroup(groupName, cancelGroupCallback); +``` + + + +## Notification.cancelGroup + +cancelGroup(groupName: string): Promise\ + +Cancels notifications under a notification group of this application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | -------------- | +| groupName | string | Yes | Name of the notification group.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +var groupName = "GroupName"; +Notification.cancelGroup(groupName).then(() => { + console.info("cancelGroup success"); +}); +``` + + + +## Notification.removeGroupByBundle + +removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\): void + +Removes notifications under a notification group of a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | --------------------- | ---- | ---------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| groupName | string | Yes | Name of the notification group. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function removeGroupByBundleCallback(err) { + if (err) { + console.info("removeGroupByBundle failed " + JSON.stringify(err)); + } else { + console.info("removeGroupByBundle success"); + } +} + +var bundleOption = {bundle: "Bundle"}; +var groupName = "GroupName"; + +Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback); +``` + + + +## Notification.removeGroupByBundle + +removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\ + +Removes notifications under a notification group of a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | ------------ | ---- | -------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| groupName | string | Yes | Name of the notification group.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundleOption = {bundle: "Bundle"}; +var groupName = "GroupName"; +Notification.removeGroupByBundle(bundleOption, groupName).then(() => { + console.info("removeGroupByBundle success"); +}); +``` + + + +## Notification.setDoNotDisturbDate + +setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\): void + +Sets the DND time. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ---------------------- | +| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function setDoNotDisturbDateCallback(err) { + if (err) { + console.info("setDoNotDisturbDate failed " + JSON.stringify(err)); + } else { + console.info("setDoNotDisturbDate success"); + } +} + +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} + +Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback); +``` + + + +## Notification.setDoNotDisturbDate + +setDoNotDisturbDate(date: DoNotDisturbDate): Promise\ + +Sets the DND time. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type | Mandatory| Description | +| ---- | ---------------- | ---- | -------------- | +| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} +Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { + console.info("setDoNotDisturbDate success"); +}); +``` + + +## Notification.setDoNotDisturbDate + +setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback\): void + +Sets the DND time for a specified user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ---------------------- | +| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set. | +| userId | number | Yes | ID of the user for whom you want to set the DND time.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +function setDoNotDisturbDateCallback(err) { + if (err) { + console.info("setDoNotDisturbDate failed " + JSON.stringify(err)); + } else { + console.info("setDoNotDisturbDate success"); + } +} + +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} + +var userId = 1 + +Notification.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback); +``` + + + +## Notification.setDoNotDisturbDate + +setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\ + +Sets the DND time for a specified user. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ---------------- | ---- | -------------- | +| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set.| +| userId | number | Yes | ID of the user for whom you want to set the DND time.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} + +var userId = 1 + +Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => { + console.info("setDoNotDisturbDate success"); +}); +``` + + +## Notification.getDoNotDisturbDate + +getDoNotDisturbDate(callback: AsyncCallback\): void + +Obtains the DND time. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ---------------------- | +| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function getDoNotDisturbDateCallback(err,data) { + if (err) { + console.info("getDoNotDisturbDate failed " + JSON.stringify(err)); + } else { + console.info("getDoNotDisturbDate success"); + } +} + +Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback); +``` + + + +## Notification.getDoNotDisturbDate + +getDoNotDisturbDate(): Promise\ + +Obtains the DND time. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Return value** + +| Type | Description | +| ------------------------------------------------ | ----------------------------------------- | +| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.getDoNotDisturbDate().then((data) => { + console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); +}); +``` + + +## Notification.getDoNotDisturbDate + +getDoNotDisturbDate(userId: number, callback: AsyncCallback\): void + +Obtains the DND time of a specified user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ---------------------- | +| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes | Callback used to return the result.| +| userId | number | Yes | User ID.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +function getDoNotDisturbDateCallback(err,data) { + if (err) { + console.info("getDoNotDisturbDate failed " + JSON.stringify(err)); + } else { + console.info("getDoNotDisturbDate success"); + } +} + +var userId = 1 + +Notification.getDoNotDisturbDate(userId, getDoNotDisturbDateCallback); +``` + + + +## Notification.getDoNotDisturbDate + +getDoNotDisturbDate(userId: number): Promise\ + +Obtains the DND time of a specified user. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ---------------------- | +| userId | number | Yes | User ID.| + +**Return value** + +| Type | Description | +| ------------------------------------------------ | ----------------------------------------- | +| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +var userId = 1 + +Notification.getDoNotDisturbDate(userId).then((data) => { + console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); +}); +``` + + +## Notification.supportDoNotDisturbMode + +supportDoNotDisturbMode(callback: AsyncCallback\): void + +Checks whether DND mode is supported. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function supportDoNotDisturbModeCallback(err,data) { + if (err) { + console.info("supportDoNotDisturbMode failed " + JSON.stringify(err)); + } else { + console.info("supportDoNotDisturbMode success"); + } +} + +Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback); +``` + + + +## Notification.supportDoNotDisturbMode + +supportDoNotDisturbMode(): Promise\ + +Checks whether DND mode is supported. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.supportDoNotDisturbMode().then((data) => { + console.info("supportDoNotDisturbMode success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.isSupportTemplate + +isSupportTemplate(templateName: string, callback: AsyncCallback\): void + +Checks whether a specified template is supported. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ------------------------ | ---- | -------------------------- | +| templateName | string | Yes | Template name. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600011 | Read template config failed. | + +**Example** + +```javascript +var templateName = 'process'; +function isSupportTemplateCallback(err, data) { + if (err) { + console.info("isSupportTemplate failed " + JSON.stringify(err)); + } else { + console.info("isSupportTemplate success"); + } +} + +Notification.isSupportTemplate(templateName, isSupportTemplateCallback); +``` + + + +## Notification.isSupportTemplate + +isSupportTemplate(templateName: string): Promise\ + +Checks whether a specified template is supported. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ------ | ---- | -------- | +| templateName | string | Yes | Template name.| + +**Return value** + +| Type | Description | +| ------------------ | --------------- | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600011 | Read template config failed. | + +**Example** + +```javascript +var templateName = 'process'; + +Notification.isSupportTemplate(templateName).then((data) => { + console.info("isSupportTemplate success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.requestEnableNotification + +requestEnableNotification(callback: AsyncCallback\): void + +Requests notification to be enabled for this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```javascript +function requestEnableNotificationCallback(err) { + if (err) { + console.info("requestEnableNotification failed " + JSON.stringify(err)); + } else { + console.info("requestEnableNotification success"); + } +}; + +Notification.requestEnableNotification(requestEnableNotificationCallback); +``` + + + +## Notification.requestEnableNotification + +requestEnableNotification(): Promise\ + +Requests notification to be enabled for this application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```javascript +Notification.requestEnableNotification().then(() => { + console.info("requestEnableNotification success"); +}); +``` + + + +## Notification.setDistributedEnable + +setDistributedEnable(enable: boolean, callback: AsyncCallback\): void + +Sets whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| enable | boolean | Yes | Whether the device supports distributed notifications.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | + +**Example** + +```javascript +function setDistributedEnableCallback() { + if (err) { + console.info("setDistributedEnable failed " + JSON.stringify(err)); + } else { + console.info("setDistributedEnable success"); + } +}; + +var enable = true + +Notification.setDistributedEnable(enable, setDistributedEnableCallback); +``` + + + +## Notification.setDistributedEnable + +setDistributedEnable(enable: boolean): Promise\ + +Sets whether this device supports distributed notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| enable | boolean | Yes | Whether the device supports distributed notifications.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | + +**Example** + +```javascript +var enable = true + +Notification.setDistributedEnable(enable).then(() => { + console.info("setDistributedEnable success"); + }); +``` + + +## Notification.isDistributedEnabled + +isDistributedEnabled(callback: AsyncCallback\): void + +Checks whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | + +**Example** + +```javascript +function isDistributedEnabledCallback(err, data) { + if (err) { + console.info("isDistributedEnabled failed " + JSON.stringify(err)); + } else { + console.info("isDistributedEnabled success " + JSON.stringify(data)); + } +}; + +Notification.isDistributedEnabled(isDistributedEnabledCallback); +``` + + + +## Notification.isDistributedEnabled + +isDistributedEnabled(): Promise\ + +Checks whether this device supports distributed notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Return value** + +| Type | Description | +| ------------------ | --------------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | + +**Example** + +```javascript +Notification.isDistributedEnabled() + .then((data) => { + console.info("isDistributedEnabled success, data: " + JSON.stringify(data)); + }); +``` + + +## Notification.setDistributedEnableByBundle + +setDistributedEnableByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void + +Sets whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| enable | boolean | Yes | Whether the application supports distributed notifications. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```javascript +function setDistributedEnableByBundleCallback(err) { + if (err) { + console.info("enableDistributedByBundle failed " + JSON.stringify(err)); + } else { + console.info("enableDistributedByBundle success"); + } +}; + +var bundle = { + bundle: "bundleName1", +} + +var enable = true + +Notification.setDistributedEnableByBundle(bundle, enable, setDistributedEnableByBundleCallback); +``` + + + +## Notification.setDistributedEnableByBundle + +setDistributedEnableByBundle(bundle: BundleOption, enable: boolean): Promise\ + +Sets whether a specified application supports distributed notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| enable | boolean | Yes | Whether the application supports distributed notifications. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```javascript +var bundle = { + bundle: "bundleName1", +} + +var enable = true + +Notification.setDistributedEnableByBundle(bundle, enable).then(() => { + console.info("setDistributedEnableByBundle success"); + }); +``` + +## Notification.isDistributedEnabledByBundle + +isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\): void + +Checks whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```javascript +function isDistributedEnabledByBundleCallback(data) { + if (err) { + console.info("isDistributedEnabledByBundle failed " + JSON.stringify(err)); + } else { + console.info("isDistributedEnabledByBundle success" + JSON.stringify(data)); + } +}; + +var bundle = { + bundle: "bundleName1", +} + +Notification.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCallback); +``` + + + +## Notification.isDistributedEnabledByBundle + +isDistributedEnabledByBundle(bundle: BundleOption): Promise\ + +Checks whether a specified application supports distributed notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | + +**Return value** + +| Type | Description | +| ------------------ | ------------------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```javascript +var bundle = { + bundle: "bundleName1", +} + +Notification.isDistributedEnabledByBundle(bundle).then((data) => { + console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data)); +}); +``` + + +## Notification.getDeviceRemindType + +getDeviceRemindType(callback: AsyncCallback\): void + +Obtains the notification reminder type. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | -------------------------- | +| callback | AsyncCallback\<[DeviceRemindType](#deviceremindtype)\> | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```javascript +function getDeviceRemindTypeCallback(err, data) { + if (err) { + console.info("getDeviceRemindType failed " + JSON.stringify(err)); + } else { + console.info("getDeviceRemindType success"); + } +}; + +Notification.getDeviceRemindType(getDeviceRemindTypeCallback); +``` + + + +## Notification.getDeviceRemindType + +getDeviceRemindType(): Promise\ + +Obtains the notification reminder type. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Return value** + +| Type | Description | +| ------------------ | --------------- | +| Promise\<[DeviceRemindType](#deviceremindtype)\> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```javascript +Notification.getDeviceRemindType().then((data) => { + console.info("getDeviceRemindType success, data: " + JSON.stringify(data)); +}); +``` + + +## Notification.publishAsBundle + +publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number, callback: AsyncCallback\): void + +Publishes a notification through the reminder agent. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------------------- | ------------------------------------------- | ---- | ---------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | +| userId | number | Yes | User ID. | +| callback | AsyncCallback | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600008 | The user is not exist. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +// publishAsBundle callback +function callback(err) { + if (err) { + console.info("publishAsBundle failed " + JSON.stringify(err)); + } else { + console.info("publishAsBundle success"); + } +} +// Bundle name of the application whose notification function is taken over by the reminder agent +let representativeBundle = "com.example.demo" +// User ID +let userId = 100 +// NotificationRequest object +let request = { + id: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} + +Notification.publishAsBundle(request, representativeBundle, userId, callback); +``` + +## Notification.publishAsBundle + +publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number): Promise\ + +Publishes a notification through the reminder agent. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + + +| Name | Type | Mandatory| Description | +| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | +| userId | number | Yes | User ID. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600008 | The user is not exist. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +// Bundle name of the application whose notification function is taken over by the reminder agent +let representativeBundle = "com.example.demo" +// User ID +let userId = 100 +// NotificationRequest object +var request = { + id: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} + +Notification.publishAsBundle(request, representativeBundle, userId).then(() => { + console.info("publishAsBundle success"); +}); +``` + +## Notification.cancelAsBundle + +cancelAsBundle(id: number, representativeBundle: string, userId: number, callback: AsyncCallback\): void + +Cancels a notification published by the reminder agent. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------------------- | ------------- | ---- | ------------------------ | +| id | number | Yes | Notification ID. | +| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | +| userId | number | Yes | User ID. | +| callback | AsyncCallback | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | +| 1600008 | The user is not exist. | + +**Example** + +```js +// cancelAsBundle +function cancelAsBundleCallback(err) { + if (err) { + console.info("cancelAsBundle failed " + JSON.stringify(err)); + } else { + console.info("cancelAsBundle success"); + } +} +// Bundle name of the application whose notification function is taken over by the reminder agent +let representativeBundle = "com.example.demo" +// User ID +let userId = 100 + +Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback); +``` + +## Notification.cancelAsBundle + +cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\ + +Cancels a notification published by the reminder agent. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------------------- | ------ | ---- | ------------------ | +| id | number | Yes | Notification ID. | +| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent.| +| userId | number | Yes | User ID.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | +| 1600008 | The user is not exist. | + +**Example** + +```js +// Bundle name of the application whose notification function is taken over by the reminder agent +let representativeBundle = "com.example.demo" +// User ID +let userId = 100 + +Notification.cancelAsBundle(0, representativeBundle, userId).then(() => { + console.info("cancelAsBundle success"); +}); +``` + +## Notification.setNotificationEnableSlot + +setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\): void + +Sets whether to enable a specified notification slot type for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------- | ---- | ---------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| type | [SlotType](#slottype) | Yes | Notification slot type. | +| enable | boolean | Yes | Whether to enable the notification slot type. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +// setNotificationEnableSlot +function setNotificationEnableSlotCallback(err) { + if (err) { + console.info("setNotificationEnableSlot failed " + JSON.stringify(err)); + } else { + console.info("setNotificationEnableSlot success"); + } +}; + +Notification.setNotificationEnableSlot( + { bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION, + true, + setNotificationEnableSlotCallback); +``` + +## Notification.setNotificationEnableSlot + +setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise\ + +Sets whether to enable a specified notification slot type for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| type | [SlotType](#slottype) | Yes | Notification slot type.| +| enable | boolean | Yes | Whether to enable the notification slot type. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +// setNotificationEnableSlot +Notification.setNotificationEnableSlot( + { bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION, + true).then(() => { + console.info("setNotificationEnableSlot success"); + }); +``` + +## Notification.isNotificationSlotEnabled + +isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\): void + +Checks whether a specified notification slot type is enabled for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------- | ---- | ---------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| type | [SlotType](#slottype) | Yes | Notification slot type. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +// isNotificationSlotEnabled +function getEnableSlotCallback(err, data) { + if (err) { + console.info("isNotificationSlotEnabled failed " + JSON.stringify(err)); + } else { + console.info("isNotificationSlotEnabled success"); + } +}; + +Notification.isNotificationSlotEnabled( + { bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION, + getEnableSlotCallback); +``` + +## Notification.isNotificationSlotEnabled + +isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\ + +Checks whether a specified notification slot type is enabled for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| type | [SlotType](#slottype) | Yes | Notification slot type.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +// isNotificationSlotEnabled +Notification.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION).then((data) => { + console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data)); +}); +``` + + +## Notification.setSyncNotificationEnabledWithoutApp + +setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\): void + +Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| userId | number | Yes | User ID. | +| enable | boolean | Yes | Whether the feature is enabled. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +let userId = 100; +let enable = true; + +function callback(err) { + if (err) { + console.info("setSyncNotificationEnabledWithoutApp failed " + JSON.stringify(err)); + } else { + console.info("setSyncNotificationEnabledWithoutApp success"); + } +} + +Notification.setSyncNotificationEnabledWithoutApp(userId, enable, callback); +``` + + +## Notification.setSyncNotificationEnabledWithoutApp + +setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\ + +Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| userId | number | Yes | User ID. | +| enable | boolean | Yes | Whether the feature is enabled. | + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +let userId = 100; +let enable = true; + +Notification.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => { + console.info('setSyncNotificationEnabledWithoutApp success'); +}).catch((err) => { + console.info('setSyncNotificationEnabledWithoutApp, err:' + JSON.stringify(err)); +}); +``` + + +## Notification.getSyncNotificationEnabledWithoutApp + +getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\): void + +Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| userId | number | Yes | User ID. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +let userId = 100; + +function getSyncNotificationEnabledWithoutAppCallback(err, data) { + if (err) { + console.info('getSyncNotificationEnabledWithoutAppCallback, err:' + err); + } else { + console.info('getSyncNotificationEnabledWithoutAppCallback, data:' + data); + } +} + +Notification.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEnabledWithoutAppCallback); +``` + + +## Notification.getSyncNotificationEnabledWithoutApp + +getSyncNotificationEnabledWithoutApp(userId: number): Promise\ + +Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| userId | number | Yes | User ID. | + +**Return value** + +| Type | Description | +| ------------------ | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +let userId = 100; +Notification.getSyncNotificationEnabledWithoutApp(userId).then((data) => { + console.info('getSyncNotificationEnabledWithoutApp, data:' + data); +}).catch((err) => { + console.info('getSyncNotificationEnabledWithoutApp, err:' + err); +}); + .catch((err) => { + console.info('getSyncNotificationEnabledWithoutApp, err:', err); + }); +``` + + + + +## DoNotDisturbDate + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable| Writable| Description | +| ----- | ------------------------------------- | ---- | ---- | ---------------------- | +| type | [DoNotDisturbType](#donotdisturbtype) | Yes | Yes | DND time type.| +| begin | Date | Yes | Yes | DND start time.| +| end | Date | Yes | Yes | DND end time.| + + + +## DoNotDisturbType + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Value | Description | +| ------------ | ---------------- | ------------------------------------------ | +| TYPE_NONE | 0 | Non-DND. | +| TYPE_ONCE | 1 | One-shot DND at the specified time segment (only considering the hour and minute).| +| TYPE_DAILY | 2 | Daily DND at the specified time segment (only considering the hour and minute).| +| TYPE_CLEARLY | 3 | DND at the specified time segment (considering the year, month, day, hour, and minute). | + + +## ContentType + +**System capability**: SystemCapability.Notification.Notification + +| Name | Value | Description | +| --------------------------------- | ----------- | ------------------ | +| NOTIFICATION_CONTENT_BASIC_TEXT | NOTIFICATION_CONTENT_BASIC_TEXT | Normal text notification. | +| NOTIFICATION_CONTENT_LONG_TEXT | NOTIFICATION_CONTENT_LONG_TEXT | Long text notification. | +| NOTIFICATION_CONTENT_PICTURE | NOTIFICATION_CONTENT_PICTURE | Picture-attached notification. | +| NOTIFICATION_CONTENT_CONVERSATION | NOTIFICATION_CONTENT_CONVERSATION | Conversation notification. | +| NOTIFICATION_CONTENT_MULTILINE | NOTIFICATION_CONTENT_MULTILINE | Multi-line text notification.| + +## SlotLevel + +**System capability**: SystemCapability.Notification.Notification + +| Name | Value | Description | +| --------------------------------- | ----------- | ------------------ | +| LEVEL_NONE | 0 | Notification is disabled. | +| LEVEL_MIN | 1 | Notification is enabled, but the notification icon is not displayed in the status bar, with no banner or alert tone.| +| LEVEL_LOW | 2 | Notification is enabled, and the notification icon is displayed in the status bar, with no banner or alert tone.| +| LEVEL_DEFAULT | 3 | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone but no banner.| +| LEVEL_HIGH | 4 | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone and banner.| + + +## BundleOption + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ------ | ------ |---- | --- | ------ | +| bundle | string | Yes | Yes | Bundle information of the application.| +| uid | number | Yes | Yes | User ID.| + + +## SlotType + +**System capability**: SystemCapability.Notification.Notification + +| Name | Value | Description | +| -------------------- | -------- | ---------- | +| UNKNOWN_TYPE | 0 | Unknown type.| +| SOCIAL_COMMUNICATION | 1 | Notification slot for social communication.| +| SERVICE_INFORMATION | 2 | Notification slot for service information.| +| CONTENT_INFORMATION | 3 | Notification slot for content consultation.| +| OTHER_TYPES | 0xFFFF | Notification slot for other purposes.| + + +## NotificationActionButton + +Describes the button displayed in the notification. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| --------- | ----------------------------------------------- | --- | ---- | ------------------------- | +| title | string | Yes | Yes | Button title. | +| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** of the button.| +| extras | { [key: string]: any } | Yes | Yes | Extra information of the button. | +| userInput | [NotificationUserInput](#notificationuserinput) | Yes | Yes | User input object. | + + +## NotificationBasicContent + +Describes the normal text notification. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------------- | ------ | ---- | ---- | ---------------------------------- | +| title | string | Yes | Yes | Notification title. | +| text | string | Yes | Yes | Notification content. | +| additionalText | string | Yes | Yes | Additional information of the notification.| + + +## NotificationLongTextContent + +Describes the long text notification. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------------- | ------ | ---- | --- | -------------------------------- | +| title | string | Yes | Yes | Notification title. | +| text | string | Yes | Yes | Notification content. | +| additionalText | string | Yes | Yes | Additional information of the notification.| +| longText | string | Yes | Yes | Long text of the notification. | +| briefText | string | Yes | Yes | Brief text of the notification.| +| expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. | + + +## NotificationMultiLineContent + +Describes the multi-line text notification. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------------- | --------------- | --- | --- | -------------------------------- | +| title | string | Yes | Yes | Notification title. | +| text | string | Yes | Yes | Notification content. | +| additionalText | string | Yes | Yes | Additional information of the notification.| +| briefText | string | Yes | Yes | Brief text of the notification.| +| longTitle | string | Yes | Yes | Title of the notification in the expanded state. | +| lines | Array\ | Yes | Yes | Multi-line text of the notification. | + + +## NotificationPictureContent + +Describe the picture-attached notification. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------------- | -------------- | ---- | --- | -------------------------------- | +| title | string | Yes | Yes | Notification title. | +| text | string | Yes | Yes | Notification content. | +| additionalText | string | Yes | Yes | Additional information of the notification.| +| briefText | string | Yes | Yes | Brief text of the notification.| +| expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. | +| picture | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Picture attached to the notification. | + + +## NotificationContent + +Describes the notification content. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ----------- | ------------------------------------------------------------ | ---- | --- | ------------------ | +| contentType | [ContentType](#contenttype) | Yes | Yes | Notification content type. | +| normal | [NotificationBasicContent](#notificationbasiccontent) | Yes | Yes | Normal text. | +| longText | [NotificationLongTextContent](#notificationlongtextcontent) | Yes | Yes | Long text.| +| multiLine | [NotificationMultiLineContent](#notificationmultilinecontent) | Yes | Yes | Multi-line text. | +| picture | [NotificationPictureContent](#notificationpicturecontent) | Yes | Yes | Picture-attached. | + + +## NotificationFlagStatus + +Describes the notification flag status. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Value | Description | +| -------------- | --- | --------------------------------- | +| TYPE_NONE | 0 | The default flag is used. | +| TYPE_OPEN | 1 | The notification flag is enabled. | +| TYPE_CLOSE | 2 | The notification flag is disabled. | + + +## NotificationFlags + +Enumerates notification flags. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ---------------- | ---------------------- | ---- | ---- | --------------------------------- | +| soundEnabled | [NotificationFlagStatus](#notificationflagstatus) | Yes | No | Whether to enable the sound alert for the notification. | +| vibrationEnabled | [NotificationFlagStatus](#notificationflagstatus) | Yes | No | Whether to enable vibration for the notification. | + + +## NotificationRequest + +Describes the notification request. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| --------------------- | --------------------------------------------- | ---- | --- | -------------------------- | +| content | [NotificationContent](#notificationcontent) | Yes | Yes | Notification content. | +| id | number | Yes | Yes | Notification ID. | +| slotType | [SlotType](#slottype) | Yes | Yes | Notification slot type. | +| isOngoing | boolean | Yes | Yes | Whether the notification is an ongoing notification. | +| isUnremovable | boolean | Yes | Yes | Whether the notification can be removed. | +| deliveryTime | number | Yes | Yes | Time when the notification is sent. | +| tapDismissed | boolean | Yes | Yes | Whether the notification is automatically cleared. | +| autoDeletedTime | number | Yes | Yes | Time when the notification is automatically cleared. | +| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected after being clicked.| +| extraInfo | {[key: string]: any} | Yes | Yes | Extended parameters. | +| color | number | Yes | Yes | Background color of the notification. Not supported currently.| +| colorEnabled | boolean | Yes | Yes | Whether the notification background color can be enabled. Not supported currently.| +| isAlertOnce | boolean | Yes | Yes | Whether the notification triggers an alert only once.| +| isStopwatch | boolean | Yes | Yes | Whether to display the stopwatch. | +| isCountDown | boolean | Yes | Yes | Whether to display the countdown time. | +| isFloatingIcon | boolean | Yes | Yes | Whether the notification is displayed as a floating icon in the status bar. | +| label | string | Yes | Yes | Notification label. | +| badgeIconStyle | number | Yes | Yes | Notification badge type. | +| showDeliveryTime | boolean | Yes | Yes | Whether to display the time when the notification is delivered. | +| actionButtons | Array\<[NotificationActionButton](#notificationactionbutton)\> | Yes | Yes | Buttons in the notification. Up to two buttons are allowed. | +| smallIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Small notification icon. This field is optional, and the icon size cannot exceed 30 KB.| +| largeIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Large notification icon. This field is optional, and the icon size cannot exceed 30 KB.| +| creatorBundleName | string | Yes | No | Name of the bundle that creates the notification. | +| creatorUid | number | Yes | No | UID used for creating the notification. | +| creatorPid | number | Yes | No | PID used for creating the notification. | +| creatorUserId| number | Yes | No | ID of the user who creates the notification. | +| hashCode | string | Yes | No | Unique ID of the notification. | +| classification | string | Yes | Yes | Notification category.
**System API**: This is a system API and cannot be called by third-party applications. | +| groupName| string | Yes | Yes | Notification group name. | +| template | [NotificationTemplate](#notificationtemplate) | Yes | Yes | Notification template. | +| isRemoveAllowed | boolean | Yes | No | Whether the notification can be removed.
**System API**: This is a system API and cannot be called by third-party applications. | +| source | number | Yes | No | Notification source.
**System API**: This is a system API and cannot be called by third-party applications. | +| distributedOption | [DistributedOptions](#distributedoptions) | Yes | Yes | Distributed notification options. | +| deviceId | string | Yes | No | Device ID of the notification source.
**System API**: This is a system API and cannot be called by third-party applications. | +| notificationFlags | [NotificationFlags](#notificationflags) | Yes | No | Notification flags. | +| removalWantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected when it is removed. | +| badgeNumber | number | Yes | Yes | Number of notifications displayed on the application icon. | + + +## DistributedOptions + +Describes distributed options. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ---------------------- | -------------- | ---- | ---- | ---------------------------------- | +| isDistributed | boolean | Yes | Yes | Whether the notification is a distributed notification. | +| supportDisplayDevices | Array\ | Yes | Yes | List of the devices to which the notification can be synchronized. | +| supportOperateDevices | Array\ | Yes | Yes | List of the devices on which the notification can be opened. | +| remindType | number | Yes | No | Notification reminder type.
**System API**: This is a system API and cannot be called by third-party applications. | + + +## NotificationSlot + +Describes the notification slot. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------------------- | --------------------- | ---- | --- | ------------------------------------------ | +| type | [SlotType](#slottype) | Yes | Yes | Notification slot type. | +| level | number | Yes | Yes | Notification level. If this parameter is not set, the default value is used based on the notification slot type.| +| desc | string | Yes | Yes | Notification slot description. | +| badgeFlag | boolean | Yes | Yes | Whether to display the badge. | +| bypassDnd | boolean | Yes | Yes | Whether to bypass DND mode in the system. | +| lockscreenVisibility | number | Yes | Yes | Mode for displaying the notification on the lock screen. | +| vibrationEnabled | boolean | Yes | Yes | Whether vibration is enabled for the notification. | +| sound | string | Yes | Yes | Notification alert tone. | +| lightEnabled | boolean | Yes | Yes | Whether the indicator blinks for the notification. | +| lightColor | number | Yes | Yes | Indicator color of the notification. | +| vibrationValues | Array\ | Yes | Yes | Vibration mode of the notification. | +| enabled9+ | boolean | Yes | No | Whether the notification slot is enabled. | + + +## NotificationTemplate + +Describes the notification template. + +**System capability**: SystemCapability.Notification.Notification + +| Name| Type | Readable| Writable| Description | +| ---- | ---------------------- | ---- | ---- | ---------- | +| name | string | Yes | Yes | Template name.| +| data | {[key:string]: Object} | Yes | Yes | Template data.| + + +## NotificationUserInput + +Provides the notification user input. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------- | ------ | --- | ---- | ----------------------------- | +| inputKey | string | Yes | Yes | Key to identify the user input.| + + +## DeviceRemindType + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Value | Description | +| -------------------- | --- | --------------------------------- | +| IDLE_DONOT_REMIND | 0 | The device is not in use. No notification is required. | +| IDLE_REMIND | 1 | The device is not in use. | +| ACTIVE_DONOT_REMIND | 2 | The device is in use. No notification is required. | +| ACTIVE_REMIND | 3 | The device is in use. | + + +## SourceType + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Value | Description | +| -------------------- | --- | -------------------- | +| TYPE_NORMAL | 0 | Normal notification. | +| TYPE_CONTINUOUS | 1 | Continuous notification. | +| TYPE_TIMER | 2 | Timed notification. | diff --git a/en/application-dev/reference/apis/js-apis-notificationSubscribe.md b/en/application-dev/reference/apis/js-apis-notificationSubscribe.md new file mode 100644 index 0000000000000000000000000000000000000000..ed0ad9400ed59c637b5495c7b20f8770b0b4329c --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-notificationSubscribe.md @@ -0,0 +1,1074 @@ +# @ohos.notificationSubscribe + +The **NotificationSubscribe** module provides APIs for notification subscription, notification unsubscription, subscription removal, and more. In general cases, only system applications can call these APIs. + +> **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 NotificationSubscribe from '@ohos.notificationSubscribe'; +``` + + + +## NotificationSubscribe.subscribe + +subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\): void + +Subscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ---------- | ------------------------- | ---- | ---------------- | +| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | +| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Notification subscription information.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// subscribe callback +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribe success"); + } +} +function onConsumeCallback(data) { + console.info("Consume callback: " + JSON.stringify(data)); +} +var subscriber = { + onConsume: onConsumeCallback +} +var info = { + bundleNames: ["bundleName1","bundleName2"] +} +NotificationSubscribe.subscribe(subscriber, info, subscribeCallback); +``` + + + +## NotificationSubscribe.subscribe + +subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\): void + +Subscribes to notifications of all applications under this user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ---------- | ---------------------- | ---- | ---------------- | +| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribe success"); + } +} +function onConsumeCallback(data) { + console.info("Consume callback: " + JSON.stringify(data)); +} +var subscriber = { + onConsume: onConsumeCallback +} +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + + + +## NotificationSubscribe.subscribe + +subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise\ + +Subscribes to a notification with the subscription information specified. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ---------- | ------------------------- | ---- | ------------ | +| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.| +| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | No | Notification subscription information. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function onConsumeCallback(data) { + console.info("Consume callback: " + JSON.stringify(data)); +} +var subscriber = { + onConsume: onConsumeCallback +}; +NotificationSubscribe.subscribe(subscriber).then(() => { + console.info("subscribe success"); +}); +``` + + + +## NotificationSubscribe.unsubscribe + +unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\): void + +Unsubscribes from a notification. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ---------- | ---------------------- | ---- | -------------------- | +| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function unsubscribeCallback(err) { + if (err) { + console.info("unsubscribe failed " + JSON.stringify(err)); + } else { + console.info("unsubscribe success"); + } +} +function onDisconnectCallback(data) { + console.info("Cancel callback: " + JSON.stringify(data)); +} +var subscriber = { + onDisconnect: onDisconnectCallback +} +NotificationSubscribe.unsubscribe(subscriber, unsubscribeCallback); +``` + + + +## NotificationSubscribe.unsubscribe + +unsubscribe(subscriber: NotificationSubscriber): Promise\ + +Unsubscribes from a notification. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ---------- | ---------------------- | ---- | ------------ | +| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function onDisconnectCallback(data) { + console.info("Cancel callback: " + JSON.stringify(data)); +} +var subscriber = { + onDisconnect: onDisconnectCallback +}; +NotificationSubscribe.unsubscribe(subscriber).then(() => { + console.info("unsubscribe success"); +}); +``` + + + +## NotificationSubscribe.remove + +remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason, callback: AsyncCallback\): void + +Removes a notification for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------------- | ----------------------------------| ---- | -------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | +| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function removeCallback(err) { + if (err) { + console.info("remove failed " + JSON.stringify(err)); + } else { + console.info("remove success"); + } +} +var bundle = { + bundle: "bundleName1", +} +var notificationKey = { + id: 0, + label: "label", +} +var reason = NotificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; +NotificationSubscribe.remove(bundle, notificationKey, reason, removeCallback); +``` + + + +## NotificationSubscribe.remove + +remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise\ + +Removes a notification for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------------- | --------------- | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| +| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | +| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +var notificationKey = { + id: 0, + label: "label", +} +var reason = NotificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; +NotificationSubscribe.remove(bundle, notificationKey, reason).then(() => { + console.info("remove success"); +}); +``` + + + +## NotificationSubscribe.remove + +remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\): void + +Removes a specified notification. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| hashCode | string | Yes | Unique notification ID. It is the **hashCode** in the [NotificationRequest](#notificationrequest) object of [SubscribeCallbackData](#subscribecallbackdata) of the [onConsume](#onconsume) callback.| +| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | + +**Example** + +```js +var hashCode = 'hashCode' + +function removeCallback(err) { + if (err) { + console.info("remove failed " + JSON.stringify(err)); + } else { + console.info("remove success"); + } +} +var reason = NotificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE; +NotificationSubscribe.remove(hashCode, reason, removeCallback); +``` + + + +## NotificationSubscribe.remove + +remove(hashCode: string, reason: RemoveReason): Promise\ + +Removes a specified notification. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------- | ---- | ---------- | +| hashCode | string | Yes | Unique notification ID.| +| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | + +**Example** + +```js +var hashCode = 'hashCode' +var reason = NotificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; +NotificationSubscribe.remove(hashCode, reason).then(() => { + console.info("remove success"); +}); +``` + + + +## NotificationSubscribe.removeAll + +removeAll(bundle: BundleOption, callback: AsyncCallback\): void + +Removes all notifications for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ---------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function removeAllCallback(err) { + if (err) { + console.info("removeAll failed " + JSON.stringify(err)); + } else { + console.info("removeAll success"); + } +} +var bundle = { + bundle: "bundleName1", +} +NotificationSubscribe.removeAll(bundle, removeAllCallback); +``` + + + +## NotificationSubscribe.removeAll + +removeAll(callback: AsyncCallback\): void + +Removes all notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function removeAllCallback(err) { + if (err) { + console.info("removeAll failed " + JSON.stringify(err)); + } else { + console.info("removeAll success"); + } +} + +NotificationSubscribe.removeAll(removeAllCallback); +``` + + + +## NotificationSubscribe.removeAll + +removeAll(bundle?: BundleOption): Promise\ + +Removes all notifications for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | No | Bundle information of the application.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +// If no application is specified, notifications of all applications are deleted. +NotificationSubscribe.removeAll().then(() => { + console.info("removeAll success"); +}); +``` + +## NotificationSubscribe.removeAll + +removeAll(userId: number, callback: AsyncCallback\): void + +Removes all notifications for a specified user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| userId | number | Yes | User ID.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +function removeAllCallback(err) { + if (err) { + console.info("removeAll failed " + JSON.stringify(err)); + } else { + console.info("removeAll success"); + } +} + +var userId = 1 + +NotificationSubscribe.removeAll(userId, removeAllCallback); +``` + +## Notification.removeAll + +removeAll(userId: number): Promise\ + +Removes all notifications for a specified user. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| userId | number | Yes | User ID.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +function removeAllCallback(err) { + if (err) { + console.info("removeAll failed " + JSON.stringify(err)); + } else { + console.info("removeAll success"); + } +} + +var userId = 1 + +NotificationSubscribe.removeAll(userId, removeAllCallback); +``` + + + +## NotificationSubscriber + +Provides callbacks for receiving or removing notifications and serves as the input parameter of [subscribe](#notificationsubscribe). + +**System API**: This is a system API and cannot be called by third-party applications. + +### onConsume + +onConsume?: (data: [SubscribeCallbackData](#subscribecallbackdata)) => void + +Callback for receiving notifications. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification received.| + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onConsumeCallback(data) { + console.info('===> onConsume in test'); + let req = data.request; + console.info('===> onConsume callback req.id:' + req.id); +}; + +var subscriber = { + onConsume: onConsumeCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +### onCancel + +onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) => void + +Callback for canceling notifications. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification to cancel.| + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onCancelCallback(data) { + console.info('===> onCancel in test'); + let req = data.request; + console.info('===> onCancel callback req.id:' + req.id); +} + +var subscriber = { + onCancel: onCancelCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +### onUpdate + +onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap)) => void + +Callback for notification sorting updates. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| data | [NotificationSortingMap](#notificationsortingmap) | Yes| Latest notification sorting list.| + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onUpdateCallback(map) { + console.info('===> onUpdateCallback map:' + JSON.stringify(map)); +} + +var subscriber = { + onUpdate: onUpdateCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +### onConnect + +onConnect?:() => void + +Callback for subscription. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onConnectCallback() { + console.info('===> onConnect in test'); +} + +var subscriber = { + onConnect: onConnectCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +### onDisconnect + +onDisconnect?:() => void + +Callback for unsubscription. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; +function unsubscribeCallback(err) { + if (err.code) { + console.info("unsubscribe failed " + JSON.stringify(err)); + } else { + console.info("unsubscribeCallback"); + } +}; + +function onConnectCallback() { + console.info('===> onConnect in test'); +} +function onDisconnectCallback() { + console.info('===> onDisconnect in test'); +} + +var subscriber = { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback +}; + +// The onConnect callback is invoked when subscription to the notification is complete. +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +// The onDisconnect callback is invoked when unsubscription to the notification is complete. +NotificationSubscribe.unsubscribe(subscriber, unsubscribeCallback); +``` + +### onDestroy + +onDestroy?:() => void + +Callback for service disconnection. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onDestroyCallback() { + console.info('===> onDestroy in test'); +} + +var subscriber = { + onDestroy: onDestroyCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +### onDoNotDisturbDateChange + +onDoNotDisturbDateChange?:(mode: notification.[DoNotDisturbDate](js-apis-notificationManager.md#donotdisturbdate)) => void + +Callback for DND time setting updates. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| mode | notification.[DoNotDisturbDate](js-apis-notificationManager.md#DoNotDisturbDate) | Yes| DND time setting updates.| + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onDoNotDisturbDateChangeCallback(mode) { + console.info('===> onDoNotDisturbDateChange:' + mode); +} + +var subscriber = { + onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + + +### onEnabledNotificationChanged + +onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata)) => void + +Listens for the notification enabled status changes. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| callback | AsyncCallback\<[EnabledNotificationCallbackData](#enablednotificationcallbackdata)\> | Yes| Callback used to return the result.| + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onEnabledNotificationChangedCallback(callbackData) { + console.info("bundle: ", callbackData.bundle); + console.info("uid: ", callbackData.uid); + console.info("enable: ", callbackData.enable); +}; + +var subscriber = { + onEnabledNotificationChanged: onEnabledNotificationChangedCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +## BundleOption + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ------ | ------ |---- | --- | ------ | +| bundle | string | Yes | Yes | Bundle information of the application.| +| uid | number | Yes | Yes | User ID.| + +## NotificationKey + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ----- | ------ | ---- | --- | -------- | +| id | number | Yes | Yes | Notification ID. | +| label | string | Yes | Yes | Notification label.| + +## SubscribeCallbackData + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable | Writable | Description | +| --------------- | ------------------------------------------------- | -------- | -------- | -------- | +| request | [NotificationRequest](js-apis-notificationManager.md#notificationrequest) | Yes| No| Notification content.| +| sortingMap | [NotificationSortingMap](#notificationsortingmap) | Yes| No| Notification sorting information.| +| reason | number | Yes | No | Reason for deletion.| +| sound | string | Yes | No | Sound used for notification.| +| vibrationValues | Array\ | Yes | No | Vibration used for notification.| + + +## EnabledNotificationCallbackData + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable | Writable | Description | +| ------ | ------- | ---------------- | ---------------- | ---------------- | +| bundle | string | Yes| No| Bundle name of the application. | +| uid | number | Yes| No| UID of the application. | +| enable | boolean | Yes| No| Notification enabled status of the application.| + + +## NotificationSorting + +Provides sorting information of activity notifications. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable| Writable| Description | +| -------- | ------------------------------------- | ---- | --- | ------------ | +| slot | [NotificationSlot](js-apis-notificationManager.md#notificationslot) | Yes | No | Notification slot.| +| hashCode | string | Yes | No | Unique ID of the notification.| +| ranking | number | Yes | No | Notification sequence number.| + + +## NotificationSortingMap + +Provides sorting information of active notifications in all subscribed notifications. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable| Writable| Description | +| -------------- | ------------------------------------------------------------ | ---- | --- | ---------------- | +| sortings | {[key: string]: [NotificationSorting](#notificationsorting)} | Yes | No | Array of notification sorting information.| +| sortedHashCode | Array\ | Yes | No | Array of unique notification IDs.| + + +## NotificationSubscribeInfo + +Provides the information about the publisher for notification subscription. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable| Writable| Description | +| ----------- | --------------- | --- | ---- | ------------------------------- | +| bundleNames | Array\ | Yes | Yes | Bundle names of the applications whose notifications are to be subscribed to.| +| userId | number | Yes | Yes | User whose notifications are to be subscribed to. | + + +## NotificationUserInput + +Provides the notification user input. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------- | ------ | --- | ---- | ----------------------------- | +| inputKey | string | Yes | Yes | Key to identify the user input.| + +## RemoveReason + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Value | Description | +| -------------------- | --- | -------------------- | +| CLICK_REASON_REMOVE | 1 | The notification is removed after a click on it. | +| CANCEL_REASON_REMOVE | 2 | The notification is removed by the user. | diff --git a/en/application-dev/reference/apis/js-apis-observer.md b/en/application-dev/reference/apis/js-apis-observer.md index a6fcacc4333ab0aa48dae7cd8b629e1e77bb399f..ad7d19b4ab7a3cfa6593c81f2c70b52f403aa4d1 100644 --- a/en/application-dev/reference/apis/js-apis-observer.md +++ b/en/application-dev/reference/apis/js-apis-observer.md @@ -531,8 +531,8 @@ Enumerates SIM card types and states. **System capability**: SystemCapability.Telephony.StateRegistry -| Name | Type | Description | -| ----------------- | --------------------- | ------------------------------------------------------------ | -| type | [CardType](js-apis-sim.md#cardtype) | SIM card type. For details, see [CardType](js-apis-sim.md#cardtype).| -| state | [SimState](js-apis-sim.md#simstate) | SIM card status. For details, see [SimState](js-apis-sim.md#simstate).| -| reason8+ | [LockReason](#lockreason8) | SIM card lock type.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| type | [CardType](js-apis-sim.md#cardtype) | Yes| SIM card type. For details, see [CardType](js-apis-sim.md#cardtype).| +| state | [SimState](js-apis-sim.md#simstate) | Yes| SIM card status. For details, see [SimState](js-apis-sim.md#simstate).| +| reason8+ | [LockReason](#lockreason8) | Yes| SIM card lock type.| diff --git a/en/application-dev/reference/apis/js-apis-pointer.md b/en/application-dev/reference/apis/js-apis-pointer.md index 14bb3753f34e0eb73e2b01fac199d62683224ef5..b70cc9cf1c4f5a109352aaadf5fc32d5b2b8854f 100644 --- a/en/application-dev/reference/apis/js-apis-pointer.md +++ b/en/application-dev/reference/apis/js-apis-pointer.md @@ -141,7 +141,7 @@ Sets the mouse movement speed. This API uses an asynchronous callback to return | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ------------------------------------- | | speed | number | Yes | Mouse movement speed. The value ranges from **1** to **11**. The default value is **5**. | -| callback | AysncCallback<void> | Yes | Callback used to return the result.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** @@ -348,7 +348,7 @@ Sets the mouse pointer style. This API uses an asynchronous callback to return t | ------------ | ------------------------------ | ---- | ----------------------------------- | | windowId | number | Yes | Window ID. | | pointerStyle | [PointerStyle](#pointerstyle9) | Yes | Mouse pointer style ID. | -| callback | AysncCallback<void> | Yes | Callback used to return the result.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** diff --git a/en/application-dev/reference/apis/js-apis-prompt.md b/en/application-dev/reference/apis/js-apis-prompt.md index 1fd0357783d6cf3ead6913cfc07a0e4b4e1c3c82..27a450de58306f1b018468d6f2590778a9f0d484 100644 --- a/en/application-dev/reference/apis/js-apis-prompt.md +++ b/en/application-dev/reference/apis/js-apis-prompt.md @@ -1,4 +1,4 @@ -# Prompt +# @ohos.prompt The **Prompt** module provides APIs for creating and showing toasts, dialog boxes, and action menus. @@ -146,11 +146,11 @@ Describes the options for showing the dialog box. **System capability**: SystemCapability.ArkUI.ArkUI.Full -| Name | Type | Mandatory | Description | -| ------- | ---------------------------------------- | ---- | ---------------------------------------- | -| title | string\| [Resource](../arkui-ts/ts-types.md#resource)9+ | No | Title of the dialog box. | -| message | string\| [Resource](../arkui-ts/ts-types.md#resource)9+ | No | Text body. | -| buttons | Array | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| title | string\| [Resource](../arkui-ts/ts-types.md#resource)9+ | No | Title of the dialog box. | +| message | string\| [Resource](../arkui-ts/ts-types.md#resource)9+ | No | Text body. | +| buttons | [[Button](#button),[Button](#button)?,[Button](#button)?] | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type.| ## ShowDialogSuccessResponse @@ -158,9 +158,9 @@ Describes the dialog box response result. **System capability**: SystemCapability.ArkUI.ArkUI.Full -| Name | Type | Description | -| ----- | ------ | ------------------- | -| index | number | Index of the selected button in the **buttons** array.| +| Name | Type | Mandatory| Description | +| ----- | ------ | ---- | ------------------------------- | +| index | number | No | Index of the selected button in the **buttons** array.| ## prompt.showActionMenu @@ -255,10 +255,10 @@ Describes the options for showing the action menu. **System capability**: SystemCapability.ArkUI.ArkUI.Full -| Name | Type | Mandatory | Description | -| ------- | ---------------------------------------- | ---- | ---------------------------------------- | -| title | string\| [Resource](../arkui-ts/ts-types.md#resource)9+ | No | Title of the text to display. | -| buttons | Array<[Button](#button)> | Yes | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| title | string\| [Resource](../arkui-ts/ts-types.md#resource)9+ | No | Title of the text to display. | +| buttons | [[Button](#button),[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?] | Yes | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.| ## ActionMenuSuccessResponse diff --git a/en/application-dev/reference/apis/js-apis-promptAction.md b/en/application-dev/reference/apis/js-apis-promptAction.md index 268673b046bbb5f775dfffe3986105718319d009..0faa9cf211bbd0a673287c34b8d9ad45d34374e6 100644 --- a/en/application-dev/reference/apis/js-apis-promptAction.md +++ b/en/application-dev/reference/apis/js-apis-promptAction.md @@ -1,4 +1,4 @@ -# Prompt +# @ohos.promptAction The **PromptAction** module provides APIs for creating and showing toasts, dialog boxes, and action menus. @@ -32,7 +32,7 @@ For details about the error codes, see [promptAction Error Codes](../errorcodes/ | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | +| 100001 | If UI execution context not found. | **Example** @@ -88,7 +88,7 @@ For details about the error codes, see [promptAction Error Codes](../errorcodes/ | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | +| 100001 | If UI execution context not found. | **Example** @@ -142,7 +142,7 @@ For details about the error codes, see [promptAction Error Codes](../errorcodes/ | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | +| 100001 | If UI execution context not found. | **Example** @@ -181,11 +181,11 @@ Describes the options for showing the dialog box. **System capability**: SystemCapability.ArkUI.ArkUI.Full -| Name | Type | Mandatory | Description | -| ------- | ---------------------------------------- | ---- | ---------------------------------------- | -| title | string\| [Resource](../arkui-ts/ts-types.md#resource)9+| No | Title of the dialog box. | -| message | string\| [Resource](../arkui-ts/ts-types.md#resource)9+| No | Text body. | -| buttons | Array | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| title | string\| [Resource](../arkui-ts/ts-types.md#resource)9+| No | Title of the dialog box. | +| message | string\| [Resource](../arkui-ts/ts-types.md#resource)9+| No | Text body. | +| buttons | [[Button](#button),[Button](#button)?,[Button](#button)?] | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type.| ## ShowDialogSuccessResponse @@ -193,9 +193,9 @@ Describes the dialog box response result. **System capability**: SystemCapability.ArkUI.ArkUI.Full -| Name | Type | Description | -| ----- | ------ | ------------------- | -| index | number | Index of the selected button in the **buttons** array.| +| Name | Type | Mandatory| Description | +| ----- | ------ | ---- | ------------------------------- | +| index | number | No | Index of the selected button in the **buttons** array.| ## promptAction.showActionMenu @@ -218,7 +218,7 @@ For details about the error codes, see [promptAction Error Codes](../errorcodes/ | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | +| 100001 | If UI execution context not found. | **Example** @@ -276,7 +276,7 @@ For details about the error codes, see [promptAction Error Codes](../errorcodes/ | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | +| 100001 | If UI execution context not found. | **Example** @@ -314,10 +314,10 @@ Describes the options for showing the action menu. **System capability**: SystemCapability.ArkUI.ArkUI.Full -| Name | Type | Mandatory | Description | -| ------- | ---------------------------------------- | ---- | ---------------------------------------- | -| title | string\| [Resource](../arkui-ts/ts-types.md#resource)9+| No | Title of the dialog box. | -| buttons | Array<[Button](#button)> | Yes | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| title | string\| [Resource](../arkui-ts/ts-types.md#resource)9+| No | Title of the dialog box. | +| buttons | [[Button](#button),[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?] | Yes | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.| ## ActionMenuSuccessResponse diff --git a/en/application-dev/reference/apis/js-apis-radio.md b/en/application-dev/reference/apis/js-apis-radio.md index 01d439fd2e3e9d1202aa6969cb15fda67fa9059d..91c6be9cd7d076dbb72a502e64363d729668972f 100644 --- a/en/application-dev/reference/apis/js-apis-radio.md +++ b/en/application-dev/reference/apis/js-apis-radio.md @@ -1734,8 +1734,8 @@ Enables listening for **imsRegStateChange** events for the SIM card in the speci **Example** ```js -radio.on('imsRegStateChange', 0, radio.ImsServiceType.TYPE_VIDEO, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.on('imsRegStateChange', 0, radio.ImsServiceType.TYPE_VIDEO, data => { + console.log(`callback: data->${JSON.stringify(data)}`); }); ``` @@ -1763,8 +1763,8 @@ Disables listening for **imsRegStateChange** events for the SIM card in the spec **Example** ```js -radio.off('imsRegStateChange', 0, radio.ImsServiceType.TYPE_VIDEO, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.off('imsRegStateChange', 0, radio.ImsServiceType.TYPE_VIDEO, data => { + console.log(`callback: data->${JSON.stringify(data)}`); }); ``` @@ -1797,10 +1797,10 @@ Defines the signal strength. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ----------- | --------------------------- | ------------------ | -| signalType | [NetworkType](#networktype) | Signal strength type.| -| signalLevel | number | Signal strength level.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| signalType | [NetworkType](#networktype) | Yes| Signal strength type.| +| signalLevel | number | Yes| Signal strength level.| ## NetworkType @@ -1825,17 +1825,17 @@ Defines the network status. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ----------------- | --------------------- | ------------------------------------------------------------ | -| longOperatorName | string | Long carrier name of the registered network.| -| shortOperatorName | string | Short carrier name of the registered network.| -| plmnNumeric | string | PLMN code of the registered network.| -| isRoaming | boolean | Whether the user is roaming.| -| regState | [RegState](#regstate) | Network registration status of the device.| -| cfgTech8+ | [RadioTechnology](#radiotechnology) | RAT of the device.| -| nsaState | [NsaState](#nsastate) | NSA network registration status of the device.| -| isCaActive | boolean | CA status.| -| isEmergency | boolean | Whether only emergency calls are allowed.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| longOperatorName | string | Yes | Long carrier name of the registered network.| +| shortOperatorName | string | Yes | Short carrier name of the registered network.| +| plmnNumeric | string | Yes | PLMN code of the registered network.| +| isRoaming | boolean | Yes | Whether the user is roaming.| +| regState | [RegState](#regstate) | Yes | Network registration status of the device.| +| cfgTech8+ | [RadioTechnology](#radiotechnology) | Yes | RAT of the device.| +| nsaState | [NsaState](#nsastate) | Yes | NSA network registration status of the device.| +| isCaActive | boolean | Yes | CA status.| +| isEmergency | boolean | Yes | Whether only emergency calls are allowed.| ## RegState @@ -1933,13 +1933,13 @@ Defines the cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| networkType | [NetworkType](#networktype) | Network type of the cell. | -| isCamped | boolean | Status of the cell. | -| timeStamp | number | Timestamp when cell information is obtained. | -| signalInformation | [SignalInformation](#signalinformation) | Signal information. | -| data | [CdmaCellInformation](#cdmacellinformation8) \| [GsmCellInformation](#gsmcellinformation8) \| [LteCellInformation](#ltecellinformation8) \| [NrCellInformation](#nrcellinformation8) \| [TdscdmaCellInformation](#tdscdmacellinformation8) | CDMA cell information \|GSM cell information \|LTE cell information \|NR cell information \|TD-SCDMA cell information| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| networkType | [NetworkType](#networktype) | Yes | Network type of the cell. | +| isCamped | boolean | Yes | Status of the cell. | +| timeStamp | number | Yes | Timestamp when cell information is obtained. | +| signalInformation | [SignalInformation](#signalinformation) | Yes | Signal information. | +| data | [CdmaCellInformation](#cdmacellinformation8) \| [GsmCellInformation](#gsmcellinformation8) \| [LteCellInformation](#ltecellinformation8) \| [NrCellInformation](#nrcellinformation8) \| [TdscdmaCellInformation](#tdscdmacellinformation8) | Yes | CDMA cell information \|GSM cell information \|LTE cell information \|NR cell information \|TD-SCDMA cell information| ## CdmaCellInformation8+ @@ -1949,13 +1949,13 @@ Defines the CDMA cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| --------- | ------ | ------------ | -| baseId | number | Base station ID. | -| latitude | number | Longitude. | -| longitude | number | Latitude. | -| nid | number | Network ID.| -| sid | number | System ID.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| baseId | number | Yes | Base station ID. | +| latitude | number | Yes | Longitude. | +| longitude | number | Yes | Latitude. | +| nid | number | Yes | Network ID.| +| sid | number | Yes | System ID.| ## GsmCellInformation8+ @@ -1965,14 +1965,14 @@ Defines the GSM cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------ | ------ | -------------------- | -| lac | number | Location area code. | -| cellId | number | Cell ID. | -| arfcn | number | Absolute radio frequency channel number.| -| bsic | number | Base station ID. | -| mcc | string | Mobile country code. | -| mnc | string | Mobile network code. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| lac | number | Yes | Location area code. | +| cellId | number | Yes | Cell ID. | +| arfcn | number | Yes | Absolute radio frequency channel number.| +| bsic | number | Yes | Base station ID. | +| mcc | string | Yes | Mobile country code. | +| mnc | string | Yes | Mobile network code. | ## LteCellInformation8+ @@ -1982,16 +1982,16 @@ Defines the LTE cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------------- | ------- | ----------------------- | -| cgi | number | Cell global identification. | -| pci | number | Physical cell ID. | -| tac | number | Tracking area code. | -| earfcn | number | Absolute radio frequency channel number. | -| bandwidth | number | Bandwidth. | -| mcc | string | Mobile country code. | -| mnc | string | Mobile network code. | -| isSupportEndc | boolean | Support New Radio_Dual Connectivity| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| cgi | number | Yes | Cell global identification. | +| pci | number | Yes | Physical cell ID. | +| tac | number | Yes | Tracking area code. | +| earfcn | number | Yes | Absolute radio frequency channel number. | +| bandwidth | number | Yes | Bandwidth. | +| mcc | string | Yes | Mobile country code. | +| mnc | string | Yes | Mobile network code. | +| isSupportEndc | boolean | Yes | Support for New Radio_Dual Connectivity. | ## NrCellInformation8+ @@ -2001,14 +2001,14 @@ Defines the NR cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------- | ------ | ---------------- | -| nrArfcn | number | 5G frequency number. | -| pci | number | Physical cell ID. | -| tac | number | Tracking area code. | -| nci | number | 5G network cell ID.| -| mcc | string | Mobile country code. | -| mnc | string | Mobile network code. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| nrArfcn | number | Yes | 5G frequency number. | +| pci | number | Yes | Physical cell ID. | +| tac | number | Yes | Tracking area code. | +| nci | number | Yes | 5G network cell ID.| +| mcc | string | Yes | Mobile country code. | +| mnc | string | Yes | Mobile network code. | ## TdscdmaCellInformation8+ @@ -2018,14 +2018,14 @@ Defines the TD-SCDMA cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------ | ------ | ------------ | -| lac | number | Location area code.| -| cellId | number | Cell ID. | -| cpid | number | Cell parameter ID.| -| uarfcn | number | Absolute radio frequency number.| -| mcc | string | Mobile country code.| -| mnc | string | Mobile network code. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| lac | number | Yes | Location area code.| +| cellId | number | Yes | Cell ID. | +| cpid | number | Yes | Cell parameter ID.| +| uarfcn | number | Yes | Absolute radio frequency number.| +| mcc | string | Yes | Mobile country code.| +| mnc | string | Yes | Mobile network code. | ## WcdmaCellInformation8+ @@ -2035,14 +2035,14 @@ Defines the WCDMA cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------ | ------ | ------------ | -| lac | number | Location area code.| -| cellId | number | Cell ID. | -| psc | number | Primary scrambling code. | -| uarfcn | number | Absolute radio frequency number.| -| mcc | string | Mobile country code.| -| mnc | string | Mobile network code. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| lac | number | Yes | Location area code.| +| cellId | number | Yes | Cell ID. | +| psc | number | Yes | Primary scrambling code. | +| uarfcn | number | Yes | Absolute radio frequency number.| +| mcc | string | Yes | Mobile country code.| +| mnc | string | Yes | Mobile network code. | ## NrOptionMode8+ @@ -2067,10 +2067,10 @@ Defines the network search result. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ---------------------- | ------------------------------------------------- | -------------- | -| isNetworkSearchSuccess | boolean | Successful network search.| -| networkSearchResult | Array<[NetworkInformation](#networkinformation)\> | Network search result.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| isNetworkSearchSuccess | boolean | Yes | Successful network search.| +| networkSearchResult | Array<[NetworkInformation](#networkinformation)\> | Yes | Network search result.| ## NetworkInformation @@ -2080,12 +2080,12 @@ Defines the network information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| --------------- | ----------------------------------------- | -------------- | -| operatorName | string | Carrier name.| -| operatorNumeric | string | Carrier number. | -| state | [NetworkInformation](#networkinformationstate) | Network information status.| -| radioTech | string | Radio technology. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| operatorName | string | Yes | Carrier name.| +| operatorNumeric | string | Yes | Carrier number. | +| state | [NetworkInformation](#networkinformationstate) | Yes | Network information status.| +| radioTech | string | Yes | Radio technology. | ## NetworkInformationState @@ -2110,12 +2110,12 @@ Defines the network selection mode. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------------------ | --------------------------------------------- | -------------------------------------- | -| slotId | number | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2| -| selectMode | [NetworkSelectionMode](#networkselectionmode) | Network selection mode. | -| networkInformation | [NetworkInformation](#networkinformation) | Network information. | -| resumeSelection | boolean | Whether to resume selection. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2| +| selectMode | [NetworkSelectionMode](#networkselectionmode) | Yes | Network selection mode. | +| networkInformation | [NetworkInformation](#networkinformation) | Yes | Network information. | +| resumeSelection | boolean | Yes | Whether to resume selection. | ## ImsRegState9+ @@ -2153,10 +2153,10 @@ Defines the IMS registration information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ----------- | ---------------------------- | ------------- | -| imsRegState | [ImsRegState](#imsregstate9) | IMS registration state.| -| imsRegTech | [ImsRegTech](#imsregtech9) | IMS registration technology.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| imsRegState | [ImsRegState](#imsregstate9) | Yes | IMS registration state.| +| imsRegTech | [ImsRegTech](#imsregtech9) | Yes | IMS registration technology.| ## ImsServiceType9+ diff --git a/en/application-dev/reference/apis/js-apis-request.md b/en/application-dev/reference/apis/js-apis-request.md index 48aebf140314470ae45a5df5d8f0f89f60988f1a..d3a0eeb30ea75a3109b6917d50b7b1d24cdd2fb4 100644 --- a/en/application-dev/reference/apis/js-apis-request.md +++ b/en/application-dev/reference/apis/js-apis-request.md @@ -43,30 +43,53 @@ Only HTTP requests are supported. HTTPS requests are not supported. **System capability**: SystemCapability.MiscServices.Download -| Name| Type| Readable| Writable| Description| -| -------- | -------- | -------- | -------- | -------- | -| NETWORK_MOBILE | number | Yes| No| Whether download is allowed on a mobile network.| -| NETWORK_WIFI | number | Yes| No| Whether download is allowed on a WLAN.| -| ERROR_CANNOT_RESUME7+ | number | Yes| No| Failure to resume the download due to an error.| -| ERROR_DEVICE_NOT_FOUND7+ | number | Yes| No| Failure to find a storage device such as a memory card.| -| ERROR_FILE_ALREADY_EXISTS7+ | number | Yes| No| Failure to download the file because it already exists.| -| ERROR_FILE_ERROR7+ | number | Yes| No| File operation failure.| -| ERROR_HTTP_DATA_ERROR7+ | number | Yes| No| HTTP transmission failure.| -| ERROR_INSUFFICIENT_SPACE7+ | number | Yes| No| Insufficient storage space.| -| ERROR_TOO_MANY_REDIRECTS7+ | number | Yes| No| Error caused by too many network redirections.| -| ERROR_UNHANDLED_HTTP_CODE7+ | number | Yes| No| Unidentified HTTP code.| -| ERROR_OFFLINE9+ | number | Yes| No| No network connection.| -| ERROR_UNSUPPORTED_NETWORK_TYPE9+ | number | Yes| No| Network type mismatch.| -| ERROR_UNKNOWN7+ | number | Yes| No| Unknown error.| -| PAUSED_QUEUED_FOR_WIFI7+ | number | Yes| No| Download paused and queuing for a WLAN connection, because the file size exceeds the maximum value allowed by a mobile network session.| -| PAUSED_UNKNOWN7+ | number | Yes| No| Download paused due to unknown reasons.| -| PAUSED_WAITING_FOR_NETWORK7+ | number | Yes| No| Download paused due to a network connection problem, for example, network disconnection.| -| PAUSED_WAITING_TO_RETRY7+ | number | Yes| No| Download paused and then retried.| -| SESSION_FAILED7+ | number | Yes| No| Download failure without retry.| -| SESSION_PAUSED7+ | number | Yes| No| Download paused.| -| SESSION_PENDING7+ | number | Yes| No| Download pending.| -| SESSION_RUNNING7+ | number | Yes| No| Download in progress.| -| SESSION_SUCCESSFUL7+ | number | Yes| No| Successful download.| +### Network Types +You can set **networkType** in [DownloadConfig](#downloadconfig) to specify the network type for the download service. + +| Name| Type| Value| Description| +| -------- | -------- | -------- | -------- | +| NETWORK_MOBILE | number | 0x00000001 | Whether download is allowed on a mobile network.| +| NETWORK_WIFI | number | 0x00010000 | Whether download is allowed on a WLAN.| + +### Download Error Codes +The table below lists the error codes that may be returned by [on('fail')7+](#onfail7)/[off('fail')7+](#offfail7)/[getTaskInfo9+](#gettaskinfo9). + +| Name| Type| Value| Description| +| -------- | -------- | -------- | -------- | +| ERROR_CANNOT_RESUME7+ | number | 0 | Failure to resume the download due to network errors.| +| ERROR_DEVICE_NOT_FOUND7+ | number | 1 | Failure to find a storage device such as a memory card.| +| ERROR_FILE_ALREADY_EXISTS7+ | number | 2 | Failure to download the file because it already exists.| +| ERROR_FILE_ERROR7+ | number | 3 | File operation failure.| +| ERROR_HTTP_DATA_ERROR7+ | number | 4 | HTTP transmission failure.| +| ERROR_INSUFFICIENT_SPACE7+ | number | 5 | Insufficient storage space.| +| ERROR_TOO_MANY_REDIRECTS7+ | number | 6 | Error caused by too many network redirections.| +| ERROR_UNHANDLED_HTTP_CODE7+ | number | 7 | Unidentified HTTP code.| +| ERROR_UNKNOWN7+ | number | 8 | Unknown error.| +| ERROR_OFFLINE9+ | number | 9 | No network connection.| +| ERROR_UNSUPPORTED_NETWORK_TYPE9+ | number | 10 | Network type mismatch.| + + +### Causes of Download Pause +The table below lists the causes of download pause that may be returned by [getTaskInfo9+](#gettaskinfo9). + +| Name| Type| Value| Description| +| -------- | -------- | -------- | -------- | +| PAUSED_QUEUED_FOR_WIFI7+ | number | 0 | Download paused and queuing for a WLAN connection, because the file size exceeds the maximum value allowed by a mobile network session.| +| PAUSED_WAITING_FOR_NETWORK7+ | number | 1 | Download paused due to a network connection problem, for example, network disconnection.| +| PAUSED_WAITING_TO_RETRY7+ | number | 2 | Download paused and then retried.| +| PAUSED_BY_USER9+ | number | 3 | The user paused the session. | +| PAUSED_UNKNOWN7+ | number | 4 | Download paused due to unknown reasons.| + +### Download Task Status Codes +The table below lists the download task status codes that may be returned by [getTaskInfo9+](#gettaskinfo9). + +| Name| Type| Value| Description| +| -------- | -------- | -------- | -------- | +| SESSION_SUCCESSFUL7+ | number | 0 | Successful download.| +| SESSION_RUNNING7+ | number | 1 | Download in progress.| +| SESSION_PENDING7+ | number | 2 | Download pending.| +| SESSION_PAUSED7+ | number | 3 | Download paused.| +| SESSION_FAILED7+ | number | 4 | Download failure without retry.| ## request.uploadFile9+ @@ -111,11 +134,15 @@ For details about the error codes, see [Upload and Download Error Codes](../erro files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }], data: [{ name: "name123", value: "123" }], }; - request.uploadFile(globalThis.abilityContext, uploadConfig).then((data) => { + try { + request.uploadFile(globalThis.abilityContext, uploadConfig).then((data) => { uploadTask = data; - }).catch((err) => { - console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); - }); + }).catch((err) => { + console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); + }); + } catch (err) { + console.error('err.code : ' + err.code + ', err.message : ' + err.message); + } ``` @@ -155,13 +182,17 @@ For details about the error codes, see [Upload and Download Error Codes](../erro files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }], data: [{ name: "name123", value: "123" }], }; - request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { + try { + request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { if (err) { console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); return; } uploadTask = data; - }); + }); + } catch (err) { + console.error('err.code : ' + err.code + ', err.message : ' + err.message); + } ``` ## request.upload(deprecated) @@ -347,8 +378,6 @@ Uploads files. This API uses an asynchronous callback to return the result. Implements file uploads. Before using any APIs of this class, you must obtain an **UploadTask** object through [request.uploadFile9+](#requestuploadfile9) in promise mode or [request.uploadFile9+](#requestuploadfile9-1) in callback mode. - - ### on('progress') on(type: 'progress', callback:(uploadedSize: number, totalSize: number) => void): void @@ -366,12 +395,12 @@ Subscribes to an upload event. This API uses an asynchronous callback to return | type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (upload progress).| | callback | function | Yes| Callback for the upload progress event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| uploadedSize | number | Yes| Size of the uploaded files, in KB.| -| totalSize | number | Yes| Total size of the files to upload, in KB.| +| uploadedSize | number | Yes| Size of the uploaded files, in bytes. | +| totalSize | number | Yes| Total size of the files to upload, in bytes. | **Example** @@ -400,7 +429,7 @@ Subscribes to an upload event. This API uses an asynchronous callback to return | type | string | Yes| Type of the event to subscribe to. The value is **'headerReceive'** (response header).| | callback | function | Yes| Callback for the HTTP Response Header event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -433,7 +462,7 @@ Subscribes to an upload event. This API uses an asynchronous callback to return | type | string | Yes| Type of the event to subscribe to. The value **'complete'** means the upload completion event, and **'fail'** means the upload failure event.| | callback | Callback<Array<TaskState>> | Yes| Callback used to return the result.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -475,12 +504,12 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret | type | string | Yes| Type of the event to unsubscribe from. The value is **'progress'** (upload progress).| | callback | function | No| Callback for the upload progress event.| - Parameters of the callback function + Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| uploadedSize | number | Yes| Size of the uploaded files, in KB.| -| totalSize | number | Yes| Total size of the files to upload, in KB.| +| uploadedSize | number | Yes| Size of the uploaded files, in bytes. | +| totalSize | number | Yes| Total size of the files to upload, in bytes. | **Example** @@ -509,7 +538,7 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret | type | string | Yes| Type of the event to unsubscribe from. The value is **'headerReceive'** (response header).| | callback | function | No| Callback for the HTTP Response Header event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -541,7 +570,7 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret | type | string | Yes| Type of the event to subscribe to. The value **'complete'** means the upload completion event, and **'fail'** means the upload failure event.| | callback | Callback<Array<TaskState>> | No| Callback used to return the result.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -599,7 +628,7 @@ Deletes this upload task. This API uses a promise to return the result. delete(callback: AsyncCallback<boolean>): void -Removes this upload task. This API uses an asynchronous callback to return the result. +Deletes this upload task. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.INTERNET @@ -786,11 +815,15 @@ For details about the error codes, see [Upload and Download Error Codes](../erro ```js let downloadTask; - request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxx.hap' }).then((data) => { - downloadTask = data; - }).catch((err) => { - console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); - }) + try { + request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxx.hap' }).then((data) => { + downloadTask = data; + }).catch((err) => { + console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); + }) + } catch (err) { + console.error('err.code : ' + err.code + ', err.message : ' + err.message); + } ``` @@ -825,14 +858,18 @@ For details about the error codes, see [Upload and Download Error Codes](../erro ```js let downloadTask; - request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxxx.hap', - filePath: 'xxx/xxxxx.hap'}, (err, data) => { - if (err) { - console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); - return; - } - downloadTask = data; - }); + try { + request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxxx.hap', + filePath: 'xxx/xxxxx.hap'}, (err, data) => { + if (err) { + console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); + return; + } + downloadTask = data; + }); + } catch (err) { + console.error('err.code : ' + err.code + ', err.message : ' + err.message); + } ``` ## request.download(deprecated) @@ -1014,8 +1051,8 @@ Subscribes to a download event. This API uses an asynchronous callback to return | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| receivedSize | number | Yes| Size of the downloaded files, in KB.| -| totalSize | number | Yes| Total size of the files to download, in KB.| +| receivedSize | number | Yes| Size of the downloaded files, in bytes. | +| totalSize | number | Yes| Total size of the files to download, in bytes. | **Example** @@ -1044,12 +1081,12 @@ Unsubscribes from a download event. This API uses an asynchronous callback to re | type | string | Yes| Type of the event to unsubscribe from. The value is **'progress'** (download progress).| | callback | function | No| Callback for the download progress event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| receivedSize | number | Yes| Size of the downloaded files.| -| totalSize | number | Yes| Total size of the files to download.| +| receivedSize | number | Yes| Size of the downloaded files, in bytes. | +| totalSize | number | Yes| Total size of the files to download, in bytes. | **Example** @@ -1132,11 +1169,11 @@ Subscribes to the download task failure event. This API uses an asynchronous cal | type | string | Yes| Type of the event to subscribe to. The value is **'fail'** (download failure).| | callback | function | Yes| Callback for the download task failure event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| err | number | Yes| Error code of the download failure. For details about the error codes, see [ERROR_*](#constants).| +| err | number | Yes| Error code of the download failure. For details about the error codes, see [Download Error Codes](#download-error-codes).| **Example** @@ -1165,11 +1202,11 @@ Unsubscribes from the download task failure event. This API uses an asynchronous | type | string | Yes| Type of the event to unsubscribe from. The value is **'fail'** (download failure).| | callback | function | No| Callback for the download task failure event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| err | number | Yes| Error code of the download failure. For details about the error codes, see [ERROR_*](#constants).| +| err | number | Yes| Error code of the download failure. For details about the error codes, see [Download Error Codes](#download-error-codes).| **Example** @@ -1180,7 +1217,7 @@ Unsubscribes from the download task failure event. This API uses an asynchronous ); ``` - ### delete9+ +### delete9+ delete(): Promise<boolean> @@ -1248,7 +1285,7 @@ Removes this download task. This API uses an asynchronous callback to return the getTaskInfo(): Promise<DownloadInfo> -Queries this download task. This API uses a promise to return the result. +Obtains the information about this download task. This API uses a promise to return the result. **Required permissions**: ohos.permission.INTERNET @@ -1275,7 +1312,7 @@ Queries this download task. This API uses a promise to return the result. getTaskInfo(callback: AsyncCallback<DownloadInfo>): void -Queries this download task. This API uses an asynchronous callback to return the result. +Obtains the information about this download task. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.INTERNET @@ -1841,12 +1878,12 @@ Resumes this download task. This API uses an asynchronous callback to return the | -------- | -------- | -------- | -------- | | url | string | Yes| Resource URL.| | header | Object | No| HTTPS flag header to be included in the download request.
The **X-TLS-Version** parameter in **header** specifies the TLS version to be used. If this parameter is not set, the CURL_SSLVERSION_TLSv1_2 version is used. Available options are as follows:
CURL_SSLVERSION_TLSv1_0
CURL_SSLVERSION_TLSv1_1
CURL_SSLVERSION_TLSv1_2
CURL_SSLVERSION_TLSv1_3
The **X-Cipher-List** parameter in **header** specifies the cipher suite list to be used. If this parameter is not specified, the secure cipher suite list is used. Available options are as follows:
- The TLS 1.2 cipher suite list includes the following ciphers:
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
TLS_DHE_DSS_WITH_AES_128_GCM_SHA256,TLS_DSS_RSA_WITH_AES_256_GCM_SHA384,
TLS_PSK_WITH_AES_256_GCM_SHA384,TLS_DHE_PSK_WITH_AES_128_GCM_SHA256,
TLS_DHE_PSK_WITH_AES_256_GCM_SHA384,TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256,
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256,
TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256,TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_128_CCM,
TLS_DHE_RSA_WITH_AES_256_CCM,TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
TLS_PSK_WITH_AES_256_CCM,TLS_DHE_PSK_WITH_AES_128_CCM,
TLS_DHE_PSK_WITH_AES_256_CCM,TLS_ECDHE_ECDSA_WITH_AES_128_CCM,
TLS_ECDHE_ECDSA_WITH_AES_256_CCM,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
- The TLS 1.3 cipher suite list includes the following ciphers:
TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_CCM_SHA256
- The TLS 1.3 cipher suite list adds the Chinese national cryptographic algorithm:
TLS_SM4_GCM_SM3,TLS_SM4_CCM_SM3 | -| enableMetered | boolean | No| Whether download is allowed on a metered connection.
- **true**: yes
- **false**: no| -| enableRoaming | boolean | No| Whether download is allowed on a roaming network.
- **true**: yes
- **false**: no| +| enableMetered | boolean | No| Whether download is allowed on a metered connection.
- **true**: allowed
- **false**: not allowed | +| enableRoaming | boolean | No| Whether download is allowed on a roaming network.
- **true**: allowed
- **false**: not allowed | | description | string | No| Description of the download session.| -| filePath7+ | string | No| Download path. (The default path is **'internal://cache/'**.)
- filePath:'workspace/test.txt': The **workspace** directory is created in the default path to store files.
- filePath:'test.txt': Files are stored in the default path.
- filePath:'workspace/': The **workspace** directory is created in the default path to store files.| +| filePath7+ | string | No| Path where the downloaded file is stored.
- filePath:'/data/storage/el2/base/haps/entry/files/test.txt': Save the file to an absolute path.
- In the FA model, use [context](js-apis-inner-app-context.md#contextgetcachedir) to obtain the cache directory of the application, for example, **'${featureAbility.getContext().getFilesDir()}/test.txt'**, and store the file in this directory.
- In the stage model, use [AbilityContext](js-apis-inner-application-context.md) to obtain the fie path, for example, **'${globalThis.abilityContext.tempDir}/test.txt'**, and store the file in this path.| | networkType | number | No| Network type allowed for download.
- NETWORK_MOBILE: 0x00000001
- NETWORK_WIFI: 0x00010000| -| title | string | No| Title of the download session.| +| title | string | No| Download task name.| | background9+ | boolean | No| Whether to enable the background task notification. When this parameter is enabled, the download status is displayed in the notification panel.| @@ -1859,13 +1896,13 @@ Resumes this download task. This API uses an asynchronous callback to return the | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | downloadId | number | Yes| ID of the downloaded file.| -| failedReason | number | No| Download failure cause, which can be any constant of [ERROR_*](#constants).| +| failedReason | number | No| Cause of the download failure. The value can be any constant in [Download Error Codes](#download-error-codes).| | fileName | string | Yes| Name of the downloaded file.| | filePath | string | Yes| URI of the saved file.| -| pausedReason | number | No| Reason for session pause, which can be any constant of [PAUSED_*](#constants).| -| status | number | Yes| Download status code, which can be any constant of [SESSION_*](#constants).| +| pausedReason | number | No| Cause of download pause. The value can be any constant in [Causes of Download Pause](#causes-of-download-pause).| +| status | number | Yes| Download task status code. The value can be any constant in [Download Task Status Codes](#download-task-status-codes).| | targetURI | string | Yes| URI of the downloaded file.| -| downloadTitle | string | Yes| Title of the downloaded file.| -| downloadTotalBytes | number | Yes| Total size of the files to download (int bytes).| +| downloadTitle | string | Yes| Download task name.| +| downloadTotalBytes | number | Yes| Total size of the files to download, in bytes.| | description | string | Yes| Description of the file to download.| -| downloadedBytes | number | Yes| Size of the files downloaded (int bytes).| +| downloadedBytes | number | Yes| Size of the files downloaded, in bytes.| diff --git a/en/application-dev/reference/apis/js-apis-resource-manager.md b/en/application-dev/reference/apis/js-apis-resource-manager.md index 94bdfad0bea88187f0adddbd318580caf468fe02..5d215b54b33730d147c72c7e1e5981710640c543 100644 --- a/en/application-dev/reference/apis/js-apis-resource-manager.md +++ b/en/application-dev/reference/apis/js-apis-resource-manager.md @@ -97,6 +97,7 @@ Obtains the **ResourceManager** object of this application. This API uses a prom **System capability**: SystemCapability.Global.ResourceManager **Return value** + | Type | Description | | ---------------------------------------- | ----------------- | | Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result.| @@ -134,6 +135,7 @@ Obtains the **ResourceManager** object of an application based on the specified | bundleName | string | Yes | Bundle name of the application.| **Return value** + | Type | Description | | ---------------------------------------- | ------------------ | | Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result.| @@ -305,7 +307,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco **Example (stage)** ```ts try { - this.context.getStringValue($r('app.string.test').id, (error, value) => { + this.context.resourceManager.getStringValue($r('app.string.test').id, (error, value) => { if (error != null) { console.log("error is " + error); } else { @@ -333,6 +335,7 @@ Obtains the string corresponding to the specified resource ID. This API uses a p | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | --------------------- | ----------- | | Promise<string> | Promise used to return the result.| @@ -423,6 +426,7 @@ Obtains the string corresponding to the specified resource object. This API uses | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | --------------------- | ---------------- | | Promise<string> | Promise used to return the result.| @@ -512,6 +516,7 @@ Obtains the string array corresponding to the specified resource ID. This API us | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ---------------------------------- | ------------- | | Promise<Array<string>> | Promise used to return the result.| @@ -599,6 +604,7 @@ Obtains the string array corresponding to the specified resource object. This AP | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | ---------------------------------- | ------------------ | | Promise<Array<string>> | Promise used to return the result.| @@ -687,6 +693,7 @@ Obtains the content of the media file corresponding to the specified resource ID | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ------------------------- | -------------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -772,6 +779,7 @@ Obtains the content of the media file corresponding to the specified resource ob | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | ------------------------- | ------------------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -859,6 +867,7 @@ Obtains the Base64 code of the image corresponding to the specified resource ID. | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | --------------------- | -------------------- | | Promise<string> | Promise used to return the result.| @@ -944,6 +953,7 @@ Obtains the Base64 code of the image corresponding to the specified resource obj | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | --------------------- | ------------------------- | | Promise<string> | Promise used to return the result.| @@ -1014,6 +1024,7 @@ Obtains the device configuration. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Return value** + | Type | Description | | ---------------------------------------- | ---------------- | | Promise<[Configuration](#configuration)> | Promise used to return the result.| @@ -1069,6 +1080,7 @@ Obtains the device capability. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Return value** + | Type | Description | | ---------------------------------------- | ------------------- | | Promise<[DeviceCapability](#devicecapability)> | Promise used to return the result.| @@ -1144,6 +1156,7 @@ Obtains the singular-plural string corresponding to the specified resource ID ba | num | number | Yes | Number. | **Return value** + | Type | Description | | --------------------- | ------------------------- | | Promise<string> | Promise used to return the result.| @@ -1234,6 +1247,7 @@ Obtains the singular-plural string corresponding to the specified resource objec | num | number | Yes | Number. | **Return value** + | Type | Description | | --------------------- | ------------------------------ | | Promise<string> | Promise used to return the result.| @@ -1321,6 +1335,7 @@ Obtains the content of the raw file in the **resources/rawfile** directory. This | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ------------------------- | ----------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -1402,6 +1417,7 @@ Obtains the descriptor of the raw file in the **resources/rawfile** directory. T | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ---------------------------------------- | ------------------- | | Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the result.| @@ -1470,6 +1486,7 @@ Closes the descriptor of the raw file in the **resources/rawfile** directory. Th | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ------------------- | ---- | | Promise<void> | Promise that returns no value.| @@ -1538,6 +1555,7 @@ Closes the descriptor of the raw file in the **resources/rawfile** directory. Th | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ------------------- | ---- | | Promise<void> | Promise that returns no value.| @@ -1634,6 +1652,7 @@ Obtains the string corresponding to the specified resource name. This API uses a | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | --------------------- | ---------- | | Promise<string> | String corresponding to the resource name.| @@ -1716,6 +1735,7 @@ Obtains the string array corresponding to the specified resource name. This API | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | ---------------------------------- | ------------ | | Promise<Array<string>> | Promise used to return the result.| @@ -1798,6 +1818,7 @@ Obtains the content of the media file corresponding to the specified resource na | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | ------------------------- | ------------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -1880,6 +1901,7 @@ Obtains the Base64 code of the image corresponding to the specified resource nam | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | --------------------- | ------------------- | | Promise<string> | Promise used to return the result.| @@ -1965,6 +1987,7 @@ Obtains the plural string corresponding to the specified resource name based on | num | number | Yes | Number. | **Return value** + | Type | Description | | --------------------- | ---------------------- | | Promise<string> | Promise used to return the result.| @@ -2007,6 +2030,7 @@ Obtains the string corresponding to the specified resource ID. This API returns | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ------ | ----------- | | string | Promise used to return the result.| @@ -2045,6 +2069,7 @@ Obtains the string corresponding to the specified resource object. This API retu | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | ------ | ---------------- | | string | Promise used to return the result.| @@ -2088,6 +2113,7 @@ Obtains the string corresponding to the specified resource name. This API return | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | ------ | ---------- | | string | String corresponding to the specified resource name.| @@ -2126,6 +2152,7 @@ Obtains the Boolean result corresponding to the specified resource ID. This API | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ------- | ------------ | | boolean | Boolean result corresponding to the specified resource ID.| @@ -2163,6 +2190,7 @@ Obtains the Boolean result corresponding to the specified resource object. This | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | ------- | ----------------- | | boolean | Boolean result corresponding to the specified resource object.| @@ -2206,6 +2234,7 @@ Obtains the Boolean result corresponding to the specified resource name. This AP | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | ------- | ----------- | | boolean | Boolean result corresponding to the specified resource name.| @@ -2244,6 +2273,7 @@ Obtains the integer or float value corresponding to the specified resource ID. T | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ------ | ---------- | | number | Integer or float value corresponding to the specified resource ID.| @@ -2288,6 +2318,7 @@ Obtains the integer or float value corresponding to the specified resource objec | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | ------ | --------------- | | number | Integer or float value corresponding to the specified resource object.| @@ -2331,6 +2362,7 @@ Obtains the integer or float value corresponding to the specified resource name. | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | ------ | --------- | | number | Integer or float value corresponding to the specified resource name.| @@ -2409,6 +2441,7 @@ This API is deprecated since API version 9. You are advised to use [getStringVal | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | --------------------- | ----------- | | Promise<string> | Promise used to return the result.| @@ -2473,6 +2506,7 @@ This API is deprecated since API version 9. You are advised to use [getStringArr | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ---------------------------------- | ------------- | | Promise<Array<string>> | Promise used to return the result.| @@ -2495,7 +2529,7 @@ getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. -This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent) instead. +This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2526,7 +2560,7 @@ getMedia(resId: number): Promise<Uint8Array> Obtains the content of the media file corresponding to the specified resource ID. This API uses a promise to return the result. -This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent-1) instead. +This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9-1) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2537,6 +2571,7 @@ This API is deprecated since API version 9. You are advised to use [getMediaCont | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ------------------------- | -------------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -2559,7 +2594,7 @@ getMediaBase64(resId: number, callback: AsyncCallback<string>): void Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. -This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase64) instead. +This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2590,7 +2625,7 @@ getMediaBase64(resId: number): Promise<string> Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses a promise to return the result. -This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase64-1) instead. +This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649-1) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2601,6 +2636,7 @@ This API is deprecated since API version 9. You are advised to use [getMediaCont | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | --------------------- | -------------------- | | Promise<string> | Promise used to return the result.| @@ -2623,7 +2659,7 @@ getPluralString(resId: number, num: number): Promise<string> Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses a promise to return the result. -This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue) instead. +This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2635,6 +2671,7 @@ This API is deprecated since API version 9. You are advised to use [getPluralStr | num | number | Yes | Number. | **Return value** + | Type | Description | | --------------------- | ------------------------- | | Promise<string> | Promise used to return the result.| @@ -2657,7 +2694,7 @@ getPluralString(resId: number, num: number, callback: AsyncCallback<string> Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses an asynchronous callback to return the result. -This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue-1) instead. +This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9-1) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2731,6 +2768,7 @@ This API is deprecated since API version 9. You are advised to use [getRawFileCo | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ------------------------- | ----------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -2796,6 +2834,7 @@ This API is deprecated since API version 9. You are advised to use [getRawFd](#g | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ---------------------------------------- | ------------------- | | Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the result.| diff --git a/en/application-dev/reference/apis/js-apis-router.md b/en/application-dev/reference/apis/js-apis-router.md index 5e85658f698d0ca85ea2d422d648b020f5d02e4b..75d75ddb09e5c9e7d5d7028b02295cf24e8cf57e 100644 --- a/en/application-dev/reference/apis/js-apis-router.md +++ b/en/application-dev/reference/apis/js-apis-router.md @@ -1,4 +1,4 @@ -# Page Routing +# @ohos.router The **Router** module provides APIs to access pages through URLs. You can use the APIs to navigate to a specified page in an application, replace the current page with another one in an application, and return to the previous page or a specified page. @@ -40,9 +40,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | -| 100002 | Uri error. The uri of router is not exist. | -| 100003 | Page stack error. The pages are pushed too much. | +| 100001 | If UI execution context not found. | +| 100002 | If the uri is not exist. | +| 100003 | If the pages are pushed too much. | **Example** @@ -54,8 +54,8 @@ try { data1: 'message', data2: { data3: [123, 456, 789] - }, - }, + } + } }) .then(() => { // success @@ -89,9 +89,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | -| 100002 | Uri error. The uri of router is not exist. | -| 100003 | Page stack error. The pages are pushed too much. | +| 100001 | If UI execution context not found. | +| 100002 | If the uri is not exist. | +| 100003 | If the pages are pushed too much. | **Example** @@ -103,8 +103,8 @@ try { data1: 'message', data2: { data3: [123, 456, 789] - }, - }, + } + } }, (err) => { if (err) { console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); @@ -143,9 +143,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | -| 100002 | Uri error. The uri of router is not exist. | -| 100003 | Page stack error. The pages are pushed too much. | +| 100001 | If UI execution context not found. | +| 100002 | If the uri is not exist. | +| 100003 | If the pages are pushed too much. | **Example** @@ -157,8 +157,8 @@ try { data1: 'message', data2: { data3: [123, 456, 789] - }, - }, + } + } }, router.RouterMode.Standard) .then(() => { // success @@ -193,9 +193,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | -| 100002 | Uri error. The uri of router is not exist. | -| 100003 | Page stack error. The pages are pushed too much. | +| 100001 | If UI execution context not found. | +| 100002 | If the uri is not exist. | +| 100003 | If the pages are pushed too much. | **Example** @@ -207,8 +207,8 @@ try { data1: 'message', data2: { data3: [123, 456, 789] - }, - }, + } + } }, router.RouterMode.Standard, (err) => { if (err) { console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); @@ -247,8 +247,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | -| 200002 | Uri error. The uri of router is not exist. | +| 100001 | If UI execution context not found, only throw in standard system. | +| 200002 | If the uri is not exist. | **Example** @@ -257,8 +257,8 @@ try { router.replaceUrl({ url: 'pages/detail', params: { - data1: 'message', - }, + data1: 'message' + } }) .then(() => { // success @@ -292,8 +292,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | -| 200002 | Uri error. The uri of router is not exist. | +| 100001 | If UI execution context not found, only throw in standard system. | +| 200002 | If the uri is not exist. | **Example** @@ -302,8 +302,8 @@ try { router.replaceUrl({ url: 'pages/detail', params: { - data1: 'message', - }, + data1: 'message' + } }, (err) => { if (err) { console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`); @@ -344,8 +344,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | -| 200002 | Uri error. The uri of router is not exist. | +| 100001 | If UI execution context not found, only throw in standard system. | +| 200002 | If the uri is not exist. | **Example** @@ -354,8 +354,8 @@ try { router.replaceUrl({ url: 'pages/detail', params: { - data1: 'message', - }, + data1: 'message' + } }, router.RouterMode.Standard) .then(() => { // success @@ -390,8 +390,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | -| 200002 | Uri error. The uri of router is not exist. | +| 100001 | If UI execution context not found, only throw in standard system. | +| 200002 | If the uri is not exist. | **Example** @@ -400,8 +400,8 @@ try { router.replaceUrl({ url: 'pages/detail', params: { - data1: 'message', - }, + data1: 'message' + } }, router.RouterMode.Standard, (err) => { if (err) { console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`); @@ -465,7 +465,7 @@ Obtains the number of pages in the current stack. **Example** ```js -var size = router.getLength(); +let size = router.getLength(); console.log('pages stack size = ' + size); ``` @@ -486,7 +486,7 @@ Obtains state information about the current page. **Example** ```js -var page = router.getState(); +let page = router.getState(); console.log('current index = ' + page.index); console.log('current name = ' + page.name); console.log('current path = ' + page.path); @@ -498,11 +498,11 @@ Describes the page routing state. **System capability**: SystemCapability.ArkUI.ArkUI.Full -| Name | Type | Description | -| ----- | ------ | ---------------------------------- | -| index | number | Index of the current page in the stack. The index starts from 1 from the bottom to the top of the stack.| -| name | string | Name of the current page, that is, the file name. | -| path | string | Path of the current page. | +| Name | Type | Mandatory| Description | +| ----- | ------ | ---- | ------------------------------------------------------------ | +| index | number | Yes | Index of the current page in the stack. The index starts from 1 from the bottom to the top of the stack.| +| name | string | No | Name of the current page, that is, the file name. | +| path | string | Yes | Path of the current page. | ## router.enableBackPageAlert9+ @@ -524,7 +524,7 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc | ID | Error Message| | --------- | ------- | -| 100001 | Internal error. | +| 100001 | If UI execution context not found. | **Example** @@ -590,7 +590,7 @@ Describes the page routing options. | Name | Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | | url | string | Yes | URL of the target page, in either of the following formats:
- Absolute path of the page. The value is available in the pages list in the **config.json** file, for example:
- pages/index/index
- pages/detail/detail
- Particular path. If the URL is a slash (/), the home page is displayed.| -| params | Object | No | Data that needs to be passed to the target page during redirection. The target page can use **router.getParams()** to obtain the passed parameters, for example, **this.keyValue** (**keyValue** is the value of a key in **params**). In the web-like paradigm, these parameters can be directly used on the target page. If the field specified by **key** already exists on the target page, the passed value of the key will be displayed.| +| params | object | No | Data that needs to be passed to the target page during redirection. The target page can use **router.getParams()** to obtain the passed parameters, for example, **this.keyValue** (**keyValue** is the value of a key in **params**). In the web-like paradigm, these parameters can be directly used on the target page. If the field specified by **key** already exists on the target page, the passed value of the key will be displayed.| > **NOTE** @@ -602,9 +602,9 @@ Enumerates the routing modes. **System capability**: SystemCapability.ArkUI.ArkUI.Full -| Name | Description | -| -------- | ---------------------------------------- | -| Standard | Standard mode.
The target page is added to the top of the page stack, regardless of whether a page with the same URL exists in the stack. | +| Name | Description | +| -------- | ------------------------------------------------------------ | +| Standard | Standard mode.
The target page is added to the top of the page stack, regardless of whether a page with the same URL exists in the stack.| | Single | Singleton mode.
If the URL of the target page already exists in the page stack, the page closest to the top of the stack is moved as a new page to the top of the stack.
If the URL of the target page does not exist in the page stack, the page is redirected to in standard mode.| ## Examples @@ -618,8 +618,8 @@ export default { router.push({ url: 'pages/detail/detail', params: { - data1: 'message', - }, + data1: 'message' + } }); } } @@ -642,18 +642,18 @@ import router from '@ohos.router' @Entry @Component struct Index { - async routePage() { + async routePage() { let options = { url: 'pages/second', params: { text: 'This is the value on the first page.', data: { array: [12, 45, 78] - }, + } } } try { - await router.push(options) + await router.pushUrl(options) } catch (err) { console.info(` fail callback, code: ${err.code}, msg: ${err.msg}`) } @@ -661,18 +661,18 @@ struct Index { build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text('This is the first page.') - .fontSize(50) - .fontWeight(FontWeight.Bold) + Text('This is the first page.') + .fontSize(50) + .fontWeight(FontWeight.Bold) Button() { Text('next page') .fontSize(25) .fontWeight(FontWeight.Bold) }.type(ButtonType.Capsule) - .margin({ top: 20 }) - .backgroundColor('#ccc') - .onClick(() => { - this.routePage() + .margin({ top: 20 }) + .backgroundColor('#ccc') + .onClick(() => { + this.routePage() }) } .width('100%') @@ -704,7 +704,7 @@ struct Second { this.secondData = (this.data.array[1]).toString() }) .margin({top:20}) - Text('Value from the first page '+'' + this.secondData) + Text(`This is the data passed from the first page: ${this.secondData}`) .fontSize(20) .margin({top:20}) .backgroundColor('red') @@ -741,8 +741,8 @@ router.push({ data1: 'message', data2: { data3: [123, 456, 789] - }, - }, + } + } }); ``` ## router.push(deprecated) @@ -772,8 +772,8 @@ router.push({ data1: 'message', data2: { data3: [123, 456, 789] - }, - }, + } + } },router.RouterMode.Standard); ``` @@ -799,8 +799,8 @@ This API is deprecated since API version 9. You are advised to use [replaceUrl9+](#routerreplaceurl9) instead. -**System capability**: SystemCapability.ArkUI.ArkUI.Full +**System capability**: SystemCapability.ArkUI.ArkUI.Lite **Parameters** @@ -827,8 +827,8 @@ This API is deprecated since API version 9. You are advised to use [replaceUrl8+ @@ -2860,11 +2860,11 @@ Defines the lock information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| -------- | ------------------------ | ------ | -| lockType | [LockType](#locktype8) | Lock type.| -| password | string | Password. | -| state | [LockState](#lockstate8) | Lock state.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| lockType | [LockType](#locktype8) | Yes | Lock type.| +| password | string | Yes | Password. | +| state | [LockState](#lockstate8) | Yes | Lock state.| ## PersoLockInfo8+ @@ -2874,10 +2874,10 @@ Defines the personalized lock information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| -------- | -------------------------------- | ------------ | -| lockType | [PersoLockType](#persolocktype8) | Personalized lock type.| -| password | string | Password. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| lockType | [PersoLockType](#persolocktype8) | Yes | Personalized lock type.| +| password | string | Yes | Password. | ## IccAccountInfo7+ @@ -2887,15 +2887,15 @@ Defines the ICC account information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ---------- | ------- | ---------------- | -| simId | number | SIM card ID. | -| slotIndex | number | Card slot ID. | -| isEsim | boolean | Whether the SIM card is an eSim card.| -| isActive | boolean | Whether the card is activated. | -| iccId | string | ICCID number. | -| showName | string | SIM card display name. | -| showNumber | string | SIM card display number. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| simId | number | Yes | SIM card ID. | +| slotIndex | number | Yes | Card slot ID. | +| isEsim | boolean | Yes | Whether the SIM card is an eSim card.| +| isActive | boolean | Yes | Whether the card is activated. | +| iccId | string | Yes | ICCID number. | +| showName | string | Yes | SIM card display name. | +| showNumber | string | Yes | SIM card display number. | ## OperatorConfig8+ @@ -2905,10 +2905,10 @@ Defines the carrier configuration. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description| -| ----- | ------ | ---- | -| field | string | Field| -| value | string | Value | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| field | string | Yes | Field. | +| value | string | Yes | Value. | ## DiallingNumbersInfo8+ @@ -2918,12 +2918,12 @@ Defines the contact number information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------------ | ------ | -------- | -| alphaTag | string | Alpha tag. | -| number | string | Contact number. | -| recordNumber | number | Record number.| -| pin2 | string | PIN 2.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| alphaTag | string | Yes | Alpha tag. | +| number | string | Yes | Contact number. | +| recordNumber | number | Yes | Record number.| +| pin2 | string | Yes | PIN 2.| ## ContactType8+ @@ -2934,6 +2934,37 @@ Enumerates contact types. **System capability**: SystemCapability.Telephony.CoreService | Name | Value | Description | -| :-------------- | ---- | ---------- | +| -------------- | ---- | ---------- | | GENERAL_CONTACT | 1 | Common contact number.| | FIXED_DIALING | 2 | Fixed dialing number. | + +## OperatorConfigKey9+ + +Enumerates carrier configuration keys. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Telephony.CoreService + +| Name | Value | Description | +| ------------------------------------------------------- | ---------------------------------------------------- | -------------------- | +| KEY_VOICE_MAIL_NUMBER_STRING | "voice_mail_number_string" | Voice mailbox number. | +| KEY_IMS_SWITCH_ON_BY_DEFAULT_BOOL | "ims_switch_on_by_default_bool" | Fixed dialing number. | +| KEY_HIDE_IMS_SWITCH_BOOL | "hide_ims_switch_bool" | Whether to hide the IMS switch. | +| KEY_VOLTE_SUPPORTED_BOOL | "volte_supported_bool" | Whether to support VoLTE. | +| KEY_NR_MODE_SUPPORTED_LIST_INT_ARRAY | "nr_mode_supported_list_int_array" | List of supported NR modes. | +| KEY_VOLTE_PROVISIONING_SUPPORTED_BOOL | "volte_provisioning_supported_bool" | Whether to support VoLTE provisioning. | +| KEY_SS_OVER_UT_SUPPORTED_BOOL | "ss_over_ut_supported_bool" | Whether SS over UT is supported. | +| KEY_IMS_GBA_REQUIRED_BOOL | "ims_gba_required_bool" | Whether GBA is required for IMS. | +| KEY_UT_PROVISIONING_SUPPORTED_BOOL | "ut_provisioning_supported_bool" | Whether to support UT provisioning. | +| KEY_IMS_PREFER_FOR_EMERGENCY_BOOL | "ims_prefer_for_emergency_bool" | IMS preferences for emergency. | +| KEY_CALL_WAITING_SERVICE_CLASS_INT | "call_waiting_service_class_int" | Call waiting service. | +| KEY_CALL_TRANSFER_VISIBILITY_BOOL | "call_transfer_visibility_bool" | Call transfer visibility. | +| KEY_IMS_CALL_DISCONNECT_REASONINFO_MAPPING_STRING_ARRAY | "ims_call_disconnect_reasoninfo_mapping_string_array" | List of IMS call disconnection reasons.| +| KEY_FORCE_VOLTE_SWITCH_ON_BOOL | "force_volte_switch_on_bool" | Whether to forcibly turn on VoLTE. | +| KEY_ENABLE_OPERATOR_NAME_CUST_BOOL | "enable_operator_name_cust_bool" | Whether to display the carrier name.| +| KEY_OPERATOR_NAME_CUST_STRING | "operator_name_cust_string" | Carrier name. | +| KEY_SPN_DISPLAY_CONDITION_CUST_INT | "spn_display_condition_cust_int" | SPN display rule. | +| KEY_PNN_CUST_STRING_ARRAY | "pnn_cust_string_array" | PLMN name | +| KEY_OPL_CUST_STRING_ARRAY | "opl_cust_string_array" | PLMN information of the carrier. | +| KEY_EMERGENCY_CALL_STRING_ARRAY | "emergency_call_string_array" | Emergency call list. | diff --git a/en/application-dev/reference/apis/js-apis-sms.md b/en/application-dev/reference/apis/js-apis-sms.md index 7d372978202503f6ed0a0517fa69f85ae5dfcf44..c26311312c5cc2360ddf4f3784f66bba05b0f5b1 100644 --- a/en/application-dev/reference/apis/js-apis-sms.md +++ b/en/application-dev/reference/apis/js-apis-sms.md @@ -870,7 +870,7 @@ promise.then(data => { ## sms.isImsSmsSupported8+ -isImsSmsSupported(callback: AsyncCallback): void +isImsSmsSupported(slotId: number, callback: AsyncCallback): void Checks whether SMS is supported on IMS. This API uses an asynchronous callback to return the result. @@ -882,12 +882,14 @@ Checks whether SMS is supported on IMS. This API uses an asynchronous callback t | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ---------- | +| slotId | number | Yes | SIM card slot ID.
- **0**: card slot 1
- **1**: card slot 2| | callback | AsyncCallback<boolean> | Yes | Callback used to return the result.| **Example** ```js -sms.isImsSmsSupported((err, data) => { +let slotId = 0; +sms.isImsSmsSupported(slotId, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); ``` @@ -895,7 +897,7 @@ sms.isImsSmsSupported((err, data) => { ## sms.isImsSmsSupported8+ -isImsSmsSupported(): Promise +isImsSmsSupported(slotId: number): Promise Checks whether SMS is supported on IMS. This API uses a promise to return the result. @@ -903,6 +905,12 @@ Checks whether SMS is supported on IMS. This API uses a promise to return the re **System capability**: SystemCapability.Telephony.SmsMms +**Parameters** + +| Name| Type | Mandatory | Description | +| ------ | ------ | ---- | -------------------------------------- | +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2| + **Return value** | Type | Description | @@ -912,7 +920,8 @@ Checks whether SMS is supported on IMS. This API uses a promise to return the re **Example** ```js -let promise = sms.isImsSmsSupported(); +let slotId = 0; +let promise = sms.isImsSmsSupported(slotId); promise.then(data => { console.log(`isImsSmsSupported success, promise: data->${JSON.stringify(data)}`); }).catch(err => { @@ -1116,19 +1125,19 @@ Defines an SMS message instance. **System capability**: SystemCapability.Telephony.SmsMms -| Name | Type | Description | -| ------------------------ | --------------------------------------- | ------------------------------------------------------------ | -| hasReplyPath | boolean | Whether the received SMS contains **TP-Reply-Path**. The default value is **false**.
**TP-Reply-Path**: The device returns a response based on the SMSC that sends the SMS message.| -| isReplaceMessage | boolean | Whether the received SMS message is a **replace short message**. The default value is **false**.
For details, see section 9.2.3.9 in **3GPP TS 23.040**.| -| isSmsStatusReportMessage | boolean | Whether the received SMS message is an SMS delivery status report. The default value is **false**.
**SMS-Status-Report**: a message sent from the SMSC to the mobile station to show the SMS message delivery status.| -| messageClass | [ShortMessageClass](#shortmessageclass) | Enumerates SMS message types. | -| pdu | Array<number> | PDU in the SMS message. | -| protocolId | number | Protocol identifier used for delivering the SMS message. | -| scAddress | string | SMSC address. | -| scTimestamp | number | SMSC timestamp. | -| status | number | SMS message status sent by the SMSC in the **SMS-STATUS-REPORT** message.| -| visibleMessageBody | string | SMS message body. | -| visibleRawAddress | string | Sender address. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| hasReplyPath | boolean | Yes |Whether the received SMS contains **TP-Reply-Path**. The default value is **false**.
**TP-Reply-Path**: The device returns a response based on the SMSC that sends the SMS message.| +| isReplaceMessage | boolean | Yes |Whether the received SMS message is a **replace short message**. The default value is **false**.
For details, see section 9.2.3.9 in **3GPP TS 23.040**.| +| isSmsStatusReportMessage | boolean | Yes |Whether the received SMS message is an SMS delivery status report. The default value is **false**.
**SMS-Status-Report**: a message sent from the SMSC to the mobile station to show the SMS message delivery status.| +| messageClass | [ShortMessageClass](#shortmessageclass) | Yes | SMS message type. | +| pdu | Array<number> | Yes | PDU in the SMS message. | +| protocolId | number | Yes | Protocol identifier used for delivering the SMS message. | +| scAddress | string | Yes | SMSC address. | +| scTimestamp | number | Yes | SMSC timestamp. | +| status | number | Yes | SMS message status sent by the SMSC in the **SMS-STATUS-REPORT** message.| +| visibleMessageBody | string | Yes | SMS message body. | +| visibleRawAddress | string | Yes | Sender address. | ## ShortMessageClass diff --git a/en/application-dev/reference/apis/js-apis-socket.md b/en/application-dev/reference/apis/js-apis-socket.md index f298e41d6a667fcb00c5dfff450dd19089c40484..989cc9985727b1e43c828f354f76a3be8dae492f 100644 --- a/en/application-dev/reference/apis/js-apis-socket.md +++ b/en/application-dev/reference/apis/js-apis-socket.md @@ -22,7 +22,7 @@ Creates a **UDPSocket** object. **Return value** | Type | Description | -| :--------------------------------- | :---------------------- | +| --------------------------------- | ---------------------- | | [UDPSocket](#udpsocket) | **UDPSocket** object.| @@ -88,7 +88,7 @@ Binds the IP address and port number. The port number can be specified or random **Return value** | Type | Description | -| :-------------- | :----------------------------------------- | +| -------------- | ----------------------------------------- | | Promise\ | Promise used to return the result.| **Example** @@ -165,7 +165,7 @@ Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and p **Return value** | Type | Description | -| :-------------- | :--------------------------------------------- | +| -------------- | --------------------------------------------- | | Promise\ | Promise used to return the result.| **Example** @@ -231,7 +231,7 @@ Closes a UDPSocket connection. This API uses a promise to return the result. **Return value** | Type | Description | -| :-------------- | :----------------------------------------- | +| -------------- | ----------------------------------------- | | Promise\ | Promise used to return the result.| **Example** @@ -253,7 +253,7 @@ getState\(callback: AsyncCallback\): void Obtains the status of the UDPSocket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [bind](#bind) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -293,7 +293,7 @@ getState\(\): Promise Obtains the status of the UDPSocket connection. This API uses a promise to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [bind](#bind) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -303,7 +303,7 @@ Obtains the status of the UDPSocket connection. This API uses a promise to retur **Return value** | Type | Description | -| :----------------------------------------------- | :----------------------------------------- | +| ----------------------------------------------- | ----------------------------------------- | | Promise<[SocketStateBase](#socketstatebase)> | Promise used to return the result.| **Example** @@ -332,7 +332,7 @@ setExtraOptions\(options: UDPExtraOptions, callback: AsyncCallback\): voi Sets other properties of the UDPSocket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [bind](#bind) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -380,7 +380,7 @@ setExtraOptions\(options: UDPExtraOptions\): Promise Sets other properties of the UDPSocket connection. This API uses a promise to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [bind](#bind) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -396,7 +396,7 @@ Sets other properties of the UDPSocket connection. This API uses a promise to re **Return value** | Type | Description | -| :-------------- | :--------------------------------------------------- | +| -------------- | --------------------------------------------------- | | Promise\ | Promise used to return the result.| **Example** @@ -455,7 +455,7 @@ off\(type: 'message', callback?: Callback<\{message: ArrayBuffer, remoteInfo: So Disables listening for message receiving events of the UDPSocket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. **System capability**: SystemCapability.Communication.NetStack @@ -515,7 +515,7 @@ off\(type: 'listening' | 'close', callback?: Callback\): void Disables listening for data packet message events or close events of the UDPSocket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. **System capability**: SystemCapability.Communication.NetStack @@ -580,7 +580,7 @@ off\(type: 'error', callback?: ErrorCallback\): void Disables listening for error events of the UDPSocket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. **System capability**: SystemCapability.Communication.NetStack @@ -679,7 +679,7 @@ Creates a **TCPSocket** object. **Return value** | Type | Description | - | :--------------------------------- | :---------------------- | + | --------------------------------- | ---------------------- | | [TCPSocket](#tcpsocket) | **TCPSocket** object.| **Example** @@ -744,7 +744,7 @@ Binds the IP address and port number. The port number can be specified or random **Return value** | Type | Description | -| :-------------- | :------------------------------------------------------- | +| -------------- | ------------------------------------------------------- | | Promise\ | Promise used to return the result.| **Example** @@ -810,7 +810,7 @@ Sets up a connection to the specified IP address and port number. This API uses **Return value** | Type | Description | -| :-------------- | :--------------------------------------------------------- | +| -------------- | --------------------------------------------------------- | | Promise\ | Promise used to return the result.| **Example** @@ -832,7 +832,7 @@ send\(options: TCPSendOptions, callback: AsyncCallback\): void Sends data over a TCPSocket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [connect](#connect) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -874,7 +874,7 @@ send\(options: TCPSendOptions\): Promise Sends data over a TCPSocket connection. This API uses a promise to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [connect](#connect) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -890,7 +890,7 @@ Sends data over a TCPSocket connection. This API uses a promise to return the re **Return value** | Type | Description | -| :-------------- | :------------------------------------------------- | +| -------------- | ------------------------------------------------- | | Promise\ | Promise used to return the result.| **Example** @@ -958,7 +958,7 @@ Closes a TCPSocket connection. This API uses a promise to return the result. **Return value** | Type | Description | -| :-------------- | :----------------------------------------- | +| -------------- | ----------------------------------------- | | Promise\ | Promise used to return the result.| **Example** @@ -980,7 +980,7 @@ getRemoteAddress\(callback: AsyncCallback\): void Obtains the remote address of a socket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [connect](#connect) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -1019,7 +1019,7 @@ getRemoteAddress\(\): Promise Obtains the remote address of a socket connection. This API uses a promise to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [connect](#connect) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -1029,7 +1029,7 @@ Obtains the remote address of a socket connection. This API uses a promise to re **Return value** | Type | Description | -| :------------------------------------------ | :------------------------------------------ | +| ------------------------------------------ | ------------------------------------------ | | Promise<[NetAddress](#netaddress)> | Promise used to return the result.| **Example** @@ -1057,7 +1057,7 @@ getState\(callback: AsyncCallback\): void Obtains the status of the TCPSocket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [bind](#bind) or [connect](#connect) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -1097,7 +1097,7 @@ getState\(\): Promise Obtains the status of the TCPSocket connection. This API uses a promise to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [bind](#bind) or [connect](#connect) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -1107,7 +1107,7 @@ Obtains the status of the TCPSocket connection. This API uses a promise to retur **Return value** | Type | Description | -| :----------------------------------------------- | :----------------------------------------- | +| ----------------------------------------------- | ----------------------------------------- | | Promise<[SocketStateBase](#socketstatebase)> | Promise used to return the result.| @@ -1136,7 +1136,7 @@ setExtraOptions\(options: TCPExtraOptions, callback: AsyncCallback\): voi Sets other properties of the TCPSocket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [bind](#bind) or [connect](#connect) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -1185,7 +1185,7 @@ setExtraOptions\(options: TCPExtraOptions\): Promise Sets other properties of the TCPSocket connection. This API uses a promise to return the result. ->**NOTE** +>**NOTE**
>This API can be called only after [bind](#bind) or [connect](#connect) is successfully called. **Required permissions**: ohos.permission.INTERNET @@ -1201,7 +1201,7 @@ Sets other properties of the TCPSocket connection. This API uses a promise to re **Return value** | Type | Description | -| :-------------- | :--------------------------------------------------- | +| -------------- | --------------------------------------------------- | | Promise\ | Promise used to return the result.| @@ -1264,7 +1264,7 @@ off\(type: 'message', callback?: Callback<\{message: ArrayBuffer, remoteInfo: So Disables listening for message receiving events of the TCPSocket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. **System capability**: SystemCapability.Communication.NetStack @@ -1325,7 +1325,7 @@ off\(type: 'connect' | 'close', callback?: Callback\): void Disables listening for connection or close events of the TCPSocket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. **System capability**: SystemCapability.Communication.NetStack @@ -1389,7 +1389,7 @@ off\(type: 'error', callback?: ErrorCallback\): void Disables listening for error events of the TCPSocket connection. This API uses an asynchronous callback to return the result. ->**NOTE** +>**NOTE**
>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. **System capability**: SystemCapability.Communication.NetStack @@ -1465,7 +1465,7 @@ Creates a **TLSSocket** object. **Return value** | Type | Description | -| :--------------------------------- | :---------------------- | +| --------------------------------- | ---------------------- | | [TLSSocket](#tlssocket9) | **TLSSocket** object.| **Example** @@ -1535,7 +1535,7 @@ Binds the IP address and port number. This API uses a promise to return the resu **Return value** | Type | Description | -| :-------------- | :------------------------------------------------------- | +| -------------- | ------------------------------------------------------- | | Promise\ | Promise used to return the result. If the operation fails, an error message is returned.| **Error codes** @@ -1609,7 +1609,7 @@ Obtains the status of the TLSSocket connection. This API uses a promise to retur **Return value** | Type | Description | -| :----------------------------------------------- | :----------------------------------------- | +| ----------------------------------------------- | ----------------------------------------- | | Promise\<[SocketStateBase](#socketstatebase)> | Promise used to return the result. If the operation fails, an error message is returned.| **Error codes** @@ -1706,7 +1706,7 @@ Sets other properties of the TCPSocket connection after successful binding of th **Return value** | Type | Description | -| :-------------- | :--------------------------------------------------- | +| -------------- | --------------------------------------------------- | | Promise\ | Promise used to return the result. If the operation fails, an error message is returned.| **Error codes** @@ -1985,7 +1985,7 @@ Obtains the remote address of a TLSSocket connection. This API uses a promise to **Return value** | Type | Description | -| :------------------------------------------ | :------------------------------------------ | +| ------------------------------------------ | ------------------------------------------ | | Promise\<[NetAddress](#netaddress)> | Promise used to return the result. If the operation fails, an error message is returned.| **Error codes** @@ -2050,7 +2050,7 @@ Obtains the local digital certificate after a TLSSocket connection is establishe **Return value** -| Type | Description | +| Type | Description | | -------------- | -------------------- | | Promise\<[X509CertRawData](#x509certrawdata9)> | Promise used to return the result. If the operation fails, an error message is returned.| @@ -2491,7 +2491,7 @@ Defines TLS connection options. | -------------- | ------------------------------------- | --- |-------------- | | address | [NetAddress](#netaddress) | Yes | Gateway address. | | secureOptions | [TLSSecureOptions](#tlssecureoptions9) | Yes| TLS security options.| -| ALPNProtocols | Array\ | No| Application Layer Protocol Negotiation (ALPN) protocols. | +| ALPNProtocols | Array\ | Yes| Application Layer Protocol Negotiation (ALPN) protocols. | ## TLSSecureOptions9+ diff --git a/en/application-dev/reference/apis/js-apis-system-notification.md b/en/application-dev/reference/apis/js-apis-system-notification.md index 0a46cec929810e8f485a66b26445f1e3042b7672..608bb4d3d3ee2ec6d4c48e7d9b7a4abd01e52c2e 100644 --- a/en/application-dev/reference/apis/js-apis-system-notification.md +++ b/en/application-dev/reference/apis/js-apis-system-notification.md @@ -1,7 +1,6 @@ -# Notification +# @system.notification > **NOTE** -> > - The APIs of this module are no longer maintained since API version 7. You are advised to use [`@ohos.notification`](js-apis-notification.md). > > - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -18,22 +17,22 @@ import notification from '@system.notification'; **System capability**: SystemCapability.Notification.Notification -| Name | Readable| Writable| Type | Mandatory| Description | -| ----------- | --- | ---- | ---------------------------------------------- | ---- | ------------------------- | -| bundleName | Yes | Yes | string | Yes | Name of the application bundle to which the notification will be redirected after being clicked. | -| abilityName | Yes | Yes | string | Yes | Name of the application ability to which the notification will be redirected after being clicked.| -| uri | Yes | Yes | string | No | URI of the page to be redirected to. | +| Name | Type | Readable | Writable | Mandatory| Description | +| ----------- | ---------------------------------------------- | ---- | ------------------------- | ------------------------- | ------------------------- | +| bundleName | string | Yes | Yes | Yes | Name of the application bundle to which the notification will be redirected after being clicked. | +| abilityName | string | Yes | Yes | Yes | Name of the application ability to which the notification will be redirected after being clicked.| +| uri | string | Yes | Yes | No | URI of the page to be redirected to. | ## ShowNotificationOptions **System capability**: SystemCapability.Notification.Notification -| Name | Readable| Writable| Type | Mandatory| Description | -| ------------- | --- | ---- | ---------------------------------------------- | ---- | ------------------------- | -| contentTitle | Yes | Yes | string | No | Notification title. | -| contentText | Yes | Yes | string | No | Notification content. | -| clickAction | Yes | Yes | ActionResult | No | Action triggered when the notification is clicked. | +| Name | Type | Readable | Writable | Mandatory| Description | +| ------------- | ---------------------------------------------- | ---- | ------------------------- | ------------------------- | ------------------------- | +| contentTitle | string | Yes | Yes | No | Notification title. | +| contentText | string | Yes | Yes | No | Notification content. | +| clickAction | ActionResult | Yes | Yes | No | Action triggered when the notification is clicked. | ## notification.show diff --git a/en/application-dev/reference/apis/js-apis-system-request.md b/en/application-dev/reference/apis/js-apis-system-request.md index 18b94b676942abb856fa9bd709c1898a6f98588d..a2b939bf7d0983a25202fe11b7c5dd4ddd9d3665 100644 --- a/en/application-dev/reference/apis/js-apis-system-request.md +++ b/en/application-dev/reference/apis/js-apis-system-request.md @@ -1,9 +1,11 @@ -# Uploading and Downloading +# @system.request -> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** -> - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [`@ohos.request`](js-apis-request.md) instead. +The **system.request** module provides applications with basic upload and download capabilities. + +> **NOTE** +> - The APIs of this module are deprecated since API version 9. You are advised to use [`@ohos.request`](js-apis-request.md) instead. > -> - The initial APIs of this module are supported since API version 4. 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 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import @@ -13,179 +15,245 @@ import request from '@system.request'; ``` -## Required Permissions +## request.upload -ohos.permission.INTERNET. +upload(options: UploadRequestOptions): void +Uploads a file. This API returns no value. -## request.upload +**System capability**: SystemCapability.MiscServices.Upload -upload(Object): void +**Parameters** -Uploads files. + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | options | [UploadRequestOptions](#uploadrequestoptions) | Yes| Upload configurations.| -**Parameters** +**Example** -| Name | Type | Mandatory | Description | -| -------- | -------- | -------- | -------- | -| url | string | Yes | URL of the upload server. | -| header | Object | No | Request header. | -| method | string | No | Request methods available: **POST** and **PUT**. The default value is **POST**. | -| files | Array<File> | Yes | List of files to upload, which is submitted through **multipart/form-data**. | -| data | Array<RequestData> | No | Form data in the request body. | -| success | Function | No | Called when the download task is complete. | -| fail | Function | No | Called when downloading fails or the task does not exist. | -| complete | Function | No | Called when the execution is complete. | + ```js + let uploadRequestOptions = { + url: 'http://www.path.com', + method: 'POST', + files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }], + data: [{ name: "name123", value: "123" }], + success: function(data) { + console.info(' upload success, code:' + JSON.stringify(data)); + }, + fail: function(data, code) { + console.info(' upload fail data: ' + data + 'code: ' + code); + }, + complete: function (){ + console.info(' upload complete'); + } + } + try { + request.upload(uploadRequestOptions); + console.info('upload start '); + } catch(err) { + console.info(' upload err:' + err); + } + ``` -**Table 1** File -| Name | Type | Mandatory | Description | -| -------- | -------- | -------- | -------- | -| filename | string | No | File name in the header when **multipart** is used. | -| name | string | No | Name of a form item when **multipart** is used. The default value is **file**. | -| uri | string | Yes | Local storage path of a file. | -| type | string | No | Type of the file content. By default, the type is obtained based on the suffix of the file name or URI. | +## UploadRequestOptions -**Table 2** RequestData +**System capability**: SystemCapability.MiscServices.Upload -| Name | Type | Mandatory | Description | -| -------- | -------- | -------- | -------- | -| name | string | Yes | Name of the form element | -| value | string | Yes | Value of the form element | -When the files are successfully uploaded, the following values will be returned. + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | url | string | Yes| URL of the upload server.| + | data | Array<[RequestData](#requestdata)> | No| Form data in the request body.| + | files | Array<[RequestFile](#requestfile)> | Yes| List of files to upload, which is submitted through **multipart/form-data**.| + | header | Object | No| Request header.| + | method | string | No| Request method, which can be **'POST'** or **'PUT'**. The default value is **POST**.| + | success | Function | No| Called when API call is successful.| + | fail | Function | No| Called when API call has failed.| + | complete | Function | No| Called when API call is complete.| -| Name | Type | Description | -| -------- | -------- | -------- | -| code | number | HTTP status code returned by the server. | -| data | string | Content returned by the server. The value type is determined by the type in the returned headers. | -| headers | Object | Headers returned by the server. | +**success parameter** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | [UploadResponse](#uploadresponse) | Yes| Information returned when the upload task is successful.| -When the files fail to be uploaded, an HTTP status code is returned in **code** of **data**. +**fail parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | any | Yes| Header information returned when the upload task fails.| + | code | number | Yes| HTTP status code returned when the upload task fails.| -**Example** -``` -export default { - upLoad() { - request.upload({ - url: 'http://www.path.com', - files: [ - { - uri: 'internal://cache/path/to/file.txt', - name: 'file', - filename: 'file.txt', - }, - ], - data:[ - { - name: 'name1', - value: 'value', - }, - ], - success: function(data) { - console.log('upload success, code:' + data.code); - }, - fail: function() { - console.log('upload fail'); - }, - }); - } -} -``` +## UploadResponse -## request.download +**System capability**: SystemCapability.MiscServices.Upload -download(Object): void + | Name| Type| Description| + | -------- | -------- | -------- | + | code | number | HTTP status code returned by the server.| + | data | string | Content returned by the server. The value type is determined by the type in the returned headers.| + | headers | Object | Headers returned by the server.| -Downloads files. -**Parameters** +## RequestFile + +**System capability**: SystemCapability.MiscServices.Upload + + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | filename | string | No| File name in the header when **multipart** is used.| + | name | string | No| Name of a form item when **multipart** is used. The default value is **file**.| + | uri | string | Yes| Local path for storing files.| + | type | string | No| Type of the file content. By default, the type is obtained based on the extension of the file name or URI.| + + +## RequestData + +**System capability**: SystemCapability.MiscServices.Upload -| Name | Type | Mandatory | Description | -| -------- | -------- | -------- | -------- | -| url | string | Yes | Resource URL. | -| header | Object | No | Request header. | -| description | string | No | Download description. The default value is the file name. | -| filename | string | No | Name of the file to download. The value is obtained from the current request or resource URL by default. | -| success | Function | No | Called when the download task is complete. | -| fail | Function | No | Called when downloading fails or the task does not exist. | -| complete | Function | No | Called when the execution is complete. | + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | name | string | Yes| Name of the form element.| + | value | string | Yes| Value of the form element.| -Return values of the **success** callback -| Name | Type | Description | -| -------- | -------- | -------- | -| token | string | Download token, which is used to obtain the download status. | -One of the following error codes will be returned if the operation fails. +## request.download + +download(options: DownloadRequestOptions): void + +Downloads a file. This API returns no value. + +**System capability**: SystemCapability.MiscServices.Download + +**Parameters** -| Error Code | Description | -| -------- | -------- | -| 400 | Download task failed | + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | options | [DownloadRequestOptions](#downloadrequestoptions) | Yes| Download configurations.| **Example** -``` -export default { - downLoad() { - request.download({ - url: 'http://www.path.com', - success: function(data) { - console.log('call success callback success: ' + data.token); - }, - fail: function(data, code) { - console.log('handling fail'); - }, - }); + ```js + let downloadRequestOptions = { + url: 'http://www.path.com', + filename: 'requestSystenTest', + header: '', + description: 'this is requeSystem download response', + success: function(data) { + console.info(' download success, code:' + JSON.stringify(data)); + }, + fail: function(data, code) { + console.info(' download fail data: ' + data + 'code: ' + code); + }, + complete: function (){ + console.info(' download complete'); + } } -} -``` + try { + request.download(downloadRequestOptions); + console.info('download start '); + } catch(err) { + console.info(' download err:' + err); + } + ``` -## request.onDownloadComplete +## DownloadRequestOptions -onDownloadComplete(Object): void +**System capability**: SystemCapability.MiscServices.Download -Listens to download task status. + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | url | string | Yes| Resource URL.| + | filename | string | No| Name of the file to download. The value is obtained from the current request or resource URL by default.| + | header | Object | No| Request header.| + | description | string | No| Download description. The default value is the file name.| + | success | Function | No| Called when API call is successful.| + | fail | Function | No| Called when API call has failed.| + | complete | Function | No| Called when API call is complete.| -**Parameters** +**success parameter** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | [DownloadResponse](#downloadresponse) | Yes| Information returned when the download task is successful.| + +**fail parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | any | Yes| Header information returned when the download task fails.| + | code | number | Yes| HTTP status code returned when the download task fails.| + +## DownloadResponse + +**System capability**: SystemCapability.MiscServices.Download + + | Name| Type| Description| + | -------- | -------- | -------- | + | token | string | Download token, which is used to obtain the download status| + + +## request.onDownloadComplete -| Name | Type | Mandatory | Description | -| -------- | -------- | -------- | -------- | -| token | string | Yes | Token of the result returned by the download method | -| success | Function | No | Called when the download task is complete. | -| fail | Function | No | Called when downloading fails or the task does not exist. | -| complete | Function | No | Called when the execution is complete. | +onDownloadComplete(options: OnDownloadCompleteOptions): void -Return values of the **success** callback +Listens for download task status. This API returns no value. -| Name | Type | Description | -| -------- | -------- | -------- | -| uri | string | URI of the download file | +**System capability**: SystemCapability.MiscServices.Download -One of the following error codes will be returned if the listening fails. +**Parameters** -| Error Code | Description | -| -------- | -------- | -| 400 | Download task failed | -| 401 | Download task not exist | + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | options | [OnDownloadCompleteOptions](#ondownloadcompleteoptions) | Yes| Configurations of the download task.| **Example** -``` -export default { - onDownloadComplete() { - request.onDownloadComplete({ - token: 'token-index', - success: function(data) { - console.log('download success, uri:' + data.uri); - }, - fail: function(data, code) { - console.log('download fail'); - }, - }); + ```js + let onDownloadCompleteOptions = { + token: 'token-index', + success: function(data) { + console.info(' download success, code:' + JSON.stringify(data)); + }, + fail: function(data, code) { + console.info(' download fail data: ' + data + 'code: ' + code); + }, + complete: function (){ + console.info(' download complete'); + } } -} -``` \ No newline at end of file + request.onDownloadComplete(onDownloadCompleteOptions); + ``` + + +## OnDownloadCompleteOptions + +**System capability**: SystemCapability.MiscServices.Download + + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | token | string | Yes| Result token returned by the download API.| + | success | Function | No| Called when API call is successful.| + | fail | Function | No| Called when API call has failed.| + | complete | Function | No| Called when API call is complete.| + +**success parameter** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | [OnDownloadCompleteResponse](#ondownloadcompleteresponse) | Yes| Information returned when the download task is successful.| + +**fail parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | any | Yes| Header information returned when the download task fails.| + | code | number | Yes| HTTP status code returned when the download task fails.| + + +## OnDownloadCompleteResponse + +**System capability**: SystemCapability.MiscServices.Download + + | Name| Type| Description| + | -------- | -------- | -------- | + | uri | string | URI of the download file.| diff --git a/en/application-dev/reference/apis/js-apis-system-router.md b/en/application-dev/reference/apis/js-apis-system-router.md index 60e999026e58bb6510a24540609f9c6bc44aa55d..1d47c8883ae8d3cc4be49d19845ce1b3e3d5bb2a 100644 --- a/en/application-dev/reference/apis/js-apis-system-router.md +++ b/en/application-dev/reference/apis/js-apis-system-router.md @@ -1,4 +1,4 @@ -# Page Routing +# @system.router The **Router** module provides APIs to access pages through URIs. @@ -43,8 +43,8 @@ export default { data1: 'message', data2: { data3: [123, 456, 789] - }, - }, + } + } }); } } @@ -67,7 +67,8 @@ export default { } ``` -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> **NOTE** +> > The page routing stack supports a maximum of 32 pages. @@ -94,8 +95,8 @@ export default { router.replace({ uri: 'pages/detail/detail', params: { - data1: 'message', - }, + data1: 'message' + } }); } } @@ -135,7 +136,7 @@ Returns to the previous page or a specified page. export default { indexPushPage() { router.push({ - uri: 'pages/detail/detail', + uri: 'pages/detail/detail' }); } } @@ -147,7 +148,7 @@ export default { export default { detailPushPage() { router.push({ - uri: 'pages/mall/mall', + uri: 'pages/mall/mall' }); } } @@ -183,7 +184,8 @@ export default { } ``` -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> **NOTE** +> > In the example, the **uri** field indicates the page route, which is specified by the **pages** list in the **config.json** file. ## router.getParams @@ -237,7 +239,7 @@ Obtains the number of pages in the current stack. ```js export default { getLength() { - var size = router.getLength(); + let size = router.getLength(); console.log('pages stack size = ' + size); } } @@ -262,7 +264,7 @@ Obtains state information about the current page. ```js export default { getState() { - var page = router.getState(); + let page = router.getState(); console.log('current index = ' + page.index); console.log('current name = ' + page.name); console.log('current path = ' + page.path); @@ -296,7 +298,7 @@ export default { }, cancel: function() { console.log('cancel'); - }, + } }); } } @@ -327,7 +329,7 @@ export default { }, cancel: function() { console.log('cancel'); - }, + } }); } } @@ -339,10 +341,10 @@ Defines the page routing parameters. **System capability**: SystemCapability.ArkUI.ArkUI.Lite -| Name | Type | Mandatory | Description | -| ------ | ------ | ---- | ---------------------------------------- | -| uri | string | Yes | URI of the target page, in either of the following formats:
1. Absolute path, which is provided by the **pages** list in the **config.json** file. Example:
- pages/index/index
- pages/detail/detail
2. Specific path. If the URI is a slash (/), the home page is displayed.| -| params | Object | No | Data that needs to be passed to the target page during redirection. The target page can use **router.getParams()** to obtain the passed parameters, for example, **this.keyValue** (**keyValue** is the value of a key in **params**). In the web-like paradigm, these parameters can be directly used on the target page. If the field specified by **key** already exists on the target page, the passed value of the key will be displayed.| +| Name | Type| Mandatory| Description | +| ------ | -------- | ---- | ------------------------------------------------------------ | +| uri | string | Yes | URI of the target page, in either of the following formats:
1. Absolute path, which is provided by the **pages** list in the **config.json** file. Example:
- pages/index/index
- pages/detail/detail
2. Specific path. If the URI is a slash (/), the home page is displayed.| +| params | object | No | Data that needs to be passed to the target page during redirection. The target page can use **router.getParams()** to obtain the passed parameters, for example, **this.keyValue** (**keyValue** is the value of a key in **params**). In the web-like paradigm, these parameters can be directly used on the target page. If the field specified by **key** already exists on the target page, the passed value of the key will be displayed.| ## BackRouterOptions @@ -351,10 +353,10 @@ Defines the parameters for routing back. **System capability**: The items in the table below require different system capabilities. For details, see the table. -| Name | Type | Mandatory | Description | -| ------ | ------ | ---- | ---------------------------------------- | -| uri | string | No | URI of the page to return to. If the specified page does not exist in the page stack, the application does not respond. If this parameter is not set, the application returns to the previous page.
**System capability**: SystemCapability.ArkUI.ArkUI.Full| -| params | Object | No | Data that needs to be passed to the target page during redirection.
**System capability**: SystemCapability.ArkUI.ArkUI.Lite| +| Name | Type| Mandatory| Description | +| ------ | -------- | ---- | ------------------------------------------------------------ | +| uri | string | No | URI of the page to return to. If the specified page does not exist in the page stack, the application does not respond. If this parameter is not set, the application returns to the previous page.
**System capability**: SystemCapability.ArkUI.ArkUI.Full| +| params | object | No | Data that needs to be passed to the target page during redirection.
**System capability**: SystemCapability.ArkUI.ArkUI.Lite| ## RouterState diff --git a/en/application-dev/reference/apis/js-apis-touchevent.md b/en/application-dev/reference/apis/js-apis-touchevent.md index 9a68f0743cce6931d71d50456f041d816a6b4868..54b4eb2aa3aa9922867abb82cb11737995751a81 100644 --- a/en/application-dev/reference/apis/js-apis-touchevent.md +++ b/en/application-dev/reference/apis/js-apis-touchevent.md @@ -15,37 +15,37 @@ import {Action,ToolType,SourceType,Touch,TouchEvent} from '@ohos.multimodalInput **System capability**: SystemCapability.MultimodalInput.Input.Core -| Name| Type| Readable| Writable| Description| -| -------- | -------- | -------- | -------- | -------- | -| CANCEL | number | Yes| No| Cancellation of the touch action.| -| DOWN | number | Yes| No| Pressing of touch.| -| MOVE | number | Yes| No| Moving of touch.| -| UP | number | Yes| No| Lifting of touch.| +| Name | Value | Description | +| ------ | ----- | ----------- | +| CANCEL | 0 | Cancellation of the touch action.| +| DOWN | 1 | Pressing of touch. | +| MOVE | 2 | Moving of touch. | +| UP | 3 | Lifting of touch. | ## ToolType **System capability**: SystemCapability.MultimodalInput.Input.Core -| Name| Type| Readable| Writable| Description| -| -------- | -------- | -------- | -------- | -------- | -| FINGER | number | Yes| No| Finger| -| PEN | number | Yes| No| Pen| -| RUBBER | number | Yes| No| Eraser| -| BRUSH | number | Yes| No| Brush| -| PENCIL | number | Yes| No| Pencil| -| AIRBRUSH | number | Yes| No| Air brush| -| MOUSE | number | Yes| No| Mouse| -| LENS | number | Yes| No| Lens| +| Name | Value | Description | +| ---- | ----- | ----------- | +| FINGER | 0 | Finger| +| PEN | 1 | Pen| +| RUBBER | 2 | Eraser| +| BRUSH | 3 | Brush| +| PENCIL | 4 | Pencil| +| AIRBRUSH | 5 | Air brush| +| MOUSE | 6 | Mouse| +| LENS | 7 | Lens| ## SourceType **System capability**: SystemCapability.MultimodalInput.Input.Core -| Name| Type| Readable| Writable| Description| -| -------- | -------- | -------- | -------- | -------- | -| TOUCH_SCREEN | number | Yes| No| Touchscreen| -| PEN | number | Yes| No| Stylus| -| TOUCH_PAD | number | Yes| No| Touchpad| +| Name | Value | Description | +| ---- | ----- | ----------- | +| TOUCH_SCREEN | 0 | Touchscreen| +| PEN | 1 | Stylus | +| TOUCH_PAD | 2 | Touchpad | ## Touch @@ -70,7 +70,7 @@ import {Action,ToolType,SourceType,Touch,TouchEvent} from '@ohos.multimodalInput | toolHeight | number | Yes| No| Height of the tool area.| | rawX | number | Yes| No| X coordinate of the input device.| | rawY | number | Yes| No| Y coordinate of the input device.| -| toolType | number | Yes| No| Tool type.| +| toolType | ToolType | Yes| No| Tool type.| ## TouchEvent diff --git a/en/application-dev/reference/apis/js-apis-usb-deprecated.md b/en/application-dev/reference/apis/js-apis-usb-deprecated.md index ca250939af9aadf2c544dee30431c889331d332e..b3be9875df2554c6df5b8c358c9243d734d87874 100644 --- a/en/application-dev/reference/apis/js-apis-usb-deprecated.md +++ b/en/application-dev/reference/apis/js-apis-usb-deprecated.md @@ -638,16 +638,16 @@ Represents the USB endpoint from which data is sent or received. You can obtain **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| ------------- | ------------------------------------------- | ------------- | -| address | number | Endpoint address. | -| attributes | number | Endpoint attributes. | -| interval | number | Endpoint interval. | -| maxPacketSize | number | Maximum size of data packets on the endpoint. | -| direction | [USBRequestDirection](#usbrequestdirection) | Endpoint direction. | -| number | number | Endpoint number. | -| type | number | Endpoint type. | -| interfaceId | number | Unique ID of the interface to which the endpoint belongs.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| address | number | Yes | Endpoint address. | +| attributes | number | Yes | Endpoint attributes. | +| interval | number | Yes | Endpoint interval. | +| maxPacketSize | number | Yes | Maximum size of data packets on the endpoint. | +| direction | [USBRequestDirection](#usbrequestdirection) | Yes | Endpoint direction. | +| number | number | Yes | Endpoint number. | +| type | number | Yes | Endpoint type. | +| interfaceId | number | Yes | Unique ID of the interface to which the endpoint belongs.| ## USBInterface @@ -655,15 +655,15 @@ Represents a USB interface. One [USBConfig](#usbconfig) can contain multiple **U **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| ---------------- | ---------------------------------------- | --------------------- | -| id | number | Unique ID of the USB interface. | -| protocol | number | Interface protocol. | -| clazz | number | Device type. | -| subClass | number | Device subclass. | -| alternateSetting | number | Settings for alternating between descriptors of the same USB interface.| -| name | string | Interface name. | -| endpoints | Array<[USBEndpoint](#usbendpoint)> | Endpoints that belong to the USB interface. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| id | number | Yes | Unique ID of the USB interface. | +| protocol | number | Yes | Interface protocol. | +| clazz | number | Yes | Device type. | +| subClass | number | Yes | Device subclass. | +| alternateSetting | number | Yes | Settings for alternating between descriptors of the same USB interface.| +| name | string | Yes | Interface name. | +| endpoints | Array<[USBEndpoint](#usbendpoint)> | Yes | Endpoints that belong to the USB interface. | ## USBConfig @@ -671,15 +671,15 @@ Represents the USB configuration. One [USBDevice](#usbdevice) can contain multip **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| -------------- | ------------------------------------------------ | --------------- | -| id | number | Unique ID of the USB configuration. | -| attributes | number | Configuration attributes. | -| maxPower | number | Maximum power consumption, in mA. | -| name | string | Configuration name, which can be left empty. | -| isRemoteWakeup | boolean | Support for remote wakeup.| -| isSelfPowered | boolean | Support for independent power supplies.| -| interfaces | Array <[USBInterface](#usbinterface)> | Supported interface attributes. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| id | number | Yes | Unique ID of the USB configuration. | +| attributes | number | Yes | Configuration attributes. | +| maxPower | number | Yes | Maximum power consumption, in mA. | +| name | string | Yes | Configuration name, which can be left empty. | +| isRemoteWakeup | boolean | Yes | Support for remote wakeup.| +| isSelfPowered | boolean | Yes | Support for independent power supplies.| +| interfaces | Array <[USBInterface](#usbinterface)> | Yes | Supported interface attributes. | ## USBDevice @@ -687,21 +687,21 @@ Represents the USB device information. **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| ---------------- | ------------------------------------ | ---------- | -| busNum | number | Bus address. | -| devAddress | number | Device address. | -| serial | string | Sequence number. | -| name | string | Device name. | -| manufacturerName | string | Device manufacturer. | -| productName | string | Product name. | -| version | string | Version number. | -| vendorId | number | Vendor ID. | -| productId | number | Product ID. | -| clazz | number | Device class. | -| subClass | number | Device subclass. | -| protocol | number | Device protocol code. | -| configs | Array<[USBConfig](#usbconfig)> | Device configuration descriptor information.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| busNum | number | Yes | Bus address. | +| devAddress | number | Yes | Device address. | +| serial | string | Yes | Sequence number. | +| name | string | Yes | Device name. | +| manufacturerName | string | Yes | Device manufacturer. | +| productName | string | Yes | Product name. | +| version | string | Yes | Version number. | +| vendorId | number | Yes | Vendor ID. | +| productId | number | Yes | Product ID. | +| clazz | number | Yes | Device class. | +| subClass | number | Yes | Device subclass. | +| protocol | number | Yes | Device protocol code. | +| configs | Array<[USBConfig](#usbconfig)> | Yes | Device configuration descriptor information.| ## USBDevicePipe @@ -709,10 +709,10 @@ Represents a USB device pipe, which is used to determine a USB device. **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| ---------- | ------ | ----- | -| busNum | number | Bus address.| -| devAddress | number | Device address.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| busNum | number | Yes | Bus address.| +| devAddress | number | Yes | Device address.| ## USBControlParams @@ -720,14 +720,14 @@ Represents control transfer parameters. **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| ------- | ----------------------------------------------- | ---------------- | -| request | number | Request type. | -| target | [USBRequestTargetType](#usbrequesttargettype) | Request target type. | -| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Control request type. | -| value | number | Request parameter value. | -| index | number | Index of the request parameter value.| -| data | Uint8Array | Buffer for writing or reading data. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| request | number | Yes | Request type. | +| target | [USBRequestTargetType](#usbrequesttargettype) | Yes | Request target type. | +| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes | Control request type. | +| value | number | Yes | Request parameter value. | +| index | number | Yes | Index of the request parameter value.| +| data | Uint8Array | Yes | Buffer for writing or reading data. | ## USBPort9+ @@ -737,11 +737,11 @@ Represents a USB port. **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| -------------- | -------------------------------- | ----------------------------------- | -| id | number | Unique identifier of a USB port. | -| supportedModes | [PortModeType](#portmodetype9) | Numeric mask combination for the supported mode list.| -| status | [USBPortStatus](#usbportstatus9) | USB port role. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| id | number | Yes | Unique identifier of a USB port. | +| supportedModes | [PortModeType](#portmodetype9) | Yes | Numeric mask combination for the supported mode list.| +| status | [USBPortStatus](#usbportstatus9) | Yes | USB port role. | ## USBPortStatus9+ @@ -751,11 +751,11 @@ Enumerates USB port roles. **System capability**: SystemCapability.USB.USBManager -| Name | Type| Description | -| ---------------- | -------- | ---------------------- | -| currentMode | number | Current USB mode. | -| currentPowerRole | number | Current power role. | -| currentDataRole | number | Current data role.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| currentMode | number | Yes | Current USB mode. | +| currentPowerRole | number | Yes | Current power role. | +| currentDataRole | number | Yes | Current data role. | ## USBRequestTargetType diff --git a/en/application-dev/reference/apis/js-apis-usb.md b/en/application-dev/reference/apis/js-apis-usb.md index dca5776e6093ab384429fc6c6fc59b7d026510a7..b7e1c63263649704212259e7c4b3735d28617e5f 100644 --- a/en/application-dev/reference/apis/js-apis-usb.md +++ b/en/application-dev/reference/apis/js-apis-usb.md @@ -719,14 +719,14 @@ Represents the USB endpoint from which data is sent or received. You can obtain | Name | Type | Mandatory |Description | | ------------- | ------------------------------------------- | ------------- |------------- | -| address | number | Yes|Endpoint address. | -| attributes | number | Yes|Endpoint attributes. | -| interval | number | Yes|Endpoint interval. | -| maxPacketSize | number | Yes|Maximum size of data packets on the endpoint. | -| direction | [USBRequestDirection](#usbrequestdirection) | Yes|Endpoint direction. | -| number | number | Yes|Endpoint number. | -| type | number | Yes|Endpoint type. | -| interfaceId | number | Yes|Unique ID of the interface to which the endpoint belongs.| +| address | number | Yes | Endpoint address. | +| attributes | number | Yes | Endpoint attributes. | +| interval | number | Yes | Endpoint interval. | +| maxPacketSize | number | Yes | Maximum size of data packets on the endpoint. | +| direction | [USBRequestDirection](#usbrequestdirection) | Yes | Endpoint direction. | +| number | number | Yes | Endpoint number. | +| type | number | Yes | Endpoint type. | +| interfaceId | number | Yes | Unique ID of the interface to which the endpoint belongs.| ## USBInterface @@ -736,13 +736,13 @@ Represents a USB interface. One [USBConfig](#usbconfig) can contain multiple **U | Name | Type | Mandatory |Description | | ---------------- | ---------------------------------------- | ------------- |--------------------- | -| id | number | Yes|Unique ID of the USB interface. | -| protocol | number | Yes|Interface protocol. | -| clazz | number | Yes|Device type. | -| subClass | number | Yes|Device subclass. | -| alternateSetting | number | Yes|Settings for alternating between descriptors of the same USB interface.| -| name | string | Yes|Interface name. | -| endpoints | Array<[USBEndpoint](#usbendpoint)> | Yes|Endpoints that belong to the USB interface. | +| id | number | Yes | Unique ID of the USB interface. | +| protocol | number | Yes | Interface protocol. | +| clazz | number | Yes | Device type. | +| subClass | number | Yes | Device subclass. | +| alternateSetting | number | Yes | Settings for alternating between descriptors of the same USB interface.| +| name | string | Yes | Interface name. | +| endpoints | Array<[USBEndpoint](#usbendpoint)> | Yes | Endpoints that belong to the USB interface. | ## USBConfig @@ -752,13 +752,13 @@ Represents the USB configuration. One [USBDevice](#usbdevice) can contain multip | Name | Type | Mandatory |Description | | -------------- | ------------------------------------------------ | --------------- |--------------- | -| id | number | Yes|Unique ID of the USB configuration. | -| attributes | number | Yes|Configuration attributes. | -| maxPower | number | Yes|Maximum power consumption, in mA. | -| name | string | Yes|Configuration name, which can be left empty. | -| isRemoteWakeup | boolean | Yes|Support for remote wakeup.| -| isSelfPowered | boolean | Yes| Support for independent power supplies.| -| interfaces | Array <[USBInterface](#usbinterface)> | Yes|Supported interface attributes. | +| id | number | Yes | Unique ID of the USB configuration. | +| attributes | number | Yes | Configuration attributes. | +| maxPower | number | Yes | Maximum power consumption, in mA. | +| name | string | Yes | Configuration name, which can be left empty. | +| isRemoteWakeup | boolean | Yes | Support for remote wakeup.| +| isSelfPowered | boolean | Yes | Support for independent power supplies.| +| interfaces | Array <[USBInterface](#usbinterface)> | Yes | Supported interface attributes. | ## USBDevice @@ -768,19 +768,19 @@ Represents the USB device information. | Name | Type | Mandatory |Description | | ---------------- | ------------------------------------ | ---------- |---------- | -| busNum | number | Yes|Bus address. | -| devAddress | number | Yes|Device address. | -| serial | string | Yes|Sequence number. | -| name | string | Yes|Device name. | -| manufacturerName | string | Yes| Device manufacturer. | -| productName | string | Yes|Product name. | -| version | string | Yes|Version number. | -| vendorId | number | Yes|Vendor ID. | -| productId | number | Yes|Product ID. | -| clazz | number | Yes|Device class. | -| subClass | number | Yes|Device subclass. | -| protocol | number | Yes|Device protocol code. | -| configs | Array<[USBConfig](#usbconfig)> | Yes|Device configuration descriptor information.| +| busNum | number | Yes | Bus address. | +| devAddress | number | Yes | Device address. | +| serial | string | Yes | Sequence number. | +| name | string | Yes | Device name. | +| manufacturerName | string | Yes | Device manufacturer. | +| productName | string | Yes | Product name. | +| version | string | Yes | Version number. | +| vendorId | number | Yes | Vendor ID. | +| productId | number | Yes | Product ID. | +| clazz | number | Yes | Device class. | +| subClass | number | Yes | Device subclass. | +| protocol | number | Yes | Device protocol code. | +| configs | Array<[USBConfig](#usbconfig)> | Yes | Device configuration descriptor information.| ## USBDevicePipe @@ -801,12 +801,12 @@ Represents control transfer parameters. | Name | Type | Mandatory |Description | | ------- | ----------------------------------------------- | ---------------- |---------------- | -| request | number | Yes |Request type. | -| target | [USBRequestTargetType](#usbrequesttargettype) | Yes |Request target type. | -| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes |Control request type. | -| value | number | Yes |Request parameter value. | -| index | number | Yes |Index of the request parameter value.| -| data | Uint8Array | Yes |Buffer for writing or reading data. | +| request | number | Yes | Request type. | +| target | [USBRequestTargetType](#usbrequesttargettype) | Yes | Request target type. | +| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes | Control request type. | +| value | number | Yes | Request parameter value. | +| index | number | Yes | Index of the request parameter value.| +| data | Uint8Array | Yes | Buffer for writing or reading data. | ## USBPort @@ -818,9 +818,9 @@ Represents a USB port. | Name | Type | Mandatory |Description | | -------------- | ------------------------------- | ------------------- |------------------------ | -| id | number | Yes |Unique identifier of a USB port. | -| supportedModes | [PortModeType](#portmodetype) | Yes |Numeric mask combination for the supported mode list.| -| status | [USBPortStatus](#usbportstatus) | Yes |USB port role. | +| id | number | Yes | Unique identifier of a USB port. | +| supportedModes | [PortModeType](#portmodetype) | Yes | Numeric mask combination for the supported mode list.| +| status | [USBPortStatus](#usbportstatus) | Yes | USB port role. | ## USBPortStatus @@ -832,9 +832,9 @@ Enumerates USB port roles. | Name | Type| Mandatory |Description | | ---------------- | -------- | ---------------- |---------------------- | -| currentMode | number | Yes|Current USB mode. | -| currentPowerRole | number | Yes |Current power role. | -| currentDataRole | number | Yes |Current data role.| +| currentMode | number | Yes | Current USB mode. | +| currentPowerRole | number | Yes | Current power role. | +| currentDataRole | number | Yes | Current data role.| ## USBRequestTargetType @@ -842,12 +842,12 @@ Enumerates request target types. **System capability**: SystemCapability.USB.USBManager -| Name | Value | Description | -| ---------------------------- | ---- | ------ | -| USB_REQUEST_TARGET_DEVICE | 0 | Device| -| USB_REQUEST_TARGET_INTERFACE | 1 | Interface| -| USB_REQUEST_TARGET_ENDPOINT | 2 | Endpoint| -| USB_REQUEST_TARGET_OTHER | 3 | Other| +| Name | Value | Description | +| ---------------------------- | ----- | ----------- | +| USB_REQUEST_TARGET_DEVICE | 0 | Device | +| USB_REQUEST_TARGET_INTERFACE | 1 | Interface | +| USB_REQUEST_TARGET_ENDPOINT | 2 | Endpoint | +| USB_REQUEST_TARGET_OTHER | 3 | Other | ## USBControlRequestType diff --git a/en/application-dev/reference/apis/js-apis-userFileManager.md b/en/application-dev/reference/apis/js-apis-userFileManager.md new file mode 100644 index 0000000000000000000000000000000000000000..5249fa7cc0feff1afbf6e79fe7fb3263434d346a --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-userFileManager.md @@ -0,0 +1,2471 @@ +# @ohos.filemanagement.userFileManager + +The **userFileManager** module provides user data management capabilities, including accessing and modifying user media data (audio and video clips, images, and files). + +> **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 system APIs. + +## Modules to Import + +```ts +import userFileManager from '@ohos.filemanagement.userFileManager'; +``` + +## userFileManager.getUserFileMgr + +getUserFileMgr(context: Context): UserFileManager + +Obtains a **UserFileManager** instance. This instance can be used to access and modify user media data (such as audio and video clips, images, and files). + +**Model restriction**: This API can be used only in the stage model. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | ------- | ---- | -------------------------- | +| context | [Context](js-apis-inner-app-context.md) | Yes | Context of the ability instance.| + +**Return value** + +| Type | Description | +| ----------------------------- | :---- | +| [UserFileManager](#userfilemanager) | **UserFileManager** instance obtained.| + +**Example** + +```ts +const context = getContext(this); +let mgr = userFileManager.getUserFileMgr(context); +``` + +## UserFileManager + +### getPhotoAssets + +getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; + + +Obtains image and video assets. This API uses an asynchronous callback to return the result. + + + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ------------------------- | +| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets. | +| callback | AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes | Callback invoked to return the image and video assets obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getPhotoAssets'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOptions = { + fetchColumns: [], + predicates: predicates + }; + + mgr.getPhotoAssets(fetchOptions, async (err, fetchResult) => { + if (fetchResult != undefined) { + console.info('fetchResult success'); + let fileAsset = await fetchResult.getFirstObject(); + if (fileAsset != undefined) { + console.info("fileAsset.displayName :" + fileAsset.displayName); + } + } else { + console.info('fetchResult fail' + err); + } + }); +} +``` + + +### getPhotoAssets + +getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; + +Obtains image and video assets. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | ------------------- | ---- | ---------------- | +| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets. | + +**Return value** + +| Type | Description | +| --------------------------- | -------------- | +| Promise<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Promise used to return the image and video assets obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getPhotoAssets'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOptions = { + fetchColumns: [], + predicates: predicates + }; + try { + var fetchResult = await mgr.getPhotoAssets(fetchOptions); + if (fetchResult != undefined) { + console.info('fetchResult success'); + let fileAsset = await fetchResult.getFirstObject(); + if (fileAsset != undefined) { + console.info("fileAsset.displayName :" + fileAsset.displayName); + } + } + } catch (err) { + console.info('getPhotoAssets failed, message = ', err); + } +} +``` +### createPhotoAsset + +createPhotoAsset(displayName: string, albumUri: string, callback: AsyncCallback<FileAsset>): void; + +Creates an image or video asset. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ------------------------- | +| displayName | string | Yes | File name of the image or video to create. | +| albumUri | string | Yes | URI of the album where the image or video is located. | +| callback | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the image or video created.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('createPhotoAssetDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOptions = { + predicates: predicates + }; + let albums = await mgr.getPhotoAlbums(fetchOptions); + let album = await albums.getFirstObject(); + let testFileName = "testFile" + Date.now() + ".jpg"; + mgr.createPhotoAsset(testFileName, album.albumUri, (err, fileAsset) => { + if (fileAsset != undefined) { + console.info('createPhotoAsset file displayName' + fileAsset.displayName); + console.info('createPhotoAsset successfully'); + } else { + console.info('createPhotoAsset failed, message = ', err); + } + }); +} +``` + +### createPhotoAsset + +createPhotoAsset(displayName: string, callback: AsyncCallback<FileAsset>): void; + +Creates an image or video asset. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ------------------------- | +| displayName | string | Yes | File name of the image or video to create. | +| callback | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the image or video created.| + +**Example** + +```ts +async function example() { + console.info('createPhotoAssetDemo'); + let testFileName = "testFile" + Date.now() + ".jpg"; + mgr.createPhotoAsset(testFileName, (err, fileAsset) => { + if (fileAsset != undefined) { + console.info('createPhotoAsset file displayName' + fileAsset.displayName); + console.info('createPhotoAsset successfully'); + } else { + console.info('createPhotoAsset failed, message = ', err); + } + }); +} +``` + +### createPhotoAsset + +createPhotoAsset(displayName: string, albumUri?: string): Promise<FileAsset>; + +Creates an image or video asset. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ------------------------- | +| displayName | string | Yes | File name of the image or video to create. | +| albumUri | string | No | URI of the album where the image or video is located. | + +**Return value** + +| Type | Description | +| --------------------------- | -------------- | +| Promise<[FileAsset](#fileasset)> | Promise used to return the image or video created.| + +**Example** + +```ts +async function example() { + console.info('createPhotoAssetDemo'); + try { + let testFileName = "testFile" + Date.now() + ".jpg"; + let fileAsset = await mgr.createPhotoAsset(testFileName); + console.info('createPhotoAsset file displayName' + fileAsset.displayName); + console.info('createPhotoAsset successfully'); + } catch (err) { + console.info('createPhotoAsset failed, message = ', err); + } +} +``` + +### getPhotoAlbums + +getPhotoAlbums(options: AlbumFetchOptions, callback: AsyncCallback<FetchResult<Album>>): void; + + +Obtains image and video albums. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ------------------------- | +| options | [AlbumFetchOptions](#albumfetchoptions) | Yes | Options for fetching the albums. | +| callback | AsyncCallback<[FetchResult](#fetchresult)<[Album](#album)>> | Yes | Callback invoked to return the albums obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getPhotoAlbumsDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let albumFetchOptions = { + predicates: predicates + }; + + mgr.getPhotoAlbums(albumFetchOptions, (err, fetchResult) => { + if (fetchResult != undefined) { + console.info('albums.count = ' + fetchResult.getCount()); + fetchResult.getFirstObject((err, album) => { + if (album != undefined) { + console.info('first album.albumName = ' + album.albumName); + } else { + console.info('album is undefined, err = ', err); + } + }); + } else { + console.info('getPhotoAlbums fail, message = ', err); + } + }); +} +``` + +### getPhotoAlbums + +getPhotoAlbums(options: AlbumFetchOptions): Promise<FetchResult<Album>>; + +Obtains image and video albums. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ------------------------- | +| options | [AlbumFetchOptions](#albumfetchoptions) | Yes | Options for fetching the albums. | + +**Return value** + +| Type | Description | +| --------------------------- | -------------- | +| Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the albums obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getPhotoAlbumsDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let albumFetchOptions = { + predicates: predicates + }; + try { + let fetchResult = await mgr.getPhotoAlbums(albumFetchOptions); + console.info('album.count = ' + fetchResult.getCount()); + const album = await fetchResult.getFirstObject(); + console.info('first album.albumName = ' + album.albumName); + } catch (err) { + console.info('getPhotoAlbums fail, message = ' + err); + } +} +``` + +### getPrivateAlbum + +getPrivateAlbum(type: PrivateAlbumType, callback: AsyncCallback<FetchResult<PrivateAlbum>>): void; + + +Obtains the system album. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ------------------------- | +| type | [PrivateAlbumType](#privatealbumtype) | Yes | Type of the album to obtain. | +| callback | AsyncCallback<[FetchResult](#fetchresult)<[PrivateAlbum](#privatealbum)>> | Yes | Callback invoked to return the album obtained.| + +**Example** + +```ts +async function example() { + console.info('getPrivateAlbumDemo'); + mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH, async (err, fetchResult) => { + if (fetchResult != undefined) { + let trashAlbum = await fetchResult.getFirstObject(); + console.info('first album.albumName = ' + trashAlbum.albumName); + } else { + console.info('getPrivateAlbum failed. message = ', err); + } + }); +} +``` + +### getPrivateAlbum + +getPrivateAlbum(type: PrivateAlbumType): Promise<FetchResult<PrivateAlbum>>; + + +Obtains the system album. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ------------------------- | +| type | [PrivateAlbumType](#privatealbumtype) | Yes | Type of the album to obtain. | + +**Return value** + +| Type | Description | +| --------------------------- | -------------- | +| Promise<[FetchResult](#fetchresult)<[PrivateAlbum](#privatealbum)>> | Promise used to return the album obtained.| + +**Example** + +```ts +async function example() { + console.info('getPrivateAlbumDemo'); + try { + var fetchResult = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); + let trashAlbum = await fetchResult.getFirstObject(); + console.info('first album.albumName = ' + trashAlbum.albumName); + } catch (err) { + console.info('getPrivateAlbum failed. message = ', err); + } +} +``` + +### getAudioAssets + +getAudioAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; + + +Obtains audio assets. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Required permissions**: ohos.permission.READ_AUDIO + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ------------------------- | +| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the audio assets. | +| callback | AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes | Callback invoked to return the audio assets obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getAudioAssets'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOptions = { + fetchColumns: [], + predicates: predicates + }; + + mgr.getAudioAssets(fetchOptions, async (err, fetchResult) => { + if (fetchResult != undefined) { + console.info('fetchFileResult success'); + let fileAsset = await fetchResult.getFirstObject(); + if (fileAsset != undefined) { + console.info("fileAsset.displayName :" + fileAsset.displayName); + } + } else { + console.info('fetchFileResult fail' + err); + } + }); +} +``` + +### getAudioAssets + +getAudioAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; + + +Obtains audio assets. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Required permissions**: ohos.permission.READ_AUDIO + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ------------------------- | +| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the audio assets. | + +**Return value** + +| Type | Description | +| --------------------------- | -------------- | +| Promise<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Promise used to return the audio assets obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getAudioAssets'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOptions = { + fetchColumns: [], + predicates: predicates + }; + try { + var fetchResult = await mgr.getAudioAssets(fetchOptions); + } catch (err) { + console.info('getAudioAssets failed, message = ', err); + } + + if (fetchResult != undefined) { + console.info('fetchFileResult success'); + let fileAsset = await fetchResult.getFirstObject(); + if (fileAsset != undefined) { + console.info("fileAsset.displayName :" + fileAsset.displayName); + } + } +} +``` +### delete + +delete(uri: string, callback: AsyncCallback<void>): void; + +Deletes a media file. This API uses an asynchronous callback to return the result. The deleted file is moved to the recycle bin. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| uri | string | Yes | URI of the media file to delete.| +| callback | AsyncCallback<void> | Yes | Callback that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('deleteAssetDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOptions = { + fetchColumns: [], + predicates: predicates + }; + try { + const fetchResult = await mgr.getPhotoAssets(fetchOptions); + var asset = await fetchResult.getFirstObject(); + } catch (err) { + console.info('fetch failed, message =', err); + } + + if (asset == undefined) { + console.error('asset not exist'); + return; + } + mgr.delete(asset.uri, (err) => { + if (err == undefined) { + console.info("delete successfully"); + } else { + console.info("delete failed with error:" + err); + } + }); +} +``` +### delete + +delete(uri: string): Promise<void>; + +Deletes a media file. This API uses a promise to return the result. The deleted file is moved to the recycle bin. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| uri | string | Yes | URI of the media file to delete.| + +**Return value** + +| Type | Description | +| --------------------------------------- | ----------------- | +| Promise<void>| Promise that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('deleteDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOptions = { + fetchColumns: [], + predicates: predicates + }; + try { + const fetchResult = await mgr.getPhotoAssets(fetchOptions); + var asset = await fetchResult.getFirstObject(); + } catch (err) { + console.info('fetch failed, message =', err); + } + + if (asset == undefined) { + console.error('asset not exist'); + return; + } + try { + await mgr.delete(asset.uri); + console.info("delete successfully"); + } catch (err) { + console.info("delete failed with error:" + err); + } +} +``` + +### on + +on(type: ChangeEvent, callback: Callback<void>): void + +Subscribes to changes of the file management library. This API uses a callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| type | [ChangeEvent](#changeevent) | Yes | Type of event to subscribe to.
**deviceChange** indicates the device change.
**albumChange** indicates the album change.
**imageChange** indicates the image change.
**audioChange** indicates the audio file change.
**videoChange** indicates the video file change.
**remoteFileChange** indicates the file change on the registered device.| +| callback | Callback<void> | Yes | Callback that returns no value. | + +**Example** + +```ts +async function example() { + console.info('onDemo'); + let count = 0; + mgr.on('imageChange', () => { + count++; + // Image file changed. Do something. + }); + try { + let testFileName = "testFile" + Date.now() + ".jpg"; + let fileAsset = await mgr.createPhotoAsset(testFileName); + console.info('createPhotoAsset file displayName' + fileAsset.displayName); + console.info('createPhotoAsset successfully'); + } catch (err) { + console.info('createPhotoAsset failed, message = ' + err); + } + //sleep 1s + if (count > 0) { + console.info("onDemo success"); + } else { + console.info("onDemo fail"); + } + mgr.off('imageChange', () => { + // Unsubscription succeeds. + }); +} +``` + +### off + +off(type: ChangeEvent, callback?: Callback<void>): void + +Unsubscribes from changes of the file management library. This API uses a callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| type | [ChangeEvent](#changeevent) | Yes | Type of event to subscribe to.
**deviceChange** indicates the device change.
**albumChange** indicates the album change.
**imageChange** indicates the image change.
**audioChange** indicates the audio file change.
**videoChange** indicates the video file change.
**remoteFileChange** indicates the file change on the registered device.| +| callback | Callback<void> | No | Callback that returns no value. | + +**Example** + +```ts +async function example() { + console.info('offDemo'); + let count = 0; + mgr.on('imageChange', () => { + count++; + // Image file changed. Do something. + }); + + mgr.off('imageChange', () => { + // Unsubscription succeeds. + }); + + try { + let testFileName = "testFile" + Date.now() + ".jpg"; + let fileAsset = await mgr.createPhotoAsset(testFileName); + console.info('createPhotoAsset file displayName' + fileAsset.displayName); + console.info('createPhotoAsset successfully'); + } catch (err) { + console.info('createPhotoAsset failed, message = ' + err); + } + //sleep 1s + if (count == 0) { + console.info("offDemo success"); + } else { + console.info("offDemo fail"); + } +} +``` + +### getActivePeers + +getActivePeers(callback: AsyncCallback<Array<PeerInfo>>): void; + +Obtains information about online peer devices. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ------------ | +| callback | AsyncCallback<Array<[PeerInfo](#peerinfo)>> | Yes | Callback invoked to return the online peer device list.| + +**Example** + +```ts +async function example() { + console.info('getActivePeersDemo'); + mgr.getActivePeers((err, devicesInfo) => { + if (devicesInfo != undefined) { + console.log('getActivePeers succeed.'); + for (let i = 0; i < devicesInfo.length; i++) { + console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); + } + } else { + console.info('getActivePeers failed. message = ', err); + } + }); +} +``` + +### getActivePeers + +getActivePeers(): Promise<Array<PeerInfo>>; + +Obtains information about online peer devices. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore + +**Return value** + +| Type | Description | +| --------------------------- | ----------------------------- | +| Promise<Array<[PeerInfo](#peerinfo)>> | Promise used to return the online device list.| + +**Example** + +```ts +async function example() { + console.info('getActivePeersDemo'); + try { + var devicesInfo = await mgr.getActivePeers(); + } catch (err) { + console.info('getActivePeers failed. message = ', err); + } + if (devicesInfo != undefined) { + console.log('getActivePeers succeed.'); + for (let i = 0; i < devicesInfo.length; i++) { + console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); + } + } else { + console.info('get distributed fail'); + } +} +``` + +### getAllPeers + +getAllPeers(callback: AsyncCallback<Array<PeerInfo>>): void; + +Obtains information about all peer devices. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ------------ | +| callback | AsyncCallback<Array<[PeerInfo](#peerinfo)>> | Yes | Callback invoked to return the online peer device list.| + +**Example** + +```ts +async function example() { + console.info('getAllPeersDemo'); + mgr.getAllPeers((err, devicesInfo) => { + if (devicesInfo != undefined) { + console.log('getAllPeers succeed.'); + for (let i = 0; i < devicesInfo.length; i++) { + console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); + } + } else { + console.info('getAllPeers failed. message = ', err); + } + }); +} +``` + +### getAllPeers + +getAllPeers(): Promise<Array<PeerInfo>>; + +Obtains information about all peer devices. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore + +**Return value** + +| Type | Description | +| --------------------------- | ----------------------------- | +| Promise<Array<[PeerInfo](#peerinfo)>> | Promise used to return the peer device list.| + +**Example** + +```ts +async function example() { + console.info('getAllPeersDemo'); + try { + var devicesInfo = await mgr.getAllPeers(); + } catch (err) { + console.info('getAllPeers failed. message = ', err); + } + if (devicesInfo != undefined) { + console.log('getAllPeers succeed.'); + for (let i = 0; i < devicesInfo.length; i++) { + console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); + } + } else { + console.info('get distributed fail'); + } +} +``` + +### release + +release(callback: AsyncCallback<void>): void + +Releases this **UserFileManager** instance. This API uses an asynchronous callback to return the result. +Call this API when the APIs in the **UserFileManager** instance are no longer used. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | -------------------- | +| callback | AsyncCallback<void> | Yes | Callback that returns no value.| + +**Example** + +```ts +async function example() { + console.info('releaseDemo'); + mgr.release((err) => { + if (err != undefined) { + console.info('release failed. message = ', err); + } else { + console.info('release ok.'); + } + }); +} +``` + +### release + +release(): Promise<void> + +Releases this **UserFileManager** instance. This API uses a promise to return the result. +Call this API when the APIs in the **UserFileManager** instance are no longer used. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Return value** + +| Type | Description | +| ------------------- | --------------------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + +```ts +async function example() { + console.info('releaseDemo'); + try { + await mgr.release(); + console.info('release ok.'); + } catch (err) { + console.info('release failed. message = ', err); + } +} +``` + +## FileAsset + +Provides APIs for encapsulating file asset attributes. + +### Attributes + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Type | Readable| Writable| Description | +| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ | +| uri | string | Yes | No | File asset URI, for example, **dataability:///media/image/2**. | +| fileType | [FileType](#filetype) | Yes | No | Type of the file. | +| displayName | string | Yes | Yes | File name, including the file name extension, to display. | + + +### get + +get(member: string): MemberType; + +Obtains the value of a **FileAsset** parameter. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ----- | +| member | string | Yes | Name of the parameter to obtain, for example, **ImageVideoKey.URI**.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('fileAssetGetDemo'); + try { + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + let fileAsset = await fetchResult.getFirstObject(); + let title = userFileManager.ImageVideoKey.TITLE; + let fileAssetTitle = fileAsset.get(title.toString()); + console.info('fileAsset Get fileAssetTitle = ', fileAssetTitle); + } catch (err) { + console.info('release failed. message = ', err); + } +} +``` + +### set + +set(member: string, value: string): void; + +Sets a **FileAsset** parameter. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ----- | +| member | string | Yes | Name of the parameter to set, for example, **ImageVideoKey.URI**.| +| value | string | Yes | Value to set. Only the value of **ImageVideoKey.TITLE** can be changed.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('fileAssetSetDemo'); + try { + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + let fileAsset = await fetchResult.getFirstObject(); + let title = userFileManager.ImageVideoKey.TITLE; + fileAsset.set(title.toString(), "newTitle"); + } catch (err) { + console.info('release failed. message = ', err); + } +} +``` + +### commitModify + +commitModify(callback: AsyncCallback<void>): void + +Commits the modification on the file metadata to the database. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ----- | +| callback | AsyncCallback<void> | Yes | Callback that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('commitModifyDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + let fileAsset = await fetchResult.getFirstObject(); + let title = userFileManager.ImageVideoKey.TITLE; + let fileAssetTitle = fileAsset.get(title.toString()); + console.info('fileAsset Get fileAssetTitle = ', fileAssetTitle); + fileAsset.set(title.toString(), "newTitle"); + fileAsset.commitModify((err) => { + if (err == undefined) { + let newFileAssetTitle = fileAsset.get(title.toString()); + console.info('fileAsset Get newFileAssetTitle = ', newFileAssetTitle); + } else { + console.info('commitModify failed, message =', err); + } + }); +} +``` + +### commitModify + +commitModify(): Promise<void> + +Commits the modification on the file metadata to the database. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Return value** + +| Type | Description | +| ------------------- | ---------- | +| Promise<void> | Promise that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('commitModifyDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + let fileAsset = await fetchResult.getFirstObject(); + let title = userFileManager.ImageVideoKey.TITLE; + let fileAssetTitle = fileAsset.get(title.toString()); + console.info('fileAsset Get fileAssetTitle = ', fileAssetTitle); + fileAsset.set(title.toString(), "newTitle"); + try { + await fileAsset.commitModify(); + let newFileAssetTitle = fileAsset.get(title.toString()); + console.info('fileAsset Get newFileAssetTitle = ', newFileAssetTitle); + } catch (err) { + console.info('release failed. message = ', err); + } +} +``` + +### open + +open(mode: string, callback: AsyncCallback<number>): void + +Opens this file asset. This API uses an asynchronous callback to return the result. + +>**NOTE** +> +>The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, ohos.permission.WRITE_IMAGEVIDEO, or ohos.permission.WRITE_AUDIO + + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ----------------------------------- | +| mode | string | Yes | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).| +| callback | AsyncCallback<number> | Yes | Callback used to return the file handle. | + +**Example** + +```ts +async function example() { + console.info('openDemo'); + let testFileName = "testFile" + Date.now() + ".jpg"; + const fileAsset = await mgr.createPhotoAsset(testFileName); + fileAsset.open('rw', (err, fd) => { + if (fd != undefined) { + console.info('File fd' + fd); + fileAsset.close(fd); + } else { + console.info('File err' + err); + } + }); +} +``` + +### open + +open(mode: string): Promise<number> + +Opens this file asset. This API uses a promise to return the result. + +>**NOTE** +> +>The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, ohos.permission.WRITE_IMAGEVIDEO, or ohos.permission.WRITE_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ----------------------------------- | +| mode | string | Yes | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).| + +**Return value** + +| Type | Description | +| --------------------- | ------------- | +| Promise<number> | Promise used to return the file handle.| + +**Example** + +```ts +async function example() { + console.info('openDemo'); + try { + let testFileName = "testFile" + Date.now() + ".jpg"; + const fileAsset = await mgr.createPhotoAsset(testFileName); + let fd = await fileAsset.open('rw'); + if (fd != undefined) { + console.info('File fd' + fd); + fileAsset.close(fd); + } else { + console.info(' open File fail'); + } + } catch (err) { + console.info('open Demo err' + err); + } +} +``` + +### close + +close(fd: number, callback: AsyncCallback<void>): void + +Closes this file asset. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ----- | +| fd | number | Yes | File descriptor.| +| callback | AsyncCallback<void> | Yes | Callback that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('closeDemo'); + try { + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + const fileAsset = await fetchResult.getFirstObject(); + let fd = await fileAsset.open('rw'); + console.info('file fd', fd); + fileAsset.close(fd, (err) => { + if (err == undefined) { + console.info('asset close succeed.'); + } else { + console.info('close failed, message = ' + err); + } + }); + } catch (err) { + console.info('close failed, message = ' + err); + } +} +``` + +### close + +close(fd: number): Promise<void> + +Closes this file asset. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ----- | +| fd | number | Yes | File descriptor.| + +**Return value** + +| Type | Description | +| ------------------- | ---------- | +| Promise<void> | Promise that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('closeDemo'); + try { + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + const asset = await fetchResult.getFirstObject(); + let fd = await asset.open('rw'); + console.info('file fd', fd); + await asset.close(fd); + console.info('asset close succeed.'); + } catch (err) { + console.info('close failed, message = ' + err); + } +} +``` + +### getThumbnail + +getThumbnail(callback: AsyncCallback<image.PixelMap>): void + +Obtains the thumbnail of this file asset. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ----------------------------------- | ---- | ---------------- | +| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes | Callback invoked to return the pixel map of the thumbnail.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getThumbnailDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + const asset = await fetchResult.getFirstObject(); + console.info('asset displayName = ', asset.displayName); + asset.getThumbnail((err, pixelMap) => { + if (err == undefined) { + console.info('getThumbnail successful ' + pixelMap); + } else { + console.info('getThumbnail fail', err); + } + }); +} +``` + +### getThumbnail + +getThumbnail(size: image.Size, callback: AsyncCallback<image.PixelMap>): void + +Obtains the file thumbnail of the given size. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ----------------------------------- | ---- | ---------------- | +| size | [image.Size](js-apis-image.md#size) | Yes | Size of the thumbnail to obtain. | +| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes | Callback invoked to return the pixel map of the thumbnail.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getThumbnailDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let size = { width: 720, height: 720 }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + const asset = await fetchResult.getFirstObject(); + console.info('asset displayName = ', asset.displayName); + asset.getThumbnail(size, (err, pixelMap) => { + if (err == undefined) { + console.info('getThumbnail successful ' + pixelMap); + } else { + console.info('getThumbnail fail', err); + } + }); +} +``` + +### getThumbnail + +getThumbnail(size?: image.Size): Promise<image.PixelMap> + +Obtains the file thumbnail of the given size. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | -------------- | ---- | ----- | +| size | [image.Size](js-apis-image.md#size) | No | Size of the thumbnail to obtain.| + +**Return value** + +| Type | Description | +| ----------------------------- | --------------------- | +| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise used to return the pixel map of the thumbnail.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getThumbnailDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let size = { width: 720, height: 720 }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + const asset = await fetchResult.getFirstObject(); + console.info('asset displayName = ', asset.displayName); + asset.getThumbnail(size).then((pixelMap) => { + console.info('getThumbnail successful ' + pixelMap); + }).catch((err) => { + console.info('getThumbnail fail' + err); + }); +} +``` + +### favorite + +favorite(isFavorite: boolean, callback: AsyncCallback<void>): void + +Favorites or unfavorites this file asset. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---------- | ------------------------- | ---- | ---------------------------------- | +| isFavorite | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| +| callback | AsyncCallback<void> | Yes | Callback that returns no value. | + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('favoriteDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + const asset = await fetchResult.getFirstObject(); + asset.favorite(true, (err) => { + if (err == undefined) { + console.info("favorite successfully"); + } else { + console.info("favorite failed with error:" + err); + } + }); +} +``` + +### favorite + +favorite(isFavorite: boolean): Promise<void> + +Favorites or unfavorites this file asset. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---------- | ------- | ---- | ---------------------------------- | +| isFavorite | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| + +**Return value** + +| Type | Description | +| ------------------- | ---------- | +| Promise<void> | Promise that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('favoriteDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + const asset = await fetchResult.getFirstObject(); + asset.favorite(true).then(function () { + console.info("favorite successfully"); + }).catch(function (err) { + console.info("favorite failed with error:" + err); + }); +} +``` + +## FetchResult + +Provides APIs to manage the file retrieval result. + +### getCount + +getCount(): number + +Obtains the total number of files in the result set. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Return value** + +| Type | Description | +| ------ | -------- | +| number | Total number of files.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getCountDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + const fetchCount = fetchResult.getCount(); + console.info('fetchCount = ', fetchCount); +} +``` + +### isAfterLast + +isAfterLast(): boolean + +Checks whether the cursor is in the last row of the result set. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Return value** + +| Type | Description | +| ------- | ---------------------------------- | +| boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + const fetchCount = fetchResult.getCount(); + console.info('count:' + fetchCount); + let fileAsset = await fetchResult.getLastObject(); + if (!fetchResult.isAfterLast()) { + console.info('fileAsset isAfterLast displayName = ', fileAsset.displayName); + } else { + console.info('fileAsset not isAfterLast '); + } +} +``` + +### close + +close(): void + +Releases and invalidates this **FetchFileResult** instance. After this instance is released, the APIs in this instance cannot be invoked. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('fetchResultCloseDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + try { + let fetchResult = await mgr.getPhotoAssets(fetchOption); + await fetchResult.close(); + console.info('close succeed.'); + } catch (err) { + console.info('close fail. message = ' + err); + } +} +``` + +### getFirstObject + +getFirstObject(callback: AsyncCallback<T>): void + +Obtains the first file asset in the result set. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------- | ---- | ------------------------------------------- | +| callback | AsyncCallback<T> | Yes | Callback invoked to return the first file asset.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getFirstObjectDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + fetchResult.getFirstObject((err, fileAsset) => { + if (fileAsset != undefined) { + console.info('fileAsset displayName: ', fileAsset.displayName); + } else { + console.info("fileAsset failed with err:" + err); + } + }); +} +``` + +### getFirstObject + +getFirstObject(): Promise<T> + +Obtains the first file asset in the result set. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Return value** + +| Type | Description | +| --------------------------------------- | -------------------------- | +| Promise<T> | Promise used to return the first file asset.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getFirstObjectDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + let fileAsset = await fetchResult.getFirstObject(); + console.info('fileAsset displayName: ', fileAsset.displayName); +} +``` + +### getNextObject + + getNextObject(callback: AsyncCallback<T>): void + +Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | --------------------------------------------- | ---- | ----------------------------------------- | +| callbacke | AsyncCallback<T> | Yes | Callback invoked to return the next file asset.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getNextObjectDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + await fetchResult.getFirstObject(); + if (fetchResult.isAfterLast()) { + fetchResult.getNextObject((err, fileAsset) => { + if (fileAsset != undefined) { + console.info('fileAsset displayName: ', fileAsset.displayName); + } else { + console.info("fileAsset failed with err:" + err); + } + }); + } +} +``` + +### getNextObject + + getNextObject(): Promise<T> + +Obtains the next file asset in the result set. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Return value** + +| Type | Description | +| --------------------------------------- | ----------------- | +| Promise<T> | Promise used to return the next file asset obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getNextObjectDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + await fetchResult.getFirstObject(); + if (fetchResult.isAfterLast()) { + let fileAsset = await fetchResult.getNextObject(); + console.info('fileAsset displayName: ', fileAsset.displayName); + } +} +``` + +### getLastObject + +getLastObject(callback: AsyncCallback<T>): void + +Obtains the last file asset in the result set. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------- | ---- | --------------------------- | +| callback | AsyncCallback<T> | Yes | Callback invoked to return the last file asset obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getLastObjectDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + fetchResult.getLastObject((err, fileAsset) => { + if (fileAsset != undefined) { + console.info('fileAsset displayName: ', fileAsset.displayName); + } else { + console.info("fileAsset failed with err:" + err); + } + }); +} +``` + +### getLastObject + +getLastObject(): Promise<T> + +Obtains the last file asset in the result set. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Return value** + +| Type | Description | +| --------------------------------------- | ----------------- | +| Promise<T> | Promise used to return the last file asset obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getLastObjectDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + let fileAsset = await fetchResult.getLastObject(); + console.info('fileAsset displayName: ', fileAsset.displayName); +} +``` + +### getPositionObject + +getPositionObject(index: number, callback: AsyncCallback<T>): void + +Obtains a file asset with the specified index in the result set. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ------------------ | +| index | number | Yes | Index of the file asset to obtain. The value starts from **0**. | +| callback | AsyncCallback<T> | Yes | Callback invoked to return the file asset obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getPositionObjectDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + fetchResult.getPositionObject(0, (err, fileAsset) => { + if (fileAsset != undefined) { + console.info('fileAsset displayName: ', fileAsset.displayName); + } else { + console.info("fileAsset failed with err:" + err); + } + }); +} +``` + +### getPositionObject + +getPositionObject(index: number): Promise<T> + +Obtains a file asset with the specified index in the result set. This API uses a promise to return the result. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | -------------- | +| index | number | Yes | Index of the file asset to obtain. The value starts from **0**.| + +**Return value** + +| Type | Description | +| --------------------------------------- | ----------------- | +| Promise<T> | Promise used to return the file asset obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('getPositionObjectDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + let fetchResult = await mgr.getPhotoAssets(fetchOption); + let fileAsset = await fetchResult.getPositionObject(0); + console.info('fileAsset displayName: ', fileAsset.displayName); +} +``` + +## Album + +Provides APIs to manage albums. + +### Attributes + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Type | Readable | Writable | Description | +| ------------ | ------ | ---- | ---- | ------- | +| albumName | string | Yes | Yes | Album name. | +| albumUri | string | Yes | No | Album URI. | +| dateModified | number | Yes | No | Date when the album was last modified. | +| count | number | Yes | No | Number of files in the album.| +| coverUri | string | Yes | No | URI of the cover file of the album. + +### getPhotoAssets + +getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; + +Obtains image and video assets. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets.| +| callback | AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes | Callback invoked to return the image and video assets obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('albumGetFileAssetsDemoCallback'); + + let predicates = new dataSharePredicates.DataSharePredicates(); + let albumFetchOptions = { + predicates: predicates + }; + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + const albumList = await mgr.getPhotoAlbums(albumFetchOptions); + const album = await albumList.getFirstObject(); + album.getPhotoAssets(fetchOption, (err, albumFetchResult) => { + if (albumFetchResult != undefined) { + console.info("album getPhotoAssets successfully, getCount:" + albumFetchResult.getCount()); + } else { + console.info("album getPhotoAssets failed with error:" + err); + } + }); +} +``` +### getPhotoAssets + +getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; + +Obtains image and video assets. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets.| +| Promise | [FetchResult](#fetchresult)<[FileAsset](#fileasset)> | Yes | Promise used to return the image and video assets obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('albumGetFileAssetsDemoPromise'); + + let predicates = new dataSharePredicates.DataSharePredicates(); + let albumFetchOptions = { + predicates: predicates + }; + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + const albumList = await mgr.getPhotoAlbums(albumFetchOptions); + const album = await albumList.getFirstObject(); + album.getPhotoAssets(fetchOption).then((albumFetchResult) => { + console.info("album getFileAssets successfully, getCount:" + albumFetchResult.getCount()); + }).catch((err) => { + console.info("album getFileAssets failed with error:" + err); + }); +} +``` + +### commitModify + +commitModify(callback: AsyncCallback<void>): void; + +Commits the modification on the album attributes to the database. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| callback | AsyncCallback<void> | Yes | Callback that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('albumCommitModifyDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let albumFetchOptions = { + predicates: predicates + }; + const albumList = await mgr.getPhotoAlbums(albumFetchOptions); + const album = await albumList.getFirstObject(); + album.albumName = 'hello'; + album.commitModify((err) => { + if (err != undefined) { + console.info("commitModify failed with error:" + err); + } else { + console.info("commitModify successfully"); + } + }); +} +``` + +### commitModify + +commitModify(): Promise<void>; + +Commits the modification on the album attributes to the database. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Return value** + +| Type | Description | +| ------------------- | ------------ | +| Promise<void> | Promise that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('albumCommitModifyDemo'); + let predicates = new dataSharePredicates.DataSharePredicates(); + let albumFetchOptions = { + predicates: predicates + }; + try { + var albumList = await mgr.getPhotoAlbums(albumFetchOptions); + } catch (err) { + console.info('getPhotoAlbums failed. message = ', err); + } + const album = await albumList.getFirstObject(); + album.albumName = 'hello'; + album.commitModify().then(() => { + console.info("commitModify successfully"); + }).catch((err) => { + console.info("commitModify failed with error:" + err); + }); +} +``` + +## PrivateAlbum + +Provides APIs for managing the system albums. + +### Attributes + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Type | Readable | Writable | Description | +| ------------ | ------ | ---- | ---- | ------- | +| albumName | string | Yes | Yes | Album name. | +| albumUri | string | Yes | No | Album URI. | +| dateModified | number | Yes | No | Date when the album was last modified. | +| count | number | Yes | No | Number of files in the album.| +| coverUri | string | Yes | No | URI of the cover file of the album. + +### getPhotoAssets + +getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; + +Obtains image and video assets from a system album. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets.| +| callback | AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes | Callback invoked to return the image and video assets obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('privateAlbumGetFileAssetsDemoCallback'); + let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + const trashAlbum = await albumList.getFirstObject(); + trashAlbum.getPhotoAssets(fetchOption, (err, fetchResult) => { + if (fetchResult != undefined) { + let count = fetchResult.getCount(); + console.info('fetchResult.count = ', count); + } else { + console.info('getFileAssets failed, message = ', err); + } + }); +} + +``` +### getPhotoAssets + +getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; + +Obtains image and video assets from a system album. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets.| + +**Return value** + +| Type | Description | +| --------------------------------------- | ----------------- | +| Promise:[FetchResult](#fetchresult)<[FileAsset](#fileasset)>| Promise used to return the image and video assets obtained.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('privateAlbumGetFileAssetsDemoPromise'); + let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + const trashAlbum = await albumList.getFirstObject(); + let fetchResult = await trashAlbum.getPhotoAssets(fetchOption); + let count = fetchResult.getCount(); + console.info('fetchResult.count = ', count); +} +``` +### delete + +delete(uri: string, callback: AsyncCallback<void>): void; + +Deletes files from a system album. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| uri | string | Yes | Album URI.| +| callback | AsyncCallback<void> | Yes | Callback that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('privateAlbumDeleteCallback'); + let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + const trashAlbum = await albumList.getFirstObject(); + let fetchResult = await trashAlbum.getPhotoAssets(fetchOption); + const fileAsset = await fetchResult.getFirstObject(); + let deleteFileUri = fileAsset.uri; + trashAlbum.delete(deleteFileUri, (err) => { + if (err != undefined) { + console.info('trashAlbum.delete failed, message = ', err); + } else { + console.info('trashAlbum.delete successfully'); + } + }); +} +``` +### delete + +delete(uri: string): Promise<void>; + +Deletes files from a system album. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| uri | string | Yes | Album URI.| + +**Return value** + +| Type | Description | +| --------------------------------------- | ----------------- | +| Promise<void>| Promise that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('privateAlbumDeleteDemoPromise'); + let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + const trashAlbum = await albumList.getFirstObject(); + let fetchResult = await trashAlbum.getPhotoAssets(fetchOption); + const fileAsset = await fetchResult.getFirstObject(); + let deleteFileUri = fileAsset.uri; + trashAlbum.delete(deleteFileUri).then(() => { + console.info('trashAlbum.delete successfully'); + }).catch((err) => { + console.info('trashAlbum.delete failed, message = ', err); + }); +} +``` + +### recover + +recover(uri: string, callback: AsyncCallback<void>): void; + +Recovers files in a system album. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| uri | string | Yes | Album URI.| +| callback | AsyncCallback<void> | Yes | Callback that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('privateAlbumRecoverDemoCallback'); + let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + const trashAlbum = await albumList.getFirstObject(); + let fetchResult = await trashAlbum.getPhotoAssets(fetchOption); + const fileAsset = await fetchResult.getFirstObject(); + let recoverFileUri = fileAsset.uri; + trashAlbum.recover(recoverFileUri, (err) => { + if (err != undefined) { + console.info('trashAlbum.recover failed, message = ', err); + } else { + console.info('trashAlbum.recover successfully'); + } + }); +} +``` +### recover + +recover(uri: string): Promise<void>; + +Recovers files in a system album. + +**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| uri | string | Yes | Album URI.| + +**Return value** + +| Type | Description | +| --------------------------------------- | ----------------- | +| Promise<void>| Promise that returns no value.| + +**Example** + +```ts +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + +async function example() { + console.info('privateAlbumRecoverDemoPromise'); + let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); + let predicates = new dataSharePredicates.DataSharePredicates(); + let fetchOption = { + fetchColumns: [], + predicates: predicates + }; + const trashAlbum = await albumList.getFirstObject(); + let fetchResult = await trashAlbum.getPhotoAssets(fetchOption); + const fileAsset = await fetchResult.getFirstObject(); + let recoverFileUri = fileAsset.uri; + trashAlbum.recover(recoverFileUri).then(() => { + console.info('trashAlbum.recover successfully'); + }).catch((err) => { + console.info('trashAlbum.recover failed, message = ', err); + }); +} +``` + +## MemberType + +Enumerates the member types. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Type| Readable | Writable | Description | +| ----- | ---- | ---- | ---- | ---- | +| number | number | Yes| Yes| The member is a number.| +| string | string | Yes| Yes| The member is a string.| +| boolean | boolean | Yes| Yes| The member is a Boolean value.| + +## ChangeEvent + +Enumerates the type of changes to observe. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Type| Readable | Writable | Description| +| ----- | ---- | ---- | ---- | ---- | +| deviceChange | string | Yes| Yes| Device.| +| albumChange | string | Yes| Yes| Album.| +| imageChange | string | Yes| Yes| Image.| +| audioChange | string | Yes| Yes| Audio.| +| videoChange | string | Yes| Yes| Video.| +| remoteFileChange | string | Yes| Yes| Remote file.| + +## PeerInfo + +Defines information about a registered device. + +**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore + +| Name | Type | Readable| Writable| Description | +| ---------- | -------------------------- | ---- | ---- | ---------------- | +| deviceName | string | Yes | No | Name of the registered device. | +| networkId | string | Yes | No | Network ID of the registered device.| +| isOnline | boolean | Yes | No | Whether the registered device is online. | + + +## FileType + +Enumerates media file types. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Value| Description| +| ----- | ---- | ---- | +| IMAGE | 1 | Image.| +| VIDEO | 2 | Video.| +| AUDIO | 3 | Audio.| + +## PrivateAlbumType + +Enumerates the system album types. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Value| Description | +| ----- | ---- | ---- | +| TYPE_FAVORITE | 0 | Favorites.| +| TYPE_TRASH | 1 | Recycle bin.| + + + +## AudioKey + +Defines the key information about an audio file. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Value | Description | +| ------------- | ------------------- | ---------------------------------------------------------- | +| URI | uri | File URI. | +| DISPLAY_NAME | display_name | File name displayed. | +| DATE_ADDED | date_added | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. | +| DATE_MODIFIED | date_modified | Date when the file was last modified. The value is the number of seconds elapsed since the Epoch time. | +| TITLE | title | Title in the file. | +| ARTIST | artist | Author of the file. | +| AUDIOALBUM | audio_album | Audio album. | +| DURATION | duration | Duration, in ms. | +| FAVORITE | favorite | Whether the file is added to favorites. | + +## ImageVideoKey + +Defines the key information about an image or video file. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Value | Description | +| ------------- | ------------------- | ---------------------------------------------------------- | +| URI | uri | File URI. | +| FILE_TYPE | file_type | Type of the file. | +| DISPLAY_NAME | display_name | File name displayed. | +| DATE_ADDED | date_added | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. | +| DATE_MODIFIED | date_modified | Date when the file was last modified. The value is the number of seconds elapsed since the Epoch time. | +| TITLE | title | Title in the file. | +| DURATION | duration | Duration, in ms. | +| WIDTH | width | Image width, in pixels. | +| HEIGHT | height | Image height, in pixels. | +| DATE_TAKEN | date_taken | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time. | +| ORIENTATION | orientation | Orientation of the image file. | +| FAVORITE | favorite | Whether the file is added to favorites. | + +## AlbumKey + +Defines the key album information. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Value | Description | +| ------------- | ------------------- | ---------------------------------------------------------- | +| URI | uri | Album URI. | +| FILE_TYPE | file_type | Type of the file. | +| ALBUM_NAME | album_name | Name of the album. | +| DATE_ADDED | date_added | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. | +| DATE_MODIFIED | date_modified | Date when the file was last modified. The value is the number of seconds elapsed since the Epoch time. | + + +## FetchOptions + +Defines the options for fetching media files. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Type | Readable| Writable| Description | +| ---------------------- | ------------------- | ---- |---- | ------------------------------------------------ | +| fetchColumns | Array<string> | Yes | Yes | Columns to fetch. If this parameter is left empty, data is fetched by URI, name, and file type by default. For example,
**fetchColumns: "uri"**.| +| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md) | Yes | Yes | Predicates that specify the fetch criteria.| + +## AlbumFetchOptions + +Defines the options for fetching an album. + +**System capability**: SystemCapability.FileManagement.UserFileManager.Core + +| Name | Type | Readable| Writable| Description | +| ---------------------- | ------------------- | ---- |---- | ------------------------------------------------ | +| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md) | Yes | Yes | Predicates that specify the fetch criteria.| diff --git a/en/application-dev/reference/apis/js-apis-userfilemanager.md b/en/application-dev/reference/apis/js-apis-userfilemanager.md deleted file mode 100644 index bc02ba6fd6cde0da0b9c81932c60cfe94a3976c0..0000000000000000000000000000000000000000 --- a/en/application-dev/reference/apis/js-apis-userfilemanager.md +++ /dev/null @@ -1,2520 +0,0 @@ -# User Data Management - -> **NOTE**
-> This module is supported since API Version 9. Updates will be marked with a superscript to indicate their earliest API version. - -## Modules to Import - -```js -import userFileManager from '@ohos.filemanagement.userfile_manager'; -``` - -## userFileManager.getUserFileMgr - -getUserFileMgr(context: Context): UserFileManager - -Obtains a **UserFileManager** instance. This instance can be used to access and modify user media data (such as audio and video files, images, and documents). - -**Model restriction**: This API can be used only in the stage model. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------- | ------- | ---- | -------------------------- | -| context | [Context](../apis/js-apis-inner-app-context.md) | Yes | Context of the ability instance.| - -**Return value** - -| Type | Description | -| ----------------------------- | :---- | -| [UserFileManager](#userfilemanager) | **UserFileManager** instance obtained.| - -**Example** - -```ts -const context = getContext(this); -let userFileMgr = userfilemanager.getUserFileMgr(context); -``` - -## userFileManager.getUserFileMgr - -getUserFileMgr(): UserFileManager - -Obtains a **UserFileManager** instance.This instance can be used to access and modify user media data (such as audio and video clips, images, and documents). - -**Model restriction**: This API can be used only in the FA model. - -> **NOTE**
You are advised to use [UserFileManager.getUserFileMgr](#userfilemanagergetuserfilemgr), the API used in the stage model. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| ----------------------------- | :--------- | -| [UserFileManager](#userfilemanager) | **UserFileManager** instance obtained.| - -**Example** - -```js -let userFileMgr = userfilemanager.getUserFileMgr(); -``` - -## UserFileManager - -### getPublicDirectory - -getPublicDirectory(type: DirectoryType, callback: AsyncCallback<string>): void; - -Obtains the preset public directory. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------ | ---- | ------------------------- | -| type | [DirectoryType](#directorytype) | Yes | Type of the public directory. | -| callback | AsyncCallback<string> | Yes | Callback invoked to return the public directory.| - -**Example** - -```ts -async function getPublicDirectoryDemoCallback() { - console.info('getPublicDirectoryDemo'); - let DIR_CAMERA = directoryType.DIR_CAMERA; - console.info('DIR_CAMERA', DIR_CAMERA); - userFileMgr.getPublicDirectory(DIR_CAMERA, (err, dicResult) => { - if (dicResult == 'Camera/') { - console.info('mediaLibraryTest : getPublicDirectory passed'); - } else { - console.info('mediaLibraryTest : getPublicDirectory failed'); - } - }); -} -``` - -### getPublicDirectory - -getPublicDirectory(type: DirectoryType): Promise<string>; - -Obtains the preset public directory. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------------- | ---- | ------------ | -| type | [DirectoryType](#directorytype) | Yes | Type of the public directory.| - -**Return value** - -| Type | Description | -| ---------------- | ---------------- | -| Promise\ | Promise used to return the public directory.| - -**Example** - -```ts -async function getPublicDirectoryDemoPromise() { - console.info('getPublicDirectoryDemo'); - let DIR_CAMERA = directoryType.DIR_CAMERA; - try { - let dicResult = await userFileMgr.getPublicDirectory(DIR_CAMERA); - console.info('mediaLibraryTest : getPublicDirectory passed, result = ', dicResult); - } catch (err) { - console.info('mediaLibraryTest : getPublicDirectory failed, message = ', err); - } -} -``` - -### getFileAssets - -getFileAssets(type: Array<MediaType>, options: MediaFetchOptions, callback: AsyncCallback<FetchFileResult>): void; - -Obtains file assets. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------ | ---- | ------------------------- | -| type | Array<[MediaType](#mediatype)> | Yes | Type of the media data to obtain. | -| options | [MediaFetchOptions](#mediafetchoptions) | Yes | Options for fetching the files. | -| callback | AsyncCallback<string> | Yes | Callback invoked to return the file assets obtained.| - -**Example** - -```ts -async function getFileAssetsDemoCallback() { - console.info('getFileAssets'); - let fileKeyObj = userfile_manager.FileKey - let imageType = userfile_manager.MediaType.IMAGE - let fetchOp = { - selections: '', - selectionArgs: [], - }; - - userFileMgr.getFileAssets([imageType, ], fetchOp, async (err, fetchFileResult) => { - if (fetchFileResult != undefined) { - console.info('fetchFileResult success'); - let fileAsset = await fetchFileResult.getFirstObject(); - if (fileAsset != undefined) { - console.info("fileAsset.displayName :" + fileAsset.displayName); - }; - } - }) -} -``` - -### getFileAssets - -getFileAssets(type: Array<MediaType>, options: MediaFetchOptions): Promise<FetchFileResult>; - -Obtains file assets. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------- | ------------------- | ---- | ---------------- | -| type | Array<[MediaType](#mediatype)> | Yes | Type of the media type to obtain.| -| options | [MediaFetchOptions](#mediafetchoptions) | Yes | Options for fetching the files. | - -**Return value** - -| Type | Description | -| --------------------------- | -------------- | -| Promise<[FetchFileResult](#fetchfileresult)> | Promise used to return the file assets obtained.| - -**Example** - -```ts -async function getFileAssetsDemoPromise() { - console.info('getFileAssets'); - let fileKeyObj = userfile_manager.FileKey - let imageType = userfile_manager.MediaType.IMAGE - let fetchOp = { - selections: '', - selectionArgs: [], - }; - try { - var fetchFileResult = await userFileMgr.getFileAssets([imageType, ], fetchOp) - } catch (err) { - console.info('getFileAssets failed, message = ', err); - } - - if (fetchFileResult != undefined) { - console.info('fetchFileResult success'); - let fileAsset = await fetchFileResult.getFirstObject(); - if (fileAsset != undefined) { - console.info("fileAsset.displayName :" + fileAsset.displayName); - }; - } -} -``` - -### on - -on(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback: Callback<void>): void - -Subscribes to changes of the file management library. This API uses a callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Media type to subscribe to.
**deviceChange** indicates the device change.
**albumChange** indicates the album change.
**imageChange** indicates the image change.
**audioChange** indicates the audio file change.
**videoChange** indicates the video file change.
**fileChange** indicates the file change.
**remoteFileChange** indicates the file change on the registered device.| -| callback | Callback<void> | Yes | Callback that returns no value. | - -**Example** - -```ts -async function onDemo() { - console.info('onDemo') - userFileMgr.on('imageChange', () => { - // Image file changes. Do something. - }); -} -``` - -### off - -off(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback?: Callback<void>): void - -Unsubscribes from changes of the file management library. This API uses a callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Media type to unsubscribe from.
**deviceChange** indicates the device change.
**albumChange** indicates the album change.
**imageChange** indicates the image change.
**audioChange** indicates the audio file change.
**videoChange** indicates the video file change.
**fileChange** indicates the file change.
**remoteFileChange** indicates the file change on the registered device.| -| callback | Callback<void> | No | Callback that returns no value. | - -**Example** - -```ts -async function offDemo() { - console.info('offDemo') - userFileMgr.off('imageChange', () => { - // stop listening success - }); -} -``` - -### createAsset - -createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback<FileAsset>): void - -Creates a file asset. This API uses an asynchronous callback to return the result. - -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------------ | --------------------------- | ---- | ------------------------------------------------------------ | -| mediaType | [MediaType](#mediatype) | Yes | Media type. | -| displayName | string | Yes | File name to display. | -| relativePath | string | Yes | File path. You can use **getPublicDirectory()** to obtain the paths for different types of files.| -| callback | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the file asset created. | - -**Example** - -```ts -async function createAssetDemoCallback() { - console.info('createAssetDemo') - let mediaType = userfile_manager.MediaType.FILE; - let DIR_DOC = directoryType.DIR_DOCUMENTS; - const path = await userFileMgr.getPublicDirectory(DIR_DOC); - userFileMgr.createAsset(mediaType, 'tesfFile.txt', path + 'myDirectory/', (err, fileAsset) => { - if (err == undefined) { - console.info('createAsset successfully'); - } else { - console.info('createAsset failed, message = ', err); - } - }) -} -``` - -### createAsset - -createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise<FileAsset>; - -Creates a file asset. This API uses a promise to return the result. - -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------------ | --------- | ---- | ------------------------------------------------------------ | -| mediaType | [MediaType](#mediatype) | Yes | Media type. | -| displayName | string | Yes | File name to display. | -| relativePath | string | Yes | File path. You can use **getPublicDirectory()** to obtain the paths for different types of files.| - -**Return value** - -| Type | Description | -| --------------------- | ----------------- | -| Promise<[FileAsset](#fileasset)> | Promise used to return the file asset created.| - -**Example** - -```ts -async function createAssetDemoPromise() { - console.info('createAssetDemo') - let mediaType = userfile_manager.MediaType.FILE; - let DIR_DOC = directoryType.DIR_DOCUMENTS; - const path = await userFileMgr.getPublicDirectory(DIR_DOC); - try { - let fileAsset = await userFileMgr.createAsset(mediaType, 'tesfFile.txt', path + 'myDirectory/') - console.info('createAsset successfully'); - } catch (err) { - console.info('createAsset failed, message = ', err); - } -} -``` - -### deleteAsset - -deleteAsset(uri: string, callback: AsyncCallback<void>): void; - -Deletes a file asset. This API uses an asynchronous callback to return the result. - -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | --------------------------- | ---- | ---------------------- | -| uri | string | Yes | URI of the file to delete. | -| callback | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the result.| - -**Example** - -```ts -async function deleteAssetDemoCallback() { - console.info('deleteAssetDemo') - let fileKeyObj = userfile_manager.FileKey - let fileType = userfile_manager.MediaType.FILE - let option = { - selections: '', - selectionArgs: [], - }; - try { - const fetchFileResult = await userFileMgr.getFileAssets([fileType, ], option); - var asset = await fetchFileResult.getFirstObject(); - } catch(err) { - console.info('fetch failed, message =', err) - } - - if (asset == undefined) { - console.error('asset not exist') - return - } - userFileMgr.deleteAsset(asset.uri, (err) => { - if (err == undefined) { - console.info("deleteAsset successfully"); - } else { - console.info("deleteAsset failed with error:"+ err); - } - }); -} -``` - -### deleteAsset - -deleteAsset(uri: string): Promise<void>; - -Deletes a file asset. This API uses a promise to return the result. - -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | ------- | -| uri | string | Yes | URI of the file to delete.| - -**Return value** - -| Type | Description | -| ---------------- | --------------------------------- | -| Promise<void> | Promise used to return the result.| - -**Example** - -```ts -async function deleteAssetDemoPromise() { - console.info('deleteAssetDemo') - let fileKeyObj = userfile_manager.FileKey - let fileType = userfile_manager.MediaType.FILE - let option = { - selections: '', - selectionArgs: [], - }; - try { - const fetchFileResult = await userFileMgr.getFileAssets([fileType, ], option); - var asset = await fetchFileResult.getFirstObject(); - } catch(err) { - console.info('fetch failed, message =', err) - } - if (asset == undefined) { - console.error('asset not exist') - return - } - try { - await userFileMgr.deleteAsset(asset.uri); - console.info("deleteAsset successfully"); - } catch (err) { - console.info("deleteAsset failed with error:"+ err); - } -} -``` - -### getAlbums - -getAlbums(type: Array<MediaType>, options: MediaFetchOptions, callback: AsyncCallback | Yes | Type of the media data to obtain. | -| options | [MediaFetchOptions](#mediafetchoptions) | Yes | Options for fetching the albums. | -| callback | AsyncCallback<Array<[Album](#album)>> | Yes | Callback invoked to return the album list.| - -**Example** - -```ts -async function getAlbumsDemoCallback() { - console.info('getAlbumsDemo') - let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - userFileMgr.getAlbums([userfile_manager.MediaType.IMAGE], AlbumNoArgsfetchOp, (err, albumList) => { - if (albumList != undefined) { - const album = albumList[0]; - console.info('first album.albumName = ' + album.albumName); - console.info('album.count = ' + albumList.length); - } else { - console.info('getAlbum fail, message = ' + err); - } - }) -} -``` - -### getAlbums - -getAlbums(type: Array<MediaType>, options: MediaFetchOptions): Promise>; - -Obtains albums. This API uses a promise to return the result. - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------- | ------------------- | ---- | -------------------- | -| type | Array<[MediaType](#mediatype)> | Yes | Type of the media data to obtain.| -| options | [MediaFetchOptions](#mediafetchoptions) | Yes | Options for fetching the albums. | - -**Return value** - -| Type | Description | -| ------------------------ | -------------------------- | -| Promise> | Promise used to return the album list.| - -**Example** - -```ts -async function getAlbumsDemoPromise() { - console.info('getAlbumsDemo') - let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - try { - let albumList = await userFileMgr.getAlbums([userfile_manager.MediaType.IMAGE], AlbumNoArgsfetchOp); - const album = albumList[0]; - console.info('first album.albumName = ' + album.albumName); - console.info('album.count = ' + albumList.length); - } catch (err) { - console.info('getAlbum fail, message = ' + err); - } -} -``` - -### getPrivateAlbum - -getPrivateAlbum(type: VirtualAlbumType, callback: AsyncCallback): void - -Obtains the system album. This API uses an asynchronous callback to return the result. - -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------- | ---- | ---------------------------------- | -| type | [VirtualAlbumType](#virtualalbumtype) | Yes | Type of the album to obtain. | -| callback | AsyncCallback> | Yes | Callback invoked to return the system album obtained.| - -**Example** - -```ts -async function getPrivateAlbumDemoCallback() { - console.info('getPrivateAlbumDemo') - userFileMgr.getPrivateAlbum(userfile_manager.VirtualAlbumType.TYPE_TRASH, async (err, albumArray) => { - if (err == undefined) { - console.info('getPrivateAlbum ok'); - try { - let fetchOpt = { - selections: '', - selectionArgs: [], - }; - let trashAlbum = albumArray[0]; - var fetchResult = await trashAlbum.getFileAssets([userfile_manager.MediaType.IMAGE], fetchOpt); - } catch (err) { - console.info('getFileAssets failed. message = ', err); - } - // Get file count in trash album - let count = fetchResult.getCount(); - console.info('fetchResult count = ', count) - // Get fileAssets in trash album - let trashAsset = await fetchResult.getFirstObject(); - // Get file trashed date - let isTrash = trashAsset.isTrash(); - console.info('is trashed', isTrash) - } else { - console.info('getPrivateAlbum failed. message = ', err); - } - }); -} -``` - -### getPrivateAlbum - -getPrivateAlbum(type: VirtualAlbumType): Promise - -Obtains the system album. This API uses a promise to return the result. - -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ---------------- | ---- | ------------ | -| type | [VirtualAlbumType](#virtualalbumtype) | Yes | Type of the album to obtain.| - -**Return value** - -| Type | Description | -| ------------------------------- | --------------------------------- | -| Promise> | Promise used to return the system album obtained.| - -**Example** - -```ts -async function getPrivateAlbumDemoPromise() { - console.info('getPrivateAlbumDemo'); - try { - var albumArray = await userFileMgr.getPrivateAlbum(userfile_manager.VirtualAlbumType.TYPE_TRASH); - } catch(err) { - console.info('getPrivateAlbum failed. message = ', err); - } - try { - let fetchOpt = { - selections: '', - selectionArgs: [], - }; - let trashAlbum = albumArray[0]; - var fetchResult = await trashAlbum.getFileAssets([userfile_manager.MediaType.IMAGE], fetchOpt); - } catch (err) { - console.info('getFileAssets failed. message = ', err); - } - // Get file count in trash album - let count = fetchResult.getCount(); - console.info('fetchResult count = ', count) - // Get fileAssets in trash album - let trashAsset = await fetchResult.getFirstObject(); - - // Get file trashed date - let isTrash = trashAsset.isTrash(); - console.info('is trashed', isTrash) -} -``` - -### getActivePeers - -getActivePeers(callback: AsyncCallback>): void; - -Obtains information about online peer devices. This API uses an asynchronous callback to return the result. - -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | --------------------------------- | ---- | ------------ | -| callback | AsyncCallback> | Yes | Callback invoked to return the online device list.| - -**Example** - -```ts -async function getActivePeersDemoCallback() { - console.info('getActivePeersDemo') - var devicesInfo = userFileMgr.getActivePeers((err, devicesInfo) => { - if (err == undefined) { - console.log('getActivePeers succeed.') - for (let i = 0; i < devicesInfo.length; i++) { - console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); - } - } else { - console.info('getActivePeers failed. message = ', err) - } - }); -} -``` - -### getActivePeers - -getActivePeers(): Promise>; - -Obtains information about online peer devices. This API uses a promise to return the result. - -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore - -**Return value** - -| Type | Description | -| --------------------------- | ----------------------------- | -| Promise> | Promise used to return the online device list.| - -**Example** - -```ts -async function getActivePeersDemoPromise() { - console.info('getActivePeersDemo') - try { - var devicesInfo = await userFileMgr.getActivePeers(); - } catch (err) { - console.info('getActivePeers failed. message = ', err) - } - if (devicesInfo != undefined) { - console.log('getActivePeers succeed.') - for (let i = 0; i < devicesInfo.length; i++) { - console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); - } - } else { - console.info('get distributed fail') - } -} -``` - -### getAllPeers - -getAllPeers(callback: AsyncCallback>): void; - -Obtains information about all peer devices. This API uses an asynchronous callback to return the result. - -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | --------------------------------- | ---- | ------------ | -| callback | AsyncCallback> | Yes | Callback invoked to return the peer device list.| - -**Example** - -```ts -async function getAllPeersDemoCallback() { - console.info('getAllPeersDemo') - var devicesInfo = await userFileMgr.getAllPeers((err, devicesInfo) => { - if (err == undefined) { - console.log('getAllPeers succeed.') - for (let i = 0; i < devicesInfo.length; i++) { - console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); - } - } else { - console.info('getAllPeers failed. message = ', err) - } - }); -} -``` - -### getAllPeers - -getAllPeers(): Promise>; - -Obtains information about all peer devices. This API uses a promise to return the result. - -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore - -**Return value** - -| Type | Description | -| --------------------------- | ----------------------------- | -| Promise> | Promise used to return the peer device list.| - -**Example** - -```ts -async function getAllPeersDemoPromise() { - console.info('getAllPeersDemo') - try { - var devicesInfo = await userFileMgr.getAllPeers(); - } catch (err) { - console.info('getAllPeers failed. message = ', err) - } - if (devicesInfo != undefined) { - console.log('getAllPeers succeed.') - for (let i = 0; i < devicesInfo.length; i++) { - console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); - } - } else { - console.info('get distributed fail') - } -} -``` - -### release - -release(callback: AsyncCallback<void>): void - -Releases this **UserFileManager** instance. This API uses an asynchronous callback to return the result. -Call this API when the APIs in the **UserFileManager** instance are no longer used. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------- | ---- | -------------------- | -| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| - -**Example** - -```ts -async function releaseDemoCallback() { - console.info('releaseDemo'); - userFileMgr.release((err) => { - if (err != undefined) { - console.info('release failed. message = ', err); - } else { - console.info('release ok.'); - } - }) -} -``` - -### release - -release(): Promise<void> - -Releases this **UserFileManager** instance. This API uses a promise to return the result. -Call this API when the APIs in the **UserFileManager** instance are no longer used. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| ------------------- | --------------------------------- | -| Promise<void> | Promise used to return the result.| - -**Example** - -```ts -async function releaseDemoPromise() { - console.info('releaseDemo'); - try { - await userFileMgr.release(); - console.info('release ok.'); - } catch (err) { - console.info('release failed. message = ', err); - } -} -``` - -## FileAsset - -Provides APIs for encapsulating file asset attributes. - -### Attributes - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -| Name | Type | Readable| Writable| Description | -| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ | -| uri | string | Yes | No | File asset URI, for example, **dataability:///media/image/2**. | -| mediaType | [MediaType](#mediatype) | Yes | No | Media type. | -| displayName | string | Yes | Yes | File name, including the file name extension, to display. | - - -### isDirectory - -isDirectory(callback: AsyncCallback<boolean>): void - -Checks whether this file asset is a directory. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ---------------------------- | ---- | ------------------- | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If the file asset is a directory, **true** will be returned; otherwise, **false** will be returned.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.isDirectory((err, isDirectory) => { - // do something - }); -} -``` - -### isDirectory - -isDirectory():Promise<boolean> - -Checks whether this file asset is a directory. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| ---------------------- | ---------------------------- | -| Promise<boolean> | Promise used to return the result. If the file asset is a directory, **true** will be returned; otherwise, **false** will be returned.| - -**Example** - -```js -async function example() { - let fileKeyObj = userfile_manager.FileKey - let imageType = userfile_manager.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.isDirectory().then(function(isDirectory){ - console.info("isDirectory result:"+ isDirectory); - }).catch(function(err){ - console.info("isDirectory failed with error:"+ err); - }); -} -``` - -### commitModify - -commitModify(callback: AsyncCallback<void>): void - -Commits the modification on the file metadata to the database. This API uses an asynchronous callback to return the result. - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | ----- | -| callback | AsyncCallback<void> | Yes | Callback that returns no value.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = 'newtitle'; - asset.commitModify(() => { - console.info('commitModify success'); - }); -} -``` - -### commitModify - -commitModify(): Promise<void> - -Commits the modification on the file metadata to the database. This API uses a promise to return the result. - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| ------------------- | ---------- | -| Promise<void> | Promise that returns no value.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = 'newtitle'; - asset.commitModify(); -} -``` - -### open - -open(mode: string, callback: AsyncCallback<number>): void - -Opens this file asset. This API uses an asynchronous callback to return the result. - -**NOTE**
Currently, the write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource. - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, ohos.permission.READ_DOCUMENT, ohos.permission.WRITE_MEDIA, ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | ----------------------------------- | -| mode | string | Yes | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).| -| callback | AsyncCallback<number> | Yes | Callback used to return the file handle. | - -**Example** - -```js -async function example() { - let mediaType = mediaLibrary.MediaType.IMAGE; - let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const path = await userFileMgr.getPublicDirectory(DIR_IMAGE); - const asset = await userFileMgr.createAsset(mediaType, "image00003.jpg", path); - asset.open('rw', (openError, fd) => { - if(fd > 0){ - asset.close(fd); - }else{ - console.info('File Open Failed!' + openError); - } - }); -} -``` - -### open - -open(mode: string): Promise<number> - -Opens this file asset. This API uses a promise to return the result. - -**NOTE**
Currently, the write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource. - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, ohos.permission.READ_DOCUMENT, ohos.permission.WRITE_MEDIA, ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ----------------------------------- | -| mode | string | Yes | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).| - -**Return value** - -| Type | Description | -| --------------------- | ------------- | -| Promise<number> | Promise used to return the file handle.| - -**Example** - -```js -async function example() { - let mediaType = mediaLibrary.MediaType.IMAGE; - let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const path = await userFileMgr.getPublicDirectory(DIR_IMAGE); - const asset = await userFileMgr.createAsset(mediaType, "image00003.jpg", path); - asset.open('rw') - .then((fd) => { - console.info('File fd!' + fd); - }) - .catch((err) => { - console.info('File err!' + err); - }); -} -``` - -### close - -close(fd: number, callback: AsyncCallback<void>): void - -Closes this file asset. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | ----- | -| fd | number | Yes | File descriptor.| -| callback | AsyncCallback<void> | Yes | Callback that returns no value.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.open('rw').then((fd) => { - console.info('File fd!' + fd); - asset.close(fd, (closeErr) => { - if (closeErr != undefined) { - console.info('mediaLibraryTest : close : FAIL ' + closeErr); - console.info('mediaLibraryTest : ASSET_CALLBACK : FAIL'); - } else { - console.info("=======asset.close success====>"); - } - }); - }) - .catch((err) => { - console.info('File err!' + err); - }); -} -``` - -### close - -close(fd: number): Promise<void> - -Closes this file asset. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ----- | -| fd | number | Yes | File descriptor.| - -**Return value** - -| Type | Description | -| ------------------- | ---------- | -| Promise<void> | Promise that returns no value.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.open('rw').then((fd) => { - console.info('File fd!' + fd); - asset.close(fd).then((closeErr) => { - if (closeErr != undefined) { - console.info('mediaLibraryTest : close : FAIL ' + closeErr); - console.info('mediaLibraryTest : ASSET_CALLBACK : FAIL'); - - } else { - console.info("=======asset.close success====>"); - } - }); - }) - .catch((err) => { - console.info('File err!' + err); - }); -} -``` - -### getThumbnail - -getThumbnail(callback: AsyncCallback<image.PixelMap>): void - -Obtains the thumbnail of this file asset. This API uses an asynchronous callback to return the result. - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ----------------------------------- | ---- | ---------------- | -| callback | AsyncCallback<[image.PixelMap](../apis/js-apis-image.md#pixelmap7)> | Yes | Callback invoked to return the pixel map of the thumbnail.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.getThumbnail((err, pixelmap) => { - console.info('mediaLibraryTest : getThumbnail Successfull '+ pixelmap); - }); -} -``` - -### getThumbnail - -getThumbnail(size: Size, callback: AsyncCallback<image.PixelMap>): void - -Obtains the file thumbnail of the given size. This API uses an asynchronous callback to return the result. - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ----------------------------------- | ---- | ---------------- | -| size | [Size](#size) | Yes | Size of the thumbnail to obtain. | -| callback | AsyncCallback<[image.PixelMap](../apis/js-apis-image.md#pixelmap7)> | Yes | Callback invoked to return the pixel map of the thumbnail.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let size = { width: 720, height: 720 }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.getThumbnail(size, (err, pixelmap) => { - console.info('mediaLibraryTest : getThumbnail Successfull '+ pixelmap); - }); -} -``` - -### getThumbnail - -getThumbnail(size?: Size): Promise<image.PixelMap> - -Obtains the file thumbnail of the given size. This API uses a promise to return the result. - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| ---- | -------------- | ---- | ----- | -| size | [Size](#size) | No | Size of the thumbnail to obtain.| - -**Return value** - -| Type | Description | -| ----------------------------- | --------------------- | -| Promise<[image.PixelMap](../apis/js-apis-image.md#pixelmap7)> | Promise used to return the pixel map of the thumbnail.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let size = { width: 720, height: 720 }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.getThumbnail(size) - .then((pixelmap) => { - console.info('mediaLibraryTest : getThumbnail Successfull '+ pixelmap); - }) - .catch((err) => { - console.info('mediaLibraryTest : getThumbnail fail'+ err); - }); -} -``` - -### favorite - -favorite(isFavorite: boolean, callback: AsyncCallback<void>): void - -Favorites or unfavorites this file asset. This API uses an asynchronous callback to return the result. - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| ---------- | ------------------------- | ---- | ---------------------------------- | -| isFavorite | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| -| callback | AsyncCallback<void> | Yes | Callback that returns no value. | - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.favorite(true,function(err){ - // Do something. - }); -} -``` - -### favorite - -favorite(isFavorite: boolean): Promise<void> - -Favorites or unfavorites this file asset. This API uses a promise to return the result. - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| ---------- | ------- | ---- | ---------------------------------- | -| isFavorite | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| - -**Return value** - -| Type | Description | -| ------------------- | ---------- | -| Promise<void> | Promise that returns no value.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.favorite(true).then(function() { - console.info("favorite successfully"); - }).catch(function(err){ - console.info("favorite failed with error:"+ err); - }); -} -``` - -### isFavorite - -isFavorite(callback: AsyncCallback<boolean>): void - -Checks whether this file asset is favorited. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ---------------------------- | ---- | ----------- | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If the file asset is favorited, **true** will be returned; otherwise, **false** will be returned.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.isFavorite((err, isFavorite) => { - if (isFavorite) { - console.info('FileAsset is favorite'); - }else{ - console.info('FileAsset is not favorite'); - } - }); -} -``` - -### isFavorite - -isFavorite():Promise<boolean> - -Checks whether this file asset is favorited. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| ---------------------- | ------------------ | -| Promise<boolean> | Promise used to return the result. If the file asset is favorited, **true** will be returned; otherwise, **false** will be returned.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.isFavorite().then(function(isFavorite){ - console.info("isFavorite result:"+ isFavorite); - }).catch(function(err){ - console.info("isFavorite failed with error:"+ err); - }); -} -``` - -### trash - -trash(isTrash: boolean, callback: AsyncCallback<void>): void - -Moves this file asset to the trash. This API uses an asynchronous callback to return the result. - -Files in the trash are not actually deleted. You can set **isTrash** to **false** to restore the files from the trash. - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | --------- | -| isTrash | boolean | Yes | Whether to move the file asset to the trash. The value **true** means to move the file asset to the trash, and **false** means the opposite.| -| callback | AsyncCallback<void> | Yes | Callback that returns no value. | - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.trash(true, trashCallBack); - function trashCallBack(err, trash) { - console.info('mediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK trash'); - } -} -``` - -### trash - -trash(isTrash: boolean): Promise<void> - -Moves this file asset to the trash. This API uses a promise to return the result. - -Files in the trash are not actually deleted. You can set **isTrash** to **false** to restore the files from the trash. - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| ------- | ------- | ---- | --------- | -| isTrash | boolean | Yes | Whether to move the file asset to the trash. The value **true** means to move the file asset to the trash, and **false** means the opposite.| - -**Return value** - -| Type | Description | -| ------------------- | ---------- | -| Promise<void> | Promise that returns no value.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.trash(true).then(function() { - console.info("trash successfully"); - }).catch(function(err){ - console.info("trash failed with error:"+ err); - }); -} -``` - -### isTrash - -isTrash(callback: AsyncCallback<boolean>): void - -Checks whether this file asset is in the trash. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ---------------------------- | ---- | --------------- | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If the file asset is in the trash, **true** will be returned; otherwise, **false** will be returned.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.isTrash((err, isTrash) => { - if (isTrash == undefined) { - console.error('Failed to get trash state: ' + err); - return; - } - console.info('Get trash state success: ' + isTrash); - }); -} -``` - -### isTrash - -isTrash():Promise<boolean> - -Checks whether this file asset is in the trash. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| ------------------- | -------------------- | -| Promise<void> | Promise used to return the result. If the file asset is in the trash, **true** will be returned; otherwise, **false** will be returned.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - const fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const asset = await fetchFileResult.getFirstObject(); - asset.isTrash().then(function(isTrash){ - console.info("isTrash result: " + isTrash); - }).catch(function(err){ - console.error("isTrash failed with error: " + err); - }); -} -``` - -## FetchFileResult - -Provides APIs to manage the file retrieval result. - -### getCount - -getCount(): number - -Obtains the total number of files in the result set. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| ------ | -------- | -| number | Total number of files.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let fileType = mediaLibrary.MediaType.FILE; - let getFileCountOneOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [fileType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - let fetchFileResult = await userFileMgr.getFileAssets(getFileCountOneOp); - const fetchCount = fetchFileResult.getCount(); -} -``` - -### isAfterLast - -isAfterLast(): boolean - -Checks whether the cursor is in the last row of the result set. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| ------- | ---------------------------------- | -| boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - let fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const fetchCount = fetchFileResult.getCount(); - console.info('mediaLibraryTest : count:' + fetchCount); - let fileAsset = await fetchFileResult.getFirstObject(); - for (var i = 1; i < fetchCount; i++) { - fileAsset = await fetchFileResult.getNextObject(); - if(i == fetchCount - 1) { - console.info('mediaLibraryTest : isLast'); - var result = fetchFileResult.isAfterLast(); - console.info('mediaLibraryTest : isAfterLast:' + result); - console.info('mediaLibraryTest : isAfterLast end'); - fetchFileResult.close(); - } - } -} -``` - -### close - -close(): void - -Releases and invalidates this **FetchFileResult** instance. After this instance is released, the APIs in this instance cannot be invoked. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - let fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - fetchFileResult.close(); -} -``` - -### getFirstObject - -getFirstObject(callback: AsyncCallback<FileAsset>): void - -Obtains the first file asset in the result set. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------- | ---- | ------------------------------------------- | -| callback | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the first file asset.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - let fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - fetchFileResult.getFirstObject((err, fileAsset) => { - if (err) { - console.error('Failed '); - return; - } - console.log('fileAsset.displayName : ' + fileAsset.displayName); - }) -} -``` - -### getFirstObject - -getFirstObject(): Promise<FileAsset> - -Obtains the first file asset in the result set. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| --------------------------------------- | -------------------------- | -| Promise<[FileAsset](#fileasset)> | Promise used to return the first file asset.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - let fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - fetchFileResult.getFirstObject().then(function(fileAsset){ - console.info("getFirstObject successfully:"+ JSON.stringify(fileAsset)); - }).catch(function(err){ - console.info("getFirstObject failed with error:"+ err); - }); -} -``` - -### getNextObject - - getNextObject(callback: AsyncCallback<FileAsset>): void - -Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| --------- | --------------------------------------------- | ---- | ----------------------------------------- | -| callbacke | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the next file asset.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - let fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - fetchFileResult.getNextObject((err, fileAsset) => { - if (err) { - console.error('Failed '); - return; - } - console.log('fileAsset.displayName : ' + fileAsset.displayName); - }) -} -``` - -### getNextObject - - getNextObject(): Promise<FileAsset> - -Obtains the next file asset in the result set. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| --------------------------------------- | ----------------- | -| Promise<[FileAsset](#fileasset)> | Promise used to return the next file asset.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - let fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - const fetchCount = fetchFileResult.getCount(); - console.info('mediaLibraryTest : count:' + fetchCount); - let fileAsset = await fetchFileResult.getNextObject(); -} -``` - -### getLastObject - -getLastObject(callback: AsyncCallback<FileAsset>): void - -Obtains the last file asset in the result set. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------- | ---- | --------------------------- | -| callback | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the last file asset.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - let fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - fetchFileResult.getLastObject((err, fileAsset) => { - if (err) { - console.error('Failed '); - return; - } - console.log('fileAsset.displayName : ' + fileAsset.displayName); - }) -} -``` - -### getLastObject - -getLastObject(): Promise<FileAsset> - -Obtains the last file asset in the result set. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| --------------------------------------- | ----------------- | -| Promise<[FileAsset](#fileasset)> | Promise used to return the last file asset.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - let fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - let lastObject = await fetchFileResult.getLastObject(); -} -``` - -### getPositionObject - -getPositionObject(index: number, callback: AsyncCallback<FileAsset>): void - -Obtains a file asset with the specified index in the result set. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ------------------ | -| index | number | Yes | Index of the file asset to obtain. The value starts from **0**. | -| callback | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the file asset obtained.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - let fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - fetchFileResult.getPositionObject(0, (err, fileAsset) => { - if (err) { - console.error('Failed '); - return; - } - console.log('fileAsset.displayName : ' + fileAsset.displayName); - }) -} -``` - -### getPositionObject - -getPositionObject(index: number): Promise<FileAsset> - -Obtains a file asset with the specified index in the result set. This API uses a promise to return the result. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory | Description | -| ----- | ------ | ---- | -------------- | -| index | number | Yes | Index of the file asset to obtain. The value starts from **0**.| - -**Return value** - -| Type | Description | -| --------------------------------------- | ----------------- | -| Promise<[FileAsset](#fileasset)> | Promise used to return the file asset obtained.| - -**Example** - -```js -async function example() { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let getImageOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let userFileMgr = userfile_manager.getUserFileMgr(context); - let fetchFileResult = await userFileMgr.getFileAssets(getImageOp); - fetchFileResult.getPositionObject(1) .then(function (fileAsset){ - console.log('fileAsset.displayName : ' + fileAsset.displayName); - }).catch(function (err) { - console.info("getFileAssets failed with error:" + err); - }); -} -``` - -## Album - -Provides APIs to manage albums. - -### Attributes - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -| Name | Type | Readable | Writable | Description | -| ------------ | ------ | ---- | ---- | ------- | -| albumName | string | Yes | Yes | Album name. | -| albumUri | string | Yes | No | Album URI. | -| dateModified | number | Yes | No | Date when the album was last modified. | -| count | number | Yes | No | Number of files in the album.| -| relativePath | string | Yes | No | Relative path of the album. | -| coverUri | string | Yes | No | URI of the cover file of the album. - -### commitModify - -commitModify(callback: AsyncCallback<void>): void; - -Commits the modification on the album attributes to the database. This API uses an asynchronous callback to return the result. - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------- | ---- | ---------- | -| callback | AsyncCallback<void> | Yes | Callback that returns no value.| - -**Example** - -```ts -async function commitModifyDemoCallback() { - console.info('commitModifyDemo') - let fileKeyObj = userfile_manager.FileKey - let imageType = userfile_manager.MediaType.IMAGE; - let getImageOp = { - selections: '', - selectionArgs: [], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let fetchFileResult = await userFileMgr.getFileAssets([imageType], getImageOp); - let asset = await fetchFileResult.getFirstObject(); - console.info('old displayName:', asset.displayName) - asset.displayName = 'newDisplayName'; - console.info('new displayName:', asset.displayName) - asset.commitModify((err) => { - if (err == undefined) { - console.info('commitModify succeed.') - } else { - console.info('commitModify failed, message =', err); - } - }); -} -``` - -### commitModify - -commitModify(): Promise<void>; - -Commits the modification on the album attributes to the database. This API uses a promise to return the result. - -**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO, ohos.permission.WRITE_AUDIO, or ohos.permission.WRITE_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Return value** - -| Type | Description | -| ------------------- | ------------ | -| Promise<void> | Promise that returns no value.| - -**Example** - -```ts -async function commitModifyDemoPromise() { - console.info('commitModifyDemo') - let fileKeyObj = userfile_manager.FileKey - let imageType = userfile_manager.MediaType.IMAGE; - let getImageOp = { - selections: '', - selectionArgs: [], - order: fileKeyObj.DATE_ADDED + " DESC", - extendArgs: "", - }; - let fetchFileResult = await userFileMgr.getFileAssets([imageType], getImageOp); - let asset = await fetchFileResult.getFirstObject(); - console.info('old displayName:', asset.displayName) - asset.displayName = 'newDisplayName'; - console.info('new displayName:', asset.displayName) - try { - await asset.commitModify(); - console.info('commitModify succeed.') - } catch (err) { - console.info('commitModify failed, message =', err); - } -} -``` - -### getFileAssets - -getFileAssets(type: Array<MediaType>, callback: AsyncCallback<FetchFileResult>): void; - -Obtains the file assets in this album. This API uses an asynchronous callback to return the result. - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------------- | ---- | ----------------------------------- | -| type | Array<[MediaType](#mediatype)> | Yes | Type of the media data to obtain. | -| callback | AsyncCallback<[FetchFileResult](#fetchfileresult)> | Yes | Callback invoked to return the file assets obtained.| - -**Example** - -```ts -async function albumGetFileAssetsDemoCallback() { - console.info('albumGetFileAssetsDemoCallback2') - let imageType = userfile_manager.MediaType.IMAGE; - let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - const albumList = await userFileMgr.getAlbums([imageType], AlbumNoArgsfetchOp); - const album = albumList[0]; - album.getFileAssets([imageType], (err, albumFetchFileResult) => { - if (err == undefined) { - console.info("getFileAssets successfully:"+ JSON.stringify(albumFetchFileResult)); - } else { - console.info("getFileAssets failed with error:"+ err); - } - }); -} -``` - -### getFileAssets - -getFileAssets(type: Array<MediaType>, options: MediaFetchOptions, callback: AsyncCallback<FetchFileResult>): void; - -Obtains the file assets in this album. This API uses an asynchronous callback to return the result. - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------------- | ---- | ----------------------------------- | -| type | Array<[MediaType](#mediatype)> | Yes | Type of the media data to obtain. | -| options | [MediaFetchOptions](#mediafetchoptions) | Yes | Options for fetching the media data. | -| callback | AsyncCallback<[FetchFileResult](#fetchfileresult)> | Yes | Callback invoked to return the file assets obtained.| - -**Example** - -```ts -async function albumGetFileAssetsDemoCallback() { - console.info('albumGetFileAssetsDemoCallback') - let imageType = userfile_manager.MediaType.IMAGE; - let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - let fileNoArgsfetchOp = { - selections: '', - selectionArgs: [], - } - const albumList = await userFileMgr.getAlbums([imageType], AlbumNoArgsfetchOp); - const album = albumList[0]; - album.getFileAssets([imageType], fileNoArgsfetchOp, (err, albumFetchFileResult) => { - if (err == undefined) { - console.info("getFileAssets successfully:"+ JSON.stringify(albumFetchFileResult)); - } else { - console.info("getFileAssets failed with error:"+ err); - } - }); - } -``` - -### getFileAssets - -getFileAssets(type: Array<MediaType>, options?: MediaFetchOptions): Promise<FetchFileResult>; - -Obtains the file assets in this album. This API uses a promise to return the result. - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------- | ---------------------------------------- | ---- | -------------- | -| type | Array<[MediaType](#mediatype)> | Yes | Type of the media data to obtain. | -|options | [MediaFetchOptions](#mediafetchoptions) | No | Options for fetching the media data.| - -**Return value** - -| Type | Description | -| --------------------------------------------- | ------------------------- | -| Promise<[FetchFileResult](#fetchfileresult)> | Promise used to return the file assets obtained.| - -**Example** - -```ts -async function albumGetFileAssetsDemoPromise() { - console.info('albumGetFileAssetsDemoPromise') - let imageType = userfile_manager.MediaType.IMAGE; - let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], - }; - let fileNoArgsfetchOp = { - selections: '', - selectionArgs: [], - } - const albumList = await userFileMgr.getAlbums([imageType], AlbumNoArgsfetchOp); - const album = albumList[0]; - album.getFileAssets([imageType], fileNoArgsfetchOp).then(function(albumFetchFileResult){ - console.info("getFileAssets successfully:"+ JSON.stringify(albumFetchFileResult)); - }).catch(function(err){ - console.info("getFileAssets failed with error:"+ err); - }); -} -``` -## VirtualAlbum -Provides APIs for managing a virtual album. - -### getFileAssets - -getFileAssets(type: Array<MediaType>, options: MediaFetchOptions, callback: AsyncCallback<FetchFileResult>): void; - -Obtains file assets in the virtual album. This API uses an asynchronous callback to return the result. - -This is a system API. - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -> **NOTE**
-> The ability privilege level (APL) of the permissions required by this API is **system_basic**. Applications of the **normal** APL need to apply for these permissions through the Access Control List (ACL). For details, see [ACL](../../security/accesstoken-overview.md#acl). -> -> You are advised to use the **options** parameter to explicitly specify the type of the file access. If the file type cannot be determined, the file asset result set is returned based on the permissions of the application. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------------- | ---- | ----------------------------------- | -| type | Array<[MediaType](#mediatype)> | Yes | Type of the media data to obtain. | -| options | [MediaFetchOptions](#mediafetchoptions) | Yes | Options for fetching the files. | -| callback | AsyncCallback<[FetchFileResult](#fetchfileresult)> | Yes | Callback invoked to return the file assets obtained.| - -**Example** - -```ts -async function virtualAlbumGetFileAssetsDemoCallback() { - console.info('virtualAlbumGetFileAssetsDemoCallback') - try { - var albumArray = await userFileMgr.getPrivateAlbum(userfile_manager.VirtualAlbumType.TYPE_TRASH); - } catch (err) { - console.info('getPrivateAlbum failed, message = ', err); - } - let fetchOpt = { - selections: '', - selectionArgs: [], - }; - let trashAlbum = albumArray[0]; - - trashAlbum.getFileAssets([userfile_manager.MediaType.IMAGE], fetchOpt, (err, fetchResult) => { - if (err == undefined) { - let count = fetchResult.getCount(); - console.info('fetchResult.count = ', count); - } else { - console.info('getFileAssets failed, message = ', err); - } - }); -} -``` - -### getFileAssets -getFileAssets(type: Array<MediaType>, options: MediaFetchOptions): Promise<FetchFileResult>; - -Obtains file assets in the virtual album. This API uses a promise to return the result. - -This is a system API. - -**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, or ohos.permission.READ_DOCUMENT - -> **NOTE**
-> The APL of the permissions required by this API is **system_basic**. Applications of the **normal** APL need to apply for these permissions through the ACL. For details, see [ACL](../../security/accesstoken-overview.md#acl). -> -> You are advised to use the **options** parameter to explicitly specify the type of the file access. If the file type cannot be determined, the file asset result set is returned based on the permissions of the application. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------- | ---------------------------------------- | ---- | -------------- | -| type | Array<[MediaType](#mediatype)> | Yes | Type of the media data to obtain. | -|options | [MediaFetchOptions](#mediafetchoptions) | No | Options for fetching the files.| - -**Return value** - -| Type | Description | -| --------------------------------------------- | ------------------------- | -| Promise<[FetchFileResult](#fetchfileresult)> | Promise used to return the file assets obtained.| - -**Example** - -```ts -async function virtualAlbumGetFileAssetsDemoPromise() { - console.info('virtualAlbumGetFileAssetsDemoPromise') - let albumArray = await userFileMgr.getPrivateAlbum(userfile_manager.VirtualAlbumType.TYPE_TRASH); - let fetchOpt = { - selections: '', - selectionArgs: [], - }; - let trashAlbum = albumArray[0]; - - let fetchResult = await trashAlbum.getFileAssets([userfile_manager.MediaType.IMAGE], fetchOpt); - let count = fetchResult.getCount(); - console.info('fetchResult.count = ', count); -} -``` - -## PeerInfo - -Describes information about a registered device. -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore - -| Name | Type | Readable| Writable| Description | -| ---------- | -------------------------- | ---- | ---- | ---------------- | -| deviceName | string | Yes | No | Name of the registered device. | -| networkId | string | Yes | No | Network ID of the registered device.| -| isOnline | boolean | Yes | No | Whether the registered device is online. | - -## MediaType - -Enumerates the media types. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -| Name | Description| -| ----- | ---- | -| FILE | File.| -| IMAGE | Image.| -| VIDEO | Video.| -| AUDIO | Audio.| - -## FileKey - -Defines the key file information. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -| Name | Default Value | Description | -| ------------- | ------------------- | ---------------------------------------------------------- | -| URI | uri | File URI. | -| RELATIVE_PATH | relative_path | Relative public directory of the file. | -| DISPLAY_NAME | display_name | File name displayed. | -| DATE_ADDED | date_added | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. | -| DATE_MODIFIED | date_modified | Date when the file was last modified. The value is the number of seconds elapsed since the Epoch time. | -| TITLE | title | Title in the file. | - -## AudioKey - -Defines the key information about an audio file. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -| Name | Default Value | Description | -| ------------- | ------------------- | ---------------------------------------------------------- | -| URI | uri | Promise used to return the URI of the file created. | -| RELATIVE_PATH | relative_path | Relative public directory of the file. | -| DISPLAY_NAME | display_name | File name displayed. | -| DATE_ADDED | date_added | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. | -| DATE_MODIFIED | date_modified | Date when the file was last modified. The value is the number of seconds elapsed since the Epoch time. | -| TITLE | title | Title in the file. | -| ARTIST | artist | Author of the file. | -| AUDIOALBUM | audio_album | Audio album. | -| DURATION | duration | Duration, in ms. | - -## ImageVideoKey - -Defines the key information about an image or video file. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -| Name | Default Value | Description | -| ------------- | ------------------- | ---------------------------------------------------------- | -| URI | uri | File URI. | -| RELATIVE_PATH | relative_path | Relative public directory of the file. | -| DISPLAY_NAME | display_name | File name displayed. | -| DATE_ADDED | date_added | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. | -| DATE_MODIFIED | date_modified | Date when the file was last modified. The value is the number of seconds elapsed since the Epoch time. | -| DURATION | duration | Duration, in ms. | -| WIDTH | width | Image width, in pixels. | -| HEIGHT | height | Image height, in pixels. | -| DATE_TAKEN | date_taken | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time. | - -## AlbumKey - -Defines the key album information. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -| Name | Default Value | Description | -| ------------- | ------------------- | ---------------------------------------------------------- | -| URI | uri | Album URI. | -| RELATIVE_PATH | relative_path | Relative public directory of the album. | -| DISPLAY_NAME | display_name | Album name displayed. | -| DATE_ADDED | date_added | Date when the album was added. The value is the number of seconds elapsed since the Epoch time. | -| DATE_MODIFIED | date_modified | Date when the album was last modified. The value is the number of seconds elapsed since the Epoch time. | - -## DirectoryType - -Enumerates directory types. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -| Name | Description | -| ------------- | ------------------ | -| DIR_CAMERA | Directory of camera files.| -| DIR_VIDEO | Directory of video files. | -| DIR_IMAGE | Directory of image files. | -| DIR_AUDIO | Directory of audio files. | -| DIR_DOCUMENTS | Directory of documents. | -| DIR_DOWNLOAD | Download directory. | - -## MediaFetchOptions - -Defines the options for fetching media files. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -| Name | Type | Readable| Writable| Mandatory| Description | -| ----------------------- | ------------------- | ---- | ---- | ---- | ------------------------------------------------------------ | -| selections | string | Yes | Yes | Yes | Conditions for fetching files. The values in [FileKey](#filekey) are used as the column names of the conditions. Example:
selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR' +mediaLibrary.FileKey.MEDIA_TYPE + '= ?',| -| selectionArgs | Array<string> | Yes | Yes | Yes | Values of the conditions specified in **selections**.
Example:
selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], | - -## Size - -Defines the image size. -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -| Name | Type | Readable | Writable | Description | -| ------ | ------ | ---- | ---- | -------- | -| width | number | Yes | Yes | Image width, in pixels.| -| height | number | Yes | Yes | Image height, in pixels.| - -## VirtualAlbumType -Enumerates the system or virtual album types. - -This is a system API. - -**System capability**: SystemCapability.FileManagement.UserFileManager.Core - -| Name | Description | -| ------------- | ------------------ | -| TYPE_FAVORITE | Favorites album.
This is a system API.| -| TYPE_TRASH | Trash album.
This is a system API.| diff --git a/en/application-dev/reference/apis/js-apis-wallpaper.md b/en/application-dev/reference/apis/js-apis-wallpaper.md index 371e69dd03b0e5886456a189f9aceeb4444610c0..c7f4c94d54cc19d3a95ff40784af886d28f1e3ff 100644 --- a/en/application-dev/reference/apis/js-apis-wallpaper.md +++ b/en/application-dev/reference/apis/js-apis-wallpaper.md @@ -1,6 +1,6 @@ # @ohos.wallpaper -The **wallpaper** module is part of the theme framework and provides the system-level wallpaper management service in OpenHarmony. You can use the APIs of this module to show, set, and switch between wallpapers. +The **wallpaper** module is a system service module in OpenHarmony that provides the wallpaper management service. You can use the APIs of this module to show, set, and switch between wallpapers. > **NOTE** > @@ -63,7 +63,12 @@ Obtains the main color information of the wallpaper of the specified type. **Example** ```js -let colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); +try { + let colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); + console.log(`success to getColorsSync: ${JSON.stringify(colors)}`); +} catch (error) { + console.error(`failed to getColorsSync because: ${JSON.stringify(error)}`); +} ``` ## wallpaper.getIdSync9+ @@ -84,12 +89,17 @@ Obtains the ID of the wallpaper of the specified type. | Type| Description| | -------- | -------- | -| number | ID of the wallpaper. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to 2^31-1.| +| number | ID of the wallpaper. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to (2^31-1).| **Example** ```js -let id = wallpaper.getIdSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); +try { + let id = wallpaper.getIdSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); + console.log(`success to getIdSync: ${JSON.stringify(id)}`); +} catch (error) { + console.error(`failed to getIdSync because: ${JSON.stringify(error)}`); +} ``` ## wallpaper.getMinHeightSync9+ @@ -187,7 +197,7 @@ Resets the wallpaper of the specified type to the default wallpaper. This API us | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is error information.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is reset, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** @@ -247,14 +257,14 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.| +| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is error information.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** ```js -//The source type is string. +// The source type is string. let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { if (error) { @@ -300,7 +310,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.| +| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| **Return value** @@ -312,7 +322,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr **Example** ```js -//The source type is string. +// The source type is string. let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { console.log(`success to setImage.`); @@ -365,7 +375,12 @@ Obtains the wallpaper of the specified type. **Example** ```js -let file = wallpaper.getFileSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); +try { + let file = wallpaper.getFileSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); + console.log(`success to getFileSync: ${JSON.stringify(file)}`); +} catch (error) { + console.error(`failed to getFileSync because: ${JSON.stringify(error)}`); +} ``` ## wallpaper.getImage9+ @@ -385,7 +400,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses an | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes| Callback used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.| +| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes| Callback used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| **Example** @@ -422,7 +437,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses a p | Type| Description| | -------- | -------- | -| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.| +| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| **Example** @@ -452,10 +467,14 @@ Subscribes to the wallpaper color change event. **Example** ```js -let listener = (colors, wallpaperType) => { - console.log(`wallpaper color changed.`); -}; -wallpaper.on('colorChange', listener); +try { + let listener = (colors, wallpaperType) => { + console.log(`wallpaper color changed.`); + }; + wallpaper.on('colorChange', listener); +} catch (error) { + console.error(`failed to on because: ${JSON.stringify(error)}`); +} ``` ## wallpaper.off('colorChange')9+ @@ -479,11 +498,25 @@ Unsubscribes from the wallpaper color change event. let listener = (colors, wallpaperType) => { console.log(`wallpaper color changed.`); }; -wallpaper.on('colorChange', listener); -// Unsubscribe from the listener. -wallpaper.off('colorChange', listener); -// Unsubscribe from all subscriptions of the colorChange type. -wallpaper.off('colorChange'); +try { + wallpaper.on('colorChange', listener); +} catch (error) { + console.error(`failed to on because: ${JSON.stringify(error)}`); +} + +try { + // Unsubscribe from the listener. + wallpaper.off('colorChange', listener); +} catch (error) { + console.error(`failed to off because: ${JSON.stringify(error)}`); +} + +try { + // Unsubscribe from all subscriptions of the colorChange type. + wallpaper.off('colorChange'); +} catch (error) { + console.error(`failed to off because: ${JSON.stringify(error)}`); +} ``` ## wallpaper.getColors(deprecated) @@ -568,7 +601,7 @@ Obtains the ID of the wallpaper of the specified type. This API uses an asynchro | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<number> | Yes| Callback used to return the wallpaper ID. If the wallpaper of the specified type is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to 2^31-1.| +| callback | AsyncCallback<number> | Yes| Callback used to return the wallpaper ID. If the wallpaper of the specified type is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to (2^31-1).| **Example** @@ -604,7 +637,7 @@ Obtains the ID of the wallpaper of the specified type. This API uses a promise t | Type| Description| | -------- | -------- | -| Promise<number> | Promise used to return the wallpaper ID. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to 2^31-1.| +| Promise<number> | Promise used to return the wallpaper ID. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to (2^31-1).| **Example** @@ -867,7 +900,7 @@ Resets the wallpaper of the specified type to the default wallpaper. This API us | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is error information.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is reset, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** @@ -935,14 +968,14 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.| +| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is error information.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** ```js -//The source type is string. +// The source type is string. let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { if (error) { @@ -992,7 +1025,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.| +| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| **Return value** @@ -1004,7 +1037,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr **Example** ```js -//The source type is string. +// The source type is string. let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { console.log(`success to setWallpaper.`); @@ -1123,7 +1156,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses an | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<image.PixelMap> | Yes| Callback used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.| +| callback | AsyncCallback<image.PixelMap> | Yes| Callback used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| **Example** @@ -1163,7 +1196,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses a p | Type| Description| | -------- | -------- | -| Promise<image.PixelMap> | Promise used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.| +| Promise<image.PixelMap> | Promise used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| **Example** diff --git a/en/application-dev/reference/arkui-js/Readme-EN.md b/en/application-dev/reference/arkui-js/Readme-EN.md index d14e06d8a3a83329a2a6e2b508508e03c93aea4c..c46abd3bd91d1acbf99bb15152d3f55f636483eb 100644 --- a/en/application-dev/reference/arkui-js/Readme-EN.md +++ b/en/application-dev/reference/arkui-js/Readme-EN.md @@ -96,10 +96,9 @@ - Custom Components - [Basic Usage](js-components-custom-basic-usage.md) - - [Style Inheritance](js-components-custom-style.md) - - [Custom Events](js-components-custom-events.md) - [props](js-components-custom-props.md) - - [Event Parameter](js-components-custom-event-parameter.md) + - [Style Inheritance](js-components-custom-style.md) - [slot](js-components-custom-slot.md) - [Lifecycle Definition](js-components-custom-lifecycle.md) -- [Data Type Attributes](js-appendix-types.md) +- [Dynamic Component Creation](js-components-create-elements.md) +- [Data Type Attributes](js-appendix-types.md) diff --git a/en/application-dev/reference/arkui-js/figures/animate-4.gif b/en/application-dev/reference/arkui-js/figures/en-us_image_0000001127125126.gif similarity index 100% rename from en/application-dev/reference/arkui-js/figures/animate-4.gif rename to en/application-dev/reference/arkui-js/figures/en-us_image_0000001127125126.gif diff --git a/en/application-dev/reference/arkui-js/en-us_image_0000001127284938.gif b/en/application-dev/reference/arkui-js/figures/en-us_image_0000001127284938.gif similarity index 100% rename from en/application-dev/reference/arkui-js/en-us_image_0000001127284938.gif rename to en/application-dev/reference/arkui-js/figures/en-us_image_0000001127284938.gif diff --git a/en/application-dev/reference/arkui-js/en-us_image_0000001167662852.gif b/en/application-dev/reference/arkui-js/figures/en-us_image_0000001167662852.gif similarity index 100% rename from en/application-dev/reference/arkui-js/en-us_image_0000001167662852.gif rename to en/application-dev/reference/arkui-js/figures/en-us_image_0000001167662852.gif diff --git a/en/application-dev/reference/arkui-js/en-us_image_0000001173324703.gif b/en/application-dev/reference/arkui-js/figures/en-us_image_0000001173324703.gif similarity index 100% rename from en/application-dev/reference/arkui-js/en-us_image_0000001173324703.gif rename to en/application-dev/reference/arkui-js/figures/en-us_image_0000001173324703.gif diff --git a/en/application-dev/reference/arkui-js/js-components-common-customizing-font.md b/en/application-dev/reference/arkui-js/js-components-common-customizing-font.md index 4054548e00f9e9b80e8d3fff5abc9d3cf209c2b4..f57ab118948791263a353c2d1da63d08ecc6466e 100644 --- a/en/application-dev/reference/arkui-js/js-components-common-customizing-font.md +++ b/en/application-dev/reference/arkui-js/js-components-common-customizing-font.md @@ -11,8 +11,8 @@ The custom font can be loaded from the font file in a project. The font file mus ``` @font-face { - font-family: HWfont; - src: url('/common/HWfont.ttf'); + font-family: font; + src: url('/common/font.ttf'); } ``` @@ -48,10 +48,10 @@ Page style: ```css /*xxx.css*/ @font-face { - font-family: HWfont; - src: url("/common/HWfont.ttf"); + font-family: font; + src: url("/common/font.ttf"); } .demo-text { - font-family: HWfont; + font-family: font; } ``` diff --git a/en/application-dev/reference/arkui-js/js-components-common-methods.md b/en/application-dev/reference/arkui-js/js-components-common-methods.md index 044dbfb7308137d34cb00d4b6720ad162c99e5d9..3a7d61034f5e8eece95d71ebe9ca2c82556401f7 100644 --- a/en/application-dev/reference/arkui-js/js-components-common-methods.md +++ b/en/application-dev/reference/arkui-js/js-components-common-methods.md @@ -32,7 +32,7 @@ animate( keyframes: Keyframes, options: Options): void | height | number | - | Height set for the component during playback of the animation. | | backgroundColor | <color> | none | Background color set for the component during playback of the animation. | | opacity | number | 1 | Opacity set for the component. The value ranges from 0 to 1. | -| backgroundPosition | string | - | The value format is **x y**, in percentage or pixels.
The first value indicates the horizontal position, and the second value indicates the vertical position.
If only one value is specified, the other value is **50%**.| +| backgroundPosition | string | - | The value format is **"x y"**, in percentage or pixels.
The first value indicates the horizontal position, and the second value indicates the vertical position.
If only one value is specified, the other value is **50%**.| | transformOrigin | string | 'center center' | Origin position of the transformed element.
The first value indicates the x-axis position. The value can be **left**, **center**, **right**, a length, or a percentage.
The second value indicates the y-axis position. The value can be **top**, **center**, **bottom**, a length, or a percentage.| | transform | [Transform](../arkui-js/js-components-common-animation.md) | - | Transformation type set for a transformed element. | | offset | number | - | - The value of **offset** must be within (0.0, 1.0] and sorted in ascending order if it is provided.
- If there are only two frames, **offset** can be left empty.
- If there are more than two frames, **offset** is mandatory.| @@ -53,10 +53,10 @@ animate( keyframes: Keyframes, options: Options): void | Value | Description | | ---------------------------------------- | ---------------------------------------- | | linear | The animation speed keeps unchanged. | -| ease-in | The animation starts at a low speed. **cubic-bezier(0.42, 0.0, 1.0, 1.0)**.| -| ease-out | The animation ends at a low speed. **cubic-bezier(0.0, 0.0, 0.58, 1.0)**.| -| ease-in-out | The animation starts and ends at a low speed. **cubic-bezier(0.42, 0.0, 0.58, 1.0)**.| -| friction | The animation uses the damping curve, **cubic-bezier(0.2, 0.0, 0.2, 1.0)**.| +| ease-in | The animation starts at a low speed and then picks up speed until the end. The cubic-bezier curve (0.42, 0.0, 1.0, 1.0) is used.| +| ease-out | The animation ends at a low speed. The cubic-bezier curve (0.0, 0.0, 0.58, 1.0) is used.| +| ease-in-out | The animation starts and ends at a low speed. The cubic-bezier curve (0.42, 0.0, 0.58, 1.0) is used.| +| friction | The animation uses the friction cubic-bezier curve (0.2, 0.0, 0.2, 1.0).| | extreme-deceleration | The animation uses the extreme deceleration cubic-bezier curve (0.0, 0.0, 0.0, 1.0).| | sharp | The animation uses the sharp cubic-bezier curve (0.33, 0.0, 0.67, 1.0).| | rhythm | The animation uses the rhythm cubic-bezier curve (0.7, 0.0, 0.2, 1.0).| @@ -71,7 +71,7 @@ animate( keyframes: Keyframes, options: Options): void | --------- | ------- | ---------------------------------------- | | finished | boolean | Read-only attribute, which indicates whether the animation playback is complete. | | pending | boolean | Read-only attribute, which indicates whether the animation is waiting for the completion of other asynchronous operations (for example, start an animation with a delay).| -| playState | string | Read-write attribute, which indicates the playback status of the animation:
- **idle**: The animation is not running (playback ended or not started).
- **running**: The animation is running.
- **paused**: The animation is paused.
- **finished**: Animation playback ends.| +| playState | string | Read-write attribute, which indicates the playback status of the animation:
- **idle**: The animation is not running (playback ended or not started).
- **running**: The animation is running.
- **paused**: The animation is paused.
- **finished**: The animation finishes playing.| | startTime | number | Read-write attribute, which indicates the animation start time. This attribute is similar to **delay** in the **options** attribute. | The **animation** methods are as follows. @@ -103,7 +103,7 @@ animate( keyframes: Keyframes, options: Options): void start @@ -139,7 +139,7 @@ button{ ```js // xxx.js -import prompt from '@system.prompt'; +import promptAction from '@ohos.promptAction'; export default{ data:{ animation:'', @@ -162,19 +162,19 @@ export default{ this.animation = this.$element('idName').animate(frames, options); // handle finish event this.animation.onfinish = function(){ - prompt.showToast({ + promptAction.showToast({ message: "The animation is finished." }); }; // handle cancel event this.animation.oncancel = function(){ - prompt.showToast({ + promptAction.showToast({ message: "The animation is canceled." }); }; // handle repeat event this.animation.onrepeat = function(){ - prompt.showToast({ + promptAction.showToast({ message: "The animation is repeated." }); }; diff --git a/en/application-dev/reference/arkui-js/js-components-common-styles.md b/en/application-dev/reference/arkui-js/js-components-common-styles.md index 2c61ed94f1317ccbd3e429b6bc2a3516db28f337..611529aec1de7dc133ff4fab8c784622cb60591a 100644 --- a/en/application-dev/reference/arkui-js/js-components-common-styles.md +++ b/en/application-dev/reference/arkui-js/js-components-common-styles.md @@ -9,61 +9,61 @@ You can set universal styles for components in the **style** attribute or **.css | Name | Type | Default Value | Description | | ---------------------------------------- | ---------------------------------------- | ------------ | ---------------------------------------- | -| width | <length> \| <percentage> | - | Component width.
If this attribute is not set, the width required for the element content is used.
| -| height | <length> \| <percentage> | - | Component height.
If this attribute is not set, the height required for the element content is used.
| +| width | <length> \| <percentage> | - | Component width.
If this attribute is not set, the width required for the element content is used. | +| height | <length> \| <percentage> | - | Component height.
If this attribute is not set, the height required for the element content is used. | | min-width5+ | <length> \| <percentage>6+ | 0 | Minimum component width. | | min-height5+ | <length> \| <percentage>6+ | 0 | Minimum component height. | | max-width5+ | <length> \| <percentage>6+ | - | Maximum component width, which has no restriction by default. | | max-height5+ | <length> \| <percentage>6+ | - | Maximum component height, which has no restriction by default. | | padding | <length> \| <percentage>5+ | 0 | Shorthand attribute to set the padding for all sides in a declaration.
The attribute can have one to four values:
- If you set only one value, it specifies the padding for all the four sides.
- If you set two values, the first value specifies the top and bottom padding, and the second value specifies the left and right padding.
- If you set three values, the first value specifies the top padding, the second value specifies the left and right padding, and the third value specifies the bottom padding.
- If you set four values, they respectively specify the padding for top, right, bottom, and left sides (in clockwise order).| -| padding-[left \| top \| right \| bottom] | <length> \| <percentage>5+ | 0 | Left, top, right, and bottom padding. | -| padding-[start \| end] | <length> \| <percentage>5+ | 0 | Start and end padding. | +| padding-[left\|top\|right\|bottom] | <length> \| <percentage>5+ | 0 | Left, top, right, and bottom padding. | +| padding-[start\|end] | <length> \| <percentage>5+ | 0 | Start and end padding. | | margin | <length> \| <percentage>5+ | 0 | Shorthand attribute to set the margin for all sides in a declaration. The attribute can have one to four values:
- If you set only one value, it specifies the margin for all the four sides.
- If you set two values, the first value specifies the top and bottom margins, and the second value specifies the left and right margins.
- If you set three values, the first value specifies the top margin, the second value specifies the left and right margins, and the third value specifies the bottom margin.
- If you set four values, they respectively specify the margin for top, right, bottom, and left sides (in clockwise order).| -| margin-[left \| top \| right \| bottom] | <length> \| <percentage>5+ | 0 | Left, top, right, and bottom margins. | -| margin-[start \| end] | <length> \| <percentage>5+ | 0 | Start and end margins. | +| margin-[left\|top\|right\|bottom] | <length> \| <percentage>5+ | 0 | Left, top, right, and bottom margins. | +| margin-[start\|end] | <length> \| <percentage>5+ | 0 | Start and end margins. | | border | - | 0 | Shorthand attribute to set all borders. Set **border-width**, **border-style**, and **border-color** in sequence. Default values are used for attributes that are not set.| | border-style | string | solid | Shorthand attribute to set the style for all borders. Available values are as follows:
- **dotted**: dotted border. The radius of a dot is half of **border-width**.
- **dashed**: dashed border.
- **solid**: solid border.| | border-[left\|top\|right\|bottom]-style | string | solid | Styles of the left, top, right, and bottom borders. The available values are **dotted**, **dashed**, and **solid**.| -| border-[left \| top \| right \| bottom] | - | - | Shorthand attribute to set the borders for every side respectively. Set **border-width**, **border-style**, and **border-color** in sequence. Default values are used for attributes that are not set.| +| border-[left\|top\|right\|bottom] | - | - | Shorthand attribute to set the borders for every side respectively. Set **border-width**, **border-style**, and **border-color** in sequence. Default values are used for attributes that are not set.| | border-width | <length> | 0 | Shorthand attribute to set the width for all borders, or separately set the width for each border. | -| border-[left \| top \| right \| bottom]-width | <length> | 0 | Attribute to set widths of left, top, right, and bottom borders. | +| border-[left\|top\|right\|bottom]-width | <length> | 0 | Attribute to set widths of left, top, right, and bottom borders. | | border-color | <color> | black | Shorthand attribute to set the color for all borders, or separately set the color for each border. | -| border-[left \| top \| right \| bottom]-color | <color> | black | Attribute to set colors for left, top, right, and bottom borders. | -| border-radius | <length> | - | Attribute to set the radius for round borders of an element. This attribute cannot be used to set the width, color, or style of a specific border. To set the width or color, you need to set **border-width**, **border-color**, or **border-style** for all the borders at the same time.| -| border-[top \| bottom]-[left \| right]-radius | <length> | - | Attribute to respectively set the radii of upper-left, upper-right, lower-right, and lower-left rounded corners | +| border-[left\|top\|right\|bottom]-color | <color> | black | Attribute to set colors for left, top, right, and bottom borders. | +| border-radius | <length> | - | Attribute to set the radius for round borders of an element. This attribute cannot be used to set the width, color, or style of a specific border. To set the width or color, you need to set **border-width**, **border-color**, or **border-style** for all the borders at the same time.
In the four-value syntax, the values apply to lower-left corner, lower-right corner, upper-left corner, and upper-right corner, respectively.| +| border-[top\|bottom]-[left\|right]-radius | <length> | - | Attribute to respectively set the radii of upper-left, upper-right, lower-right, and lower-left rounded corners | | background | <linear-gradient> | - | Background. This attribute supports [gradient styles](../arkui-js/js-components-common-gradient.md) only and is not compatible with **background-color** or **background-image**.| | background-color | <color> | - | Background color. | | background-image | string | - | Background image. Both online and local image resources are supported. Currently, this attribute is not compatible with **background-color** or **background**.
Example:
- background-image: url("/common/background.png")
The SVG format is not supported.| -| background-size | - string
- <length> <length>
- <percentage> <percentage> | auto | Background image size.
- The **string** values are as follows:
- **contain**: Expands the image to the maximum size so that its height and width are fully applicable to the content area.
- **cover**: Extends the background image to a large enough size so that it completely covers the background area. Some parts of the image may not be displayed in the background area.
- **auto**: Retains the original aspect ratio of the image.
- The two **\** values are as follows:
Width and height of the background image. The first value indicates the width, and the second value indicates the height. If you only set one value, the other value is set to **auto** by default.
- The two **\** values are as follows:
Width and height of the background image in percentage of the parent element. The first value indicates the width, and the second value indicates the height. If you only set one value, the other value is set to **auto** by default.| -| background-repeat | string | repeat | How a background image is repeatedly drawn. By default, a background image is repeated both horizontally and vertically.
- **repeat**: The image is repeated along the x-axis and y-axis at the same time.
- **repeat-x**: The image is repeated along the x-axis.
- **repeat-y**: The image is repeated along the y-axis.
- **no-repeat**: The image is not repeated.| -| background-position | - string string
- <length> <length>
- <percentage> <percentage> | 0px 0px | - Using keywords: If only one keyword is specified, the other value is **center** by default. The two values define the horizontal position and vertical position, respectively.
- **left**: leftmost in the horizontal direction.
- **right**: rightmost in the horizontal direction.
- **top**: top in the vertical direction.
- **bottom**: bottom in the vertical direction.
- **center**: center position.
- Using **\**: The first value indicates the horizontal position, and the second value indicates the vertical position. For the upper left corner, the value is **0 0**. The unit is pixel. If only one value is specified, the other one is **50%**.
- Using **\**: The first value indicates the horizontal position, and the second value indicates the vertical position. **0% 0%** indicates the upper left corner. **100% 100%** indicates the lower right corner. If only one value is specified, the other one is **50%**.
- Using both **\** and **\**. | -| box-shadow5+ | string | 0 | Syntax: **box-shadow: h-shadow v-shadow blur spread color**
Shadow style of the current component. The value includes the horizontal position (mandatory), vertical position (mandatory), fuzzy radius (optional, default value: **0**), extension distance (optional, default value: **0**), and color (optional, default value: **black**) of the shadow.
Example:
- box-shadow :10px 20px 5px 10px \#888888
- box-shadow :100px 100px 30px red
- box-shadow :-100px -100px 0px 40px | -| filter5+ | string | - | Syntax: **filter: blur(px)**
Radius of the blur area within the component layout. If this style is not set, the default value **0** (no blur) is used. Percentage values are not supported.
Example:
- filter: blur(10px) | -| backdrop-filter5+ | string | - | Syntax: **backdrop-filter: blur(px)**
Radius of the background blur area within the component layout. If this style is not set, the default value **0** (no blur) is used. Percentage values are not supported.
Example:
- backdrop-filter: blur(10px) | -| window-filter5+ | string | - | Syntax: window-filter: blur(percent), style5+
Blur degree and style for windows within the component layout. If this style is not set, the default value **0%** (no blur area) is used. Different blur degrees and styles for multiple blur areas are not supported. Available blur styles are as follows: **small_light** (default value), **medium_light**, **large_light**, **xlarge_light**, **small_dark**, **medium_dark**, **large_dark**, and **xlarge_dark**.
Example:
- window-filter: blur(50%)
- window-filter: blur(10%), large_light | +| background-size | - string
- <length> <length>
- <percentage> <percentage> | auto | Background image size.
- The available values of the **string** type are as follows:
- **contain**: extends the image to the maximum size so that its height and width are fully applicable to the content area.
- **cover**: extends the background image to a large enough size so that it completely covers the background area. Some parts of the image may not be displayed in the background area.
- **auto**: retains the original aspect ratio of the image.
- Values of the **\** type:
The two values are width and height of the background image. The first value indicates the width, and the second value indicates the height. If you only set one value, the other value is set to **auto** by default.
- Values of the **\** type:
The two values are width and height of the background image in percentage of the parent element. The first value indicates the width, and the second value indicates the height. If you only set one value, the other value is set to **auto** by default.| +| background-repeat | string | repeat | How a background image is repeatedly drawn. By default, a background image is repeated both horizontally and vertically.
- **repeat**: The image is repeated along both the x-axis and y-axis.
- **repeat-x**: The image is repeated along the x-axis.
- **repeat-y**: The image is repeated along the y-axis.
- **no-repeat**: The image is not repeated.| +| background-position | - string string
- <length> <length>
- <percentage> <percentage> | 0px 0px | - Values of the **string** type: If only one value is specified, the other value is **center** by default. The two values define the horizontal position and vertical position, respectively.
- **left**: leftmost in the horizontal direction.
- **right**: rightmost in the horizontal direction.
- **top**: top in the vertical direction.
- **bottom**: bottom in the vertical direction.
- **center**: center in the horizontal or vertical direction.
- Values of the **\** type: The first value indicates the horizontal position, and the second value indicates the vertical position. For the upper left corner, the value is 0 0 in px (**0px 0px**). If only one value is specified, the other one is **50%**.
- Values of the **\** type: The first value indicates the horizontal position, and the second value indicates the vertical position. For the upper left corner, the value is 0% 0%. For the lower right corner, the value is **100% 100%**. If only one value is specified, the other one is **50%**.
- Values of the **\** type and **\** type can be used together.| +| box-shadow5+ | string | 0 | Syntax: box-shadow: h-shadow v-shadow blur spread color
Shadow style of the current component. The value includes the horizontal position (mandatory), vertical position (mandatory), fuzzy radius (optional, default value: **0**), extension distance (optional, default value: **0**), and color (optional, default value: **black**) of the shadow.
Example:
- box-shadow :10px 20px 5px 10px \#888888
- box-shadow :100px 100px 30px red
- box-shadow :-100px -100px 0px 40px | +| filter5+ | string | - | Syntax: filter: blur(px)
Radius of the blur area within the component layout. If this style is not set, the default value **0** (no blur) is used. Percentage values are not supported.
Example:
- filter: blur(10px) | +| backdrop-filter5+ | string | - | Syntax: backdrop-filter: blur(px)
Radius of the background blur area within the component layout. If this style is not set, the default value **0** (no blur) is used. Percentage values are not supported.
Example:
- backdrop-filter: blur(10px) | +| window-filter5+ | string | - | Syntax: window-filter: blur(percent), style5+
Blur degree and style for windows within the component layout. If this style is not set, the default value **0%** (no blur area) is used. Different blur degrees and styles for multiple blur areas are not supported. Available values of **style** are as follows: small_light (default value), medium_light, large_light, xlarge_light, small_dark, medium_dark, large_dark, xlarge_dark
Example:
- window-filter: blur(50%)
- window-filter: blur(10%), large_light | | opacity | number | 1 | Opacity of an element. The value ranges from **0** to **1**. The value **1** means opaque, and **0** means completely transparent. | -| display | string | flex | Type of the box containing an element. Available values are as follows:
- **flex**: Flexible layout.
- **none**: The box is disabled.
- **inline**9+: Inline box, where the element is displayed as an inline element and does not start on a new line.
- **block**9+: Block box, where the element is displayed as a block-level element and always starts on a new line. This is the default value for container components.
- **inline-block**9+: Inline-block box, where the element is displayed on one line and you can set a width and height on the element. This is the default value for basic components.| +| display | string | flex | Type of the box containing an element. Available values are as follows:
- **flex**: flexible layout
- **none**: not rendered
- **grid**: grid layout (available only for the **\
** component) | | visibility | string | visible | Whether to display the box containing an element. The invisible box occupies layout space. (To remove the box, set the **display** attribute to **none**.) Available values are as follows:
- **visible**: The element is visible.
- **hidden**: The box is hidden but still takes up space.
If both **visibility** and **display** are set, only **display** takes effect.| | flex | number \| string | - | How to divide available space of the parent component for each child component.
You can set one, two5+, or three5+ values for this style.
Set one value in either of the following ways:
- A unitless number to set **flex-grow**.
- A valid width value5+ to set **flex-basis**.
Set two values5+ in the following ways:
The first value must be a unitless number used to set **flex-grow**. The second value must be either of the following:
- A unitless number to set **flex-shrink**.
- A valid width value to set **flex-basis**.
Set three values5+ in the following ways:
The first value must be a unitless number used to set **flex-grow**. The second value must be a unitless number used to set **flex-shrink**. The third value must be a valid width value used to set **flex-basis**.
This style takes effect only when the container is any of the following components: **\
**, **\**, **\**, **\**, and **\5+**.| | flex-grow | number | 0 | How much a child component will grow. The value specifies allocation of the remaining space on the main axis of the parent component. Size of available space = Container size - Total size of all child components. Value **0** indicates that the child component does not grow.
This style takes effect only when the container is any of the following components: **\
**, **\**, **\**, **\**, and **\5+**.| | flex-shrink | number | 1 | How much a child component will shrink. The shrink occurs only when the sum of default child component widths is greater than that of the parent component. Value **0** indicates that the child component does not shrink.
This style takes effect only when the container is any of the following components: **\
**, **\**, **\**, **\**, and **\5+**.| | flex-basis | <length> | - | Initial length of the flex item on the main axis.
This style takes effect only when the container is any of the following components: **\
**, **\**, **\**, **\**, and **\5+**.| -| align-self6+ | string | - | Alignment mode on the cross axis of the parent element. This style overwrites the align-items style of the parent element. The align-items style is used only in the div and list styles of the parent container. Available values are as follows:
- **stretch**: Items are stretched to the same height or width as the container in the cross axis direction.
- **flex-start**: Items are aligned to the start of the cross axis.
- **flex-end**: Items are aligned to the end of the cross axis.
- **center**: Items are aligned in the center of the cross axis.
- **baseline**: Items are aligned on the peracross axis.| -| position | string | relative | Positioning type of an element. Dynamic changes are not supported.
- **fixed**: The element is positioned related to the browser window.
- **absolute**: The element is positioned absolutely to its parent element. The setting takes effect only when the parent component is **\
** or **\**.
- **relative**: The element is positioned relative to its normal position.| -| [left \| top \| right \| bottom] | <length> \| <percentage>6+ | - | **left | top | right | bottom** must be used together with **position** to determine the offset of an element.
- The **left** attribute specifies the left edge position of the element. This attribute defines the offset between the left edge of the margin area of a positioned element and left edge of its containing block.
- The **top** attribute specifies the top edge position of the element. This attribute defines the offset between the top edge of a positioned element and that of a block included in the element.
- The **right** attribute specifies the right edge position of the element. This attribute defines the offset between the right edge of a positioned element and that of a block included in the element.
- The **bottom** attribute specifies the bottom edge position of the element. This attribute defines the offset between the bottom edge of a positioned element and that of a block included in the element. | -| [start \| end]6+ | <length> \| <percentage> | - | **start | end** must be used together with **position** to determine the offset of an element.
- The **start** attribute specifies the start edge position of the element. This attribute defines the offset between the start edge of a positioned element and that of a block included in the element.
- The **end** attribute specifies the end edge position of the element. This attribute defines the offset between the end edge of a positioned element and that of a block included in the element. | +| align-self6+ | string | - | How items are aligned along the main axis of the container. The setting overwrites the **align-items** setting of the container and is valid only when the container is **\
** or **\**. Available values are as follows:
- **stretch**: Items are stretched to the same height or width as the container along the cross axis.
- **flex-start**: Items are packed toward the start edge of the cross axis.
- **flex-end**: Items are packed toward the end edge of the cross axis.
- **center**: Items are packed toward the center of the cross axis.
- **baseline**: Items are packed toward the baseline of the cross axis.| +| position | string | relative | Positioning type of an element. Dynamic changes are not supported.
- **fixed**: The element is positioned relative to the entire UI.
- **absolute**: The element is positioned relative to the container. The setting is valid only when the container is **\
** or **\**.
- **relative**: The element is positioned relative to its normal position.| +| [left \| top \| right \| bottom] | <length> \| <percentage>6+ | - | Edge of the element. This style must be used together with **position** to determine the offset of an element.
- **left**: left edge position of the element. This attribute defines the offset between the left edge of the margin area of a positioned element and left edge of its containing block.
- **top**: top edge position of the element. This attribute defines the offset between the top edge of a positioned element and that of a block included in the element.
- **right**: right edge position of the element. This attribute defines the offset between the right edge of a positioned element and that of a block included in the element.
- **bottom**: bottom edge position of the element. This attribute defines the offset between the bottom edge of a positioned element and that of a block included in the element. | +| [start \| end]6+ | <length> \| <percentage> | - | start \| end must be used together with **position** to determine the offset of an element.
- **start**: start edge position of the element. This attribute defines the offset between the start edge of a positioned element and that of a block included in the element.
- **end**: end edge position of the element. This attribute defines the offset between the end edge of a positioned element and that of a block included in the element.| | z-index6+ | number | - | Rendering sequence of child nodes under the same parent node. A child node with a larger value will be rendered later.
z-index does not support auto, and other styles such as opacity do not affect the rendering sequence of z-index.| -| image-fill6+ | <color> | - | Fill color for SVG images. The following components are supported: **button** (icon attribute), **piece** (icon attribute), **search** (icon attribute), **input** (headericon attribute), **textarea** (headericon attribute), **image** (src attribute), and **toolbar-item** (icon attribute)
The **fill** color value in the SVG image file is replaced with the value of **image-fill** during rendering, and is valid only for the fill attribute that is declared in the SVG image.| -| clip-path6+ | [ <geometry-box> \| <basic-shape> ] \| none | - | Clip area of a component. Only the content within this area is displayed.
**\**: applicable scope of the clip area's width and height. The default value is **border-box**. Available values are as follows:
- **margin-box**: The width and height includes the margin.
- **border-box**: The width and height includes the border.
- **padding-box**: The width and height includes the padding.
- **content-box**: The width and height does not include any margin, border, or padding.
**\**: shape of the clip area. Available values include:
- **inset**, in the format of inset( \{1,4} [ round \<'border-radius'> ]? ).
- **circle**, in the format of circle( [ \ ]? [ at <percentage> <percentage> ]? ).
- **ellipse**, in the format of ellipse( [ \{2} ]? [ at <percentage> <percentage> ]? ).
- **polygon**, in the format of polygon( [ \ \ ]\# ).
- **path**, in the format of path( \ ).| +| image-fill6+ | <color> | - | Fill color for SVG images. The following components are supported: **\