提交 db19d2fa 编写于 作者: Z zengyawen

update docs

Signed-off-by: Nzengyawen <zengyawen1@huawei.com>
上级 78f62b8c
- [Application Development Overview](application-dev-guide.md) - [Application Development Overview](application-dev-guide.md)
- Quick Start - Quick Start
- Getting Started with Application Development
- DevEco Studio (OpenHarmony) User Guide
- [Overview](quick-start/deveco-studio-overview.md)
- [Version Change History](quick-start/deveco-studio-release-notes.md)
- [Configuring the OpenHarmony SDK](quick-start/configuring-openharmony-sdk.md)
- Creating an OpenHarmony Project
- [Using the Project Wizard to Create a Project](quick-start/use-wizard-to-create-project.md)
- [Importing a Sample to Create a Project](quick-start/import-sample-to-create-project.md)
- [Configuring the OpenHarmony App Signature](quick-start/configuring-openharmony-app-signature.md)
- [Installing and Running Your OpenHarmony App](quick-start/installing-openharmony-app.md)
- [Directory Structure](quick-start/package-structure.md) - [Directory Structure](quick-start/package-structure.md)
- [Resource File Categories](quick-start/basic-resource-file-categories.md) - [Resource File Categories](quick-start/basic-resource-file-categories.md)
- Development - Development
...@@ -24,7 +14,7 @@ ...@@ -24,7 +14,7 @@
- Other - Other
- [Ability Assistant Usage](ability/ability-assistant-guidelines.md) - [Ability Assistant Usage](ability/ability-assistant-guidelines.md)
- [UI]](ui/Readme-EN.md) - [UI](ui/Readme-EN.md)
- JavaScript-based Web-Like Development Paradigm - JavaScript-based Web-Like Development Paradigm
- [Overview](ui/ui-js-overview.md) - [Overview](ui/ui-js-overview.md)
- Framework - Framework
...@@ -213,13 +203,7 @@ ...@@ -213,13 +203,7 @@
- [Overview of Distributed Call Chain Tracing](dfx/hitracechain-overview.md) - [Overview of Distributed Call Chain Tracing](dfx/hitracechain-overview.md)
- [Development of Distributed Call Chain Tracing](dfx/hitracechain-guidelines.md) - [Development of Distributed Call Chain Tracing](dfx/hitracechain-guidelines.md)
- Tools - Tools
- DevEco Studio (OpenHarmony) User Guide - [DevEco Studio (OpenHarmony) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md)
- [Overview](quick-start/deveco-studio-overview.md)
- [Version Change History](quick-start/deveco-studio-release-notes.md)
- [Configuring the OpenHarmony SDK](quick-start/configuring-openharmony-sdk.md)
- [Creating an OpenHarmony Project](quick-start/create-openharmony-project.md)
- [Configuring the OpenHarmony App Signature](quick-start/configuring-openharmony-app-signature.md)
- [Installing and Running Your OpenHarmony App](quick-start/installing-openharmony-app.md)
- Hands-On Tutorials - Hands-On Tutorials
- [Samples](https://gitee.com/openharmony/app_samples/blob/master/README.md) - [Samples](https://gitee.com/openharmony/app_samples/blob/master/README.md)
- API References - API References
......
# Basics # Basics
- [DevEco Studio \(OpenHarmony\) User Guide](deveco-studio-user-guide-for-openharmony.md) - Development Fundamentals
- [Overview](deveco-studio-overview.md) - [Directory Structure](package-structure.md)
- [Version Change History](deveco-studio-release-notes.md) - [Resource File](basic-resource-file-categories.md)
- [Configuring the OpenHarmony SDK](configuring-openharmony-sdk.md)
- [Creating an OpenHarmony Project](create-openharmony-project.md)
- [Using the Project Wizard to Create a Project](use-wizard-to-create-project.md)
- [Importing a Sample to Create a Project](import-sample-to-create-project.md)
- [Configuring the OpenHarmony App Signature](configuring-openharmony-app-signature.md)
- [Installing and Running Your OpenHarmony App](installing-openharmony-app.md)
- [Directory Structure](package-structure.md)
# Configuring the OpenHarmony App Signature<a name="EN-US_TOPIC_0000001159890371"></a>
- [Generating a Key Store and CSR](#section153146467405)
- [In DevEco Studio](#section1298903211472)
- [In a Command-Line Tool](#section1276462024811)
- [Generating an App Certificate](#section136609429562)
- [Generating the App Profile](#section2048641015325)
- [Configuring App Signature Information](#section10152423193310)
Before running and debugging the OpenHarmony app on a real device, you need to sign the app. This section describes how to configure the signature of an OpenHarmony app. Operation instructions are the same in _HUAWEI DevEco Studio User Guide_ except this section. For details, see [HUAWEI DevEco Studio User Guide](https://developer.harmonyos.com/en/docs/documentation/doc-guides/tools_overview-0000001053582387). See the following figure for the process of configuring app signature information.
![](figures/en-us_image_0000001113808114.png)
## Generating a Key Store and CSR<a name="section153146467405"></a>
OpenHarmony uses digital certificates \(.cer\) and **Profile** files \(.p7b\) to ensure app integrity. Before applying for these files, you need to generate a key store \(.p12\) and a certificate signing request \(.csr\). You can do so in DevEco Studio or a command-line tool.
### In DevEco Studio<a name="section1298903211472"></a>
1. On the menu bar, choose **Build** \> **Generate Key and CSR**.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>If you have a local key, click **Skip** in the **Generate Key** window and use the key to generate a CSR file.
2. In **Key Store File**, click **Choose Existing** to select an existing key store \(.p12 file that contains a key\) or **New** to create one. The following describes how to create a key store.
![](figures/en-us_image_0000001119560738.png)
3. In the **Create Key Store** dialog box, set the following parameters and click **OK**.
- **Key Store File**: Select the path for storing the key store.
- **Password**: Set the key store password, which must contain at least 8 characters that include two types of the following: uppercase letters, lowercase letters, digits, and special characters. Do not lose the password as it will be used later in configuring the signature.
- **Confirm Password**: Enter the key store password again.
![](figures/en-us_image_0000001152674854.png)
4. In the **Generate Key** window, set the following parameters and click **Next**.
- **Alias**: Enter the alias of the key, which is used to identify the key name. Do not lose the alias as it will be used later in configuring the signature.
- **Password**: password of the key, which is automatically filled in and the same as the keystore password.
- **Validity**: Specify the certificate validity period. A validity period of 25 years or longer is recommended to cover the entire lifecycle of your app/service.
- **Certificate**: Enter basic certificate information.
![](figures/en-us_image_0000001117639668.png)
5. In the **Generate CSR** window, select the key and set the storage path of the CSR file.
![](figures/en-us_image_0000001117479776.png)
6. Click **OK**. You can then obtain the generated keystore file \(.p12\) and CSR file \(.csr\) from the storage path.
![](figures/en-us_image_0000001163839541.png)
### In a Command-Line Tool<a name="section1276462024811"></a>
Use the Keytool in the Open JDK to generate a CSR.
1. Run the Keytool as an administrator.
![](figures/en-us_image_0000001248045243.png)
2. Switch to the directory where the Keytool is located.
![](figures/en-us_image_0000001247125297.png)
3. Run the following command to generate a key store. This example creates a key store named **ide\_demo\_app.p12** and saves it to the root directory of the D drive.
```
keytool -genkeypair -alias "ide_demo_app" -keyalg EC -sigalg SHA256withECDSA -dname "C=CN,O=Organization,OU=Unit,CN=ide_demo_app" -keystore d:\\idedemokey.p12 -storetype pkcs12 -validity 9125 -storepass 123456Abc -keypass 123456Abc
```
Parameters in the key store:
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>Record the values of **alias**, **storepass**, and **keypass**, which will be used in [Configuring App Signature Information](#section10152423193310).
- **alias**: alias of the key, which is used to identify the key name.
- **sigalg**: signature algorithm, which is automatically set to **SHA256withECDSA** and cannot be changed.
- **dname**:
- **C**: country/region code, such as **CN**.
- **O**: organization name, such as **Organization**.
- **OU**: organization unit name, such as **Unit**.
- **CN**: your first name and last name. Set this parameter to be the same as **alias**.
- **validity**: certificate validity period. It is recommended that you set this parameter to **9125** \(25 years\).
- **storepass**: key store password, which must contain at least 8 characters that include two types of the following: uppercase letters, lowercase letters, digits, and special characters. Do not lose the password as it will be used later in configuring the signature.
- **keypass**: password of the key. The value must be the same as that of **storepass**.
4. Run the following command. After the command is executed, enter the **storepass** to generate a CSR in .csr format.
```
keytool -certreq -alias "ide_demo_app" -keystore d:\\idedemokey.p12 -storetype pkcs12 -file d:\\idedemokey.csr
```
Parameters in the CSR:
- **alias**: The value must be the same as the alias set in 3.
- **file**: name of the generated CSR. The file name extension is .csr.
## Generating an App Certificate<a name="section136609429562"></a>
Use the CSR generated in [Generating a Key Store and CSR](#section153146467405) to generate the digital certificate required for app signing. The method is as follows:
Go to the **Sdk\\toolchains\\lib** directory where the OpenHarmony SDK is saved \(see [Configuring the OpenHarmony SDK](configuring-openharmony-sdk.md) for details\) in the DevEco Studio installation directory, and run the following command in the CLI. If the **keytool** command cannot be executed, add the JDK environment variables to the system environment variables. You only need to modify the input and output to quickly generate a certificate. That is, modify **-infile** to specify the path of the CSR and **-outfile** to specify the name and path of the output certificate.
```
keytool -gencert -alias "OpenHarmony Application CA" -infile myApplication_ohos.csr -outfile myApplication_ohos.cer -keystore OpenHarmony.p12 -sigalg SHA384withECDSA -storepass 123456 -ext KeyUsage:"critical=digitalSignature" -validity 3650 -rfc
```
Refer to the following descriptions about the parameters in the command:
- **alias**: alias of the CA private key used for issuing certificates. The CA private key of the OpenHarmony community is stored in the **OpenHarmony.p12** key store file. This parameter cannot be modified.
- **infile**: path of the CSR file.
- **outfile**: name and path of the certificate chain file.
- **keystore**: path of the CA key store for issuing certificates. The name of the OpenHarmony key store file is **OpenHarmony.p12**. The file is stored in **Sdk\\toolchains\\lib** of the OpenHarmony SDK. This parameter cannot be modified. Note that the **OpenHarmony.p12** file is not the .p12 file generated in [Generating a Key Store and CSR](#section153146467405).
- **sigalg**: certificate signature algorithm. This parameter cannot be modified.
- **storepass**: key store password. The password is **123456** and cannot be changed.
- **ext**: certificate extension. This parameter cannot be modified.
- **validity**: certificate validity period, which is user-defined.
- **rfc**: specifies the output file format. This parameter cannot be modified.
## Generating the App Profile<a name="section2048641015325"></a>
The profile contains the following information about the OpenHarmony app: bundle name, digital certificate information, certificate permissions that can be applied for by the app, and devices where the app can be debugged \(the device list will be empty if the app type is Release\). Each app package must contain a profile file.
Go to the **Sdk\\toolchains\\lib** directory, open the command-line tool, and run the following command.
```
java -jar provisionsigtool.jar sign --in UnsgnedReleasedProfileTemplate.json --out myApplication_ohos_Provision.p7b --keystore OpenHarmony.p12 --storepass 123456 --alias "OpenHarmony Application Profile Release" --sigAlg SHA256withECDSA --cert OpenHarmonyProfileRelease.pem --validity 365 --developer-id ohosdeveloper --bundle-name app bundle name --permission restricted permission name (optional) --permission restricted permission name (optional) --distribution-certificate myApplication_ohos.cer
```
Refer to the following descriptions about the parameters in the command:
- **provisionsigtool**: tool for generating the profile which is stored in **Sdk\\toolchains\\lib** of the OpenHarmony SDK.
- **in**: path of the profile template which is stored in **Sdk\\toolchains\\lib** of the OpenHarmony SDK. This parameter cannot be modified.
- **out**: name and path of the profile.
- **keystore**: path of the key store for issuing certificates. The name of the OpenHarmony key store file is **OpenHarmony.p12**. The file is stored in **Sdk\\toolchains\\lib** of the OpenHarmony SDK. This parameter cannot be modified.
- **storepass**: key store password. The password is **123456** and cannot be changed.
- **alias**: alias of the private key used for app signing. The CA private key of the OpenHarmony community is stored in the **OpenHarmony.p12** key store file. This parameter cannot be modified.
- **sigalg**: certificate signature algorithm. This parameter cannot be modified.
- **cert**: path of the certificate of the signature profile. The file is stored in **Sdk\\toolchains\\lib** of the OpenHarmony SDK. This parameter cannot be modified.
- **validity**: certificate validity period, which is user-defined.
- **developer-id**: developer ID, which is a user-defined character string.
- **bundle-name**: app bundle name.
- **permission** \(optional\): If permissions are not required, this field can be left empty. You can add multiple restricted permissions in the following way: ohos.permission.READ\_CONTACTS, ohos.permission.WRITE\_CONTACTS.
- **distribution-certificate**: certificate generated in [Generating an App Certificate](#section136609429562).
## Configuring App Signature Information<a name="section10152423193310"></a>
Before debugging on a real device, use the private key file \(.p12\), certificate file \(.cer\), and profile file \(.p7b\) to sign the target module.
Go to **File** \> **Project Structure** \> **Project** \> **Signing Configs** \> **debug**, deselect **Automatically generate signing**, and configure the signature information of the specified module.
- **Store File**: Select the key store file with the file name extension .p12, which is generated in [Generating a Key Store and CSR](#section153146467405).
- **Store Password**: Enter the key store password, which is the same as the key store password entered in [Generating a Key Store and CSR](#section153146467405).
- **Key Alias**: Enter the alias of the key, which is the same as the alias entered in [Generating a Key Store and CSR](#section153146467405).
- **Key Password**: Enter the key password, which is the same as the value of **Store Password**.
- **Sign Alg**: Specify the signature algorithm, which has a fixed value of **SHA256withECDSA**.
- **Profile File**: Select the .p7b profile file generated in [Generating the App Profile](#section2048641015325).
- **Certpath File**: Select the .cer debug certificate generated in [Generating an App Certificate](#section136609429562).
![](figures/en-us_image_0000001155643492.png)
Click **OK** to save your configurations. Then you can view the signature configuration information in **build.gradle** of the project.
![](figures/en-us_image_0000001202722349.png)
By default, the type of a HAP package compiled using DevEco Studio is set to **debug**. For a release type, click the **OhosBuild Variants** tab in the lower left corner of the project and set the type to **release**. For details about how to compile and build the HAP, see [HUAWEI DevEco Studio User Guide](https://developer.harmonyos.com/en/docs/documentation/doc-guides/build_hap-0000001053342418).
![](figures/en-us_image_0000001115066116.png)
After the compilation is complete, you can obtain the HAP package of your OpenHarmony app from the **build** directory of the project.
![](figures/en-us_image_0000001163918627.png)
# Configuring the OpenHarmony SDK<a name="EN-US_TOPIC_0000001113561194"></a>
- [Prerequisites](#section164161442154812)
- [Configuring the SDK Information](#section1265592425017)
- [References](#section0384143616409)
- [Setting Up the DevEco Studio Proxy](#section10129720184214)
- [Setting Up the npm Proxy](#section19984059114316)
- [Setting Up the Gradle Proxy](#section164211820465)
To set up the OpenHarmony app development environment, configure the corresponding SDK information in DevEco Studio first.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>The OpenHarmony SDK is not applicable to HarmonyOS app development, with some necessary toolchains removed.
## Prerequisites<a name="section164161442154812"></a>
[DevEco Studio 3.0 Beta1](https://developer.harmonyos.com/cn/develop/deveco-studio#download) or later has been downloaded and installed.
## Configuring the SDK Information<a name="section1265592425017"></a>
DevEco Studio manages SDKs and toolchains using SDK Manager. OpenHarmony contains the following SDK packages:
<a name="table64565810577"></a>
<table><thead align="left"><tr id="row12455580576"><th class="cellrowborder" valign="top" width="24.709999999999997%" id="mcps1.1.4.1.1"><p id="p34565812572"><a name="p34565812572"></a><a name="p34565812572"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="25.3%" id="mcps1.1.4.1.2"><p id="p104675817575"><a name="p104675817575"></a><a name="p104675817575"></a>Package Name</p>
</th>
<th class="cellrowborder" valign="top" width="49.99%" id="mcps1.1.4.1.3"><p id="p194610586574"><a name="p194610586574"></a><a name="p194610586574"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row44334409916"><td class="cellrowborder" rowspan="2" valign="top" width="24.709999999999997%" headers="mcps1.1.4.1.1 "><p id="p88381448125813"><a name="p88381448125813"></a><a name="p88381448125813"></a>SDK</p>
</td>
<td class="cellrowborder" valign="top" width="25.3%" headers="mcps1.1.4.1.2 "><p id="p1946175813574"><a name="p1946175813574"></a><a name="p1946175813574"></a>JS</p>
</td>
<td class="cellrowborder" valign="top" width="49.99%" headers="mcps1.1.4.1.3 "><p id="p54625885713"><a name="p54625885713"></a><a name="p54625885713"></a>SDK for JS.</p>
</td>
</tr>
<tr id="row12199716103617"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p9200131683616"><a name="p9200131683616"></a><a name="p9200131683616"></a>eTS</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p523912359172"><a name="p523912359172"></a><a name="p523912359172"></a>SDK for Extended TypeScript (eTS).</p>
</td>
</tr>
<tr id="row14474585576"><td class="cellrowborder" rowspan="2" valign="top" width="24.709999999999997%" headers="mcps1.1.4.1.1 "><p id="p124765819578"><a name="p124765819578"></a><a name="p124765819578"></a>SDK Tool</p>
</td>
<td class="cellrowborder" valign="top" width="25.3%" headers="mcps1.1.4.1.2 "><p id="p1947135818571"><a name="p1947135818571"></a><a name="p1947135818571"></a>Toolchains</p>
</td>
<td class="cellrowborder" valign="top" width="49.99%" headers="mcps1.1.4.1.3 "><p id="p7471158105711"><a name="p7471158105711"></a><a name="p7471158105711"></a>Includes compiling, packaging, signing, database management, and other tools that are required to develop OpenHarmony apps.</p>
</td>
</tr>
<tr id="row337931010"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p193791108"><a name="p193791108"></a><a name="p193791108"></a>Previewer</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1238951018"><a name="p1238951018"></a><a name="p1238951018"></a>OpenHarmony app previewer, which can be used to view the UI layout during app development.</p>
</td>
</tr>
</tbody>
</table>
1. Open DevEco Studio. If this is the first time you are using it, select **Do not import settings** and click **OK**.
2. Follow the wizard to set **npm registry**. DevEco Studio has been preconfigured with the corresponding registry. Click **Start using DevEco Studio** to go to the next step.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>If the **Set up HTTP Proxy** page is displayed, it indicates that your network requires a proxy. In this case, set up the DevEco Studio proxy, npm proxy, and Gradle proxy according to [References](#section0384143616409), and then download the OpenHarmony SDK.
![](figures/en-us_image_0000001163314102.png)
3. Follow the wizard to download the SDK. By default, the OpenHarmony SDK will be downloaded. You can download the SDK to the default **user** directory or a local path that does not contain any Chinese characters. Then click **Next**.
![](figures/en-us_image_0000001208394019.png)
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>If you are not using DevEco Studio for the first time, the SDK download page may not be displayed. In this case, go to **Configure** \(or ![](figures/en-us_image_0000001208274069.png)\) \> **Settings** \> **SDK Manager** \> **OpenHarmony SDK** and click **OpenHarmony SDK Location** to download the SDK.
4. On the **Settings Confirmation** page, click **Next**. When the **License Agreement** dialog box appears, click **Accept**.
![](figures/en-us_image_0000001163472654.png)
5. After the OpenHarmony SDK and tools are downloaded, click **Finish** to access the DevEco Studio welcome page.
![](figures/en-us_image_0000001163632602.png)
## References<a name="section0384143616409"></a>
Setting up the development environment requires that your network can directly access the Internet.
Generally, only some enterprise networks rather than personal area networks or home networks require a proxy to access the Internet.
If you are using DevEco Studio for the first time and the **Set up HTTP Proxy** page is displayed, it indicates that your network requires a proxy. In this case, set up the DevEco Studio proxy, npm proxy, and Gradle proxy.
![](figures/en-us_image_0000001166582138.png)
### Setting Up the DevEco Studio Proxy<a name="section10129720184214"></a>
1. Start DevEco Studio. On the **Set up HTTP Proxy** page that is displayed, select **Manual proxy configuration** and set the HTTP proxy.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>If this is not the first time you are using DevEco Studio:
>- On the welcome page, choose **Configure** \(or ![](figures/en-us_image_0000001212142015.png)\)** \> Settings \> Appearance & Behavior \> System Settings \> HTTP Proxy** to access the HTTP Proxy settings. \(For macOS, choose **Configure \> Preferences \> Appearance & Behavior \> System Settings \> HTTP Proxy**.\)
>- When on a project page, choose **File \> Settings \> Appearance & Behavior \> System Settings \> HTTP Proxy** to access the HTTP Proxy settings. \(For macOS, choose **DevEco Studio \> Preferences \> Appearance & Behavior \> System Settings \> HTTP Proxy**.\)
- **HTTP** parameters: **If you are not sure about the information, contact your network administrator.**
- **Host name**: Enter the host name or IP address of the proxy server.
- **Port number**: Enter the port number of the proxy server.
- **No proxy for**: Enter the URLs or IP addresses which the PC can directly connect to without a proxy server. Use commas \(,\) to separate URLs and IP addresses.
- **Proxy authentication** parameters: Set the parameters only when the proxy server requires authentication.
- **Login**: Enter the user name used to access the proxy server.
- **Password**: Enter the password used to access the proxy server.
- **Remember**: Select this option to remember the password.
![](figures/en-us_image_0000001212062065.png)
2. When you have finished, click **Check connection** and enter a URL to check the network connectivity. If the message "Connection successful" is displayed, it indicates that the proxy was set up successfully.
3. Click **Next: Configure npm** to set up the npm proxy. For details, see [Setting Up the npm Proxy](#section19984059114316).
### Setting Up the npm Proxy<a name="section19984059114316"></a>
Follow the configuration wizard of DevEco Studio to configure the npm proxy information, which will be written into the **.npmrc** file in the **users/**_user name_ directory.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>The configuration wizard is displayed only the first time you install DevEco Studio. If the wizard is not displayed, manually add the proxy information to the **.npmrc** file in the **users/**_user name_ directory.
- **npm registry**: Set the address of the npm registry. You are advised to select this option.
- **HTTP proxy**: Proxy server information. By default, the value is the same as that of **HTTP proxy** of DevEco Studio.
- **Enable Https Proxy**: Indicates whether to configure HTTPS proxy. You are advised to select this option.
![](figures/en-us_image_0000001164577336.png)
Click **Start using DevEco Studio**.
If your proxy server requires the user name and password for authentication, set the user name and password as follows. If your proxy server does not require authentication, skip this step and follow the instructions in [Configuring the SDK Information](#section1265592425017).
![](figures/en-us_image_0000001209817299.png)
1. Go to the **Users** directory and open the **.npmrc** file.
2. Modify the npm proxy information. Add the **user** and **password** fields to **proxy** and **https-proxy**. Note that the values may vary depending on the proxy. The following is an example:
```
proxy=http://user:password@proxy.server.com:80
https-proxy=http://user:password@proxy.server.com:80
```
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>If the password contains special characters, such as @, \#, and \*, the configuration may not take effect. You are advised to replace the special characters with ASCII codes and add "%" before the ASCII codes. Refer to the following for the mapping between common symbols and ASCII codes.
>- !: %21
>- @: %40
>- \#: %23
>- ¥: %24
>- &: %26
>- \*: %2A
3. After the proxy is configured, open the CLI and run the following command to check whether the network is normal.
```
npm info express
```
If the following information is displayed after running the command, it indicates that the proxy has been set up successfully.
![](figures/en-us_image_0000001164417356.png)
4. When you are done, follow the instructions in [Configuring the SDK Information](#section1265592425017).
### Setting Up the Gradle Proxy<a name="section164211820465"></a>
1. Open **This PC**, and enter **%userprofile%** in the address box to access the user profile. \(For macOS, choose **Go** \> **Home**.\)
![](figures/en-us_image_0000001166740700.png)
2. Create a **.gradle** folder if there is none.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>Before creating a **.gradle** folder in macOS, set the system to show hidden files.
3. Open the **.gradle** folder, create a **gradle** file, and change the file name extension to .properties.
4. Add the following script to the **gradle.properties** file and save the file:
Modify the host name, port number, user name, password, and proxy exceptions \(**nonProxyHosts**\) based on the actual condition. Separate values for **nonProxyHosts** with a vertical bar \(|\).
```
systemProp.http.proxyHost=proxy.server.com
systemProp.http.proxyPort=8080
systemProp.http.nonProxyHosts=*.company.com|10.*|100.*
systemProp.http.proxyUser=userId
systemProp.http.proxyPassword=password
systemProp.https.proxyHost=proxy.server.com
systemProp.https.proxyPort=8080
systemProp.https.nonProxyHosts=*.company.com|10.*|100.*
systemProp.https.proxyUser=userId
systemProp.https.proxyPassword=password
```
# Creating an OpenHarmony Project<a name="EN-US_TOPIC_0000001130929834"></a>
- **[Using the Project Wizard to Create a Project](use-wizard-to-create-project.md)**
- **[Importing a Sample to Create a Project](import-sample-to-create-project.md)**
# Overview<a name="EN-US_TOPIC_0000001116414108"></a>
- [About the Document](#section189422248491)
- [Restrictions](#section65191625782)
- [DevEco Studio Evolution Roadmap](#section187875207166)
## About the Document<a name="section189422248491"></a>
DevEco Studio is an integrated development environment \(IDE\) of HarmonyOS apps. As HarmonyOS is developed based on OpenHarmony, DevEco Studio can also be used to develop OpenHarmony apps.
The process of developing an OpenHarmony app using DevEco Studio is the same as that of developing a HarmonyOS app. This document describes the differences between OpenHarmony and HarmonyOS app development.
- **Environment setup**: You need to manually install the OpenHarmony SDK for the OpenHarmony app development. For details, see [Configuring the OpenHarmony SDK](configuring-openharmony-sdk.md).
- **Creating an OpenHarmony project**: Create a project by using the project wizard or by importing a sample project. For details, see [Using the Project Wizard to Create a Project](use-wizard-to-create-project.md).
- **Signature configuration for debugging**: To run an OpenHarmony app on a real device, you need to sign the app first. For instructions, see [Configuring the OpenHarmony App Signature](configuring-openharmony-app-signature.md).
- **App running on a real device**: Push the OpenHarmony HAP package to the real device for installation. For details, see [Installing and Running Your OpenHarmony App](installing-openharmony-app.md).
For details about how to use DevEco Studio, see [HUAWEI DevEco Studio User Guide](https://developer.harmonyos.com/en/docs/documentation/doc-guides/tools_overview-0000001053582387).
## Restrictions<a name="section65191625782"></a>
- OpenHarmony supports only app development in eTS and JS.
- Developing OpenHarmony apps in DevEco Studio is supported on Windows.
DevEco Studio serves as a development tool for both OpenHarmony and HarmonyOS apps. Refer to the following table for descriptions about the functions not supported for OpenHarmony.
<a name="table852516933419"></a>
<table><thead align="left"><tr id="row1952618913415"><th class="cellrowborder" valign="top" width="29.882988298829883%" id="mcps1.1.4.1.1"><p id="p165268963418"><a name="p165268963418"></a><a name="p165268963418"></a>Feature</p>
</th>
<th class="cellrowborder" valign="top" width="36.783678367836785%" id="mcps1.1.4.1.2"><p id="p25262914349"><a name="p25262914349"></a><a name="p25262914349"></a>HarmonyOS</p>
</th>
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.1.4.1.3"><p id="p125265912343"><a name="p125265912343"></a><a name="p125265912343"></a>OpenHarmony</p>
</th>
</tr>
</thead>
<tbody><tr id="row955132319355"><td class="cellrowborder" valign="top" width="29.882988298829883%" headers="mcps1.1.4.1.1 "><p id="p1655172423517"><a name="p1655172423517"></a><a name="p1655172423517"></a>Service widgets</p>
</td>
<td class="cellrowborder" valign="top" width="36.783678367836785%" headers="mcps1.1.4.1.2 "><p id="p1555192493516"><a name="p1555192493516"></a><a name="p1555192493516"></a><strong id="b11551102403511"><a name="b11551102403511"></a><a name="b11551102403511"></a></strong></p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p85511324183514"><a name="p85511324183514"></a><a name="p85511324183514"></a><strong id="b255116244356"><a name="b255116244356"></a><a name="b255116244356"></a>X</strong></p>
</td>
</tr>
<tr id="row1552619933411"><td class="cellrowborder" valign="top" width="29.882988298829883%" headers="mcps1.1.4.1.1 "><p id="p11430122863614"><a name="p11430122863614"></a><a name="p11430122863614"></a>Automatic signing</p>
</td>
<td class="cellrowborder" valign="top" width="36.783678367836785%" headers="mcps1.1.4.1.2 "><p id="p243122863614"><a name="p243122863614"></a><a name="p243122863614"></a><strong id="b14431122873617"><a name="b14431122873617"></a><a name="b14431122873617"></a></strong></p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p4431162819362"><a name="p4431162819362"></a><a name="p4431162819362"></a><strong id="b4431328163619"><a name="b4431328163619"></a><a name="b4431328163619"></a>X</strong></p>
</td>
</tr>
<tr id="row115263913344"><td class="cellrowborder" valign="top" width="29.882988298829883%" headers="mcps1.1.4.1.1 "><p id="p1323118352362"><a name="p1323118352362"></a><a name="p1323118352362"></a>Remote emulator</p>
</td>
<td class="cellrowborder" valign="top" width="36.783678367836785%" headers="mcps1.1.4.1.2 "><p id="p723143573614"><a name="p723143573614"></a><a name="p723143573614"></a><strong id="b8231173533613"><a name="b8231173533613"></a><a name="b8231173533613"></a></strong></p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p7231435143619"><a name="p7231435143619"></a><a name="p7231435143619"></a><strong id="b1523111352363"><a name="b1523111352363"></a><a name="b1523111352363"></a>X</strong></p>
</td>
</tr>
<tr id="row183441037105115"><td class="cellrowborder" valign="top" width="29.882988298829883%" headers="mcps1.1.4.1.1 "><p id="p5345237155119"><a name="p5345237155119"></a><a name="p5345237155119"></a>Local emulator</p>
</td>
<td class="cellrowborder" valign="top" width="36.783678367836785%" headers="mcps1.1.4.1.2 "><p id="p393214320517"><a name="p393214320517"></a><a name="p393214320517"></a><strong id="b1693264315118"><a name="b1693264315118"></a><a name="b1693264315118"></a></strong></p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p139324438515"><a name="p139324438515"></a><a name="p139324438515"></a><strong id="b169321543175116"><a name="b169321543175116"></a><a name="b169321543175116"></a>X</strong></p>
</td>
</tr>
<tr id="row15269933419"><td class="cellrowborder" valign="top" width="29.882988298829883%" headers="mcps1.1.4.1.1 "><p id="p152318351369"><a name="p152318351369"></a><a name="p152318351369"></a>Using DevEco Studio for log viewing and optimization</p>
</td>
<td class="cellrowborder" valign="top" width="36.783678367836785%" headers="mcps1.1.4.1.2 "><p id="p623118353360"><a name="p623118353360"></a><a name="p623118353360"></a><strong id="b10231535143615"><a name="b10231535143615"></a><a name="b10231535143615"></a></strong></p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p192313353367"><a name="p192313353367"></a><a name="p192313353367"></a><strong id="b1423123514368"><a name="b1423123514368"></a><a name="b1423123514368"></a>X</strong></p>
</td>
</tr>
<tr id="row7357734143617"><td class="cellrowborder" valign="top" width="29.882988298829883%" headers="mcps1.1.4.1.1 "><p id="p76694468363"><a name="p76694468363"></a><a name="p76694468363"></a>Cloud testing</p>
</td>
<td class="cellrowborder" valign="top" width="36.783678367836785%" headers="mcps1.1.4.1.2 "><p id="p2066918465369"><a name="p2066918465369"></a><a name="p2066918465369"></a><strong id="b3669546133610"><a name="b3669546133610"></a><a name="b3669546133610"></a></strong></p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p1266910467363"><a name="p1266910467363"></a><a name="p1266910467363"></a><strong id="b11669144693616"><a name="b11669144693616"></a><a name="b11669144693616"></a>X</strong></p>
</td>
</tr>
<tr id="row124331939191517"><td class="cellrowborder" valign="top" width="29.882988298829883%" headers="mcps1.1.4.1.1 "><p id="p146691546143619"><a name="p146691546143619"></a><a name="p146691546143619"></a>Security testing</p>
</td>
<td class="cellrowborder" valign="top" width="36.783678367836785%" headers="mcps1.1.4.1.2 "><p id="p614815145371"><a name="p614815145371"></a><a name="p614815145371"></a><strong id="b101485149375"><a name="b101485149375"></a><a name="b101485149375"></a></strong></p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p1514811149374"><a name="p1514811149374"></a><a name="p1514811149374"></a><strong id="b01481614133717"><a name="b01481614133717"></a><a name="b01481614133717"></a>X</strong></p>
</td>
</tr>
</tbody>
</table>
## DevEco Studio Evolution Roadmap<a name="section187875207166"></a>
Refer to the following figure for when the HUAWEI DevEco Studio support for OpenHarmony app development is available in different phases.
![](figures/en-us_image_0000001210018359.png)
# Version Change History<a name="EN-US_TOPIC_0000001210143219"></a>
- [V3.0 Beta2 \(2021-12-31\)](#section18825185716537)
- [Version Compatibility](#section8155205312218)
- [Version Change History](#section1655415918226)
- [V3.0 Beta1 \(2021-09-29\)](#section21092033115018)
## V3.0 Beta2 \(2021-12-31\)<a name="section18825185716537"></a>
### Version Compatibility<a name="section8155205312218"></a>
DevEco Studio 3.0 Beta2 is compatible with the module versions listed below.
<a name="table912419211138"></a>
<table><thead align="left"><tr id="row141241921231"><th class="cellrowborder" valign="top" width="31.009999999999998%" id="mcps1.1.4.1.1"><p id="p1112432111316"><a name="p1112432111316"></a><a name="p1112432111316"></a>Module</p>
</th>
<th class="cellrowborder" valign="top" width="36.02%" id="mcps1.1.4.1.2"><p id="p111241921039"><a name="p111241921039"></a><a name="p111241921039"></a>Version</p>
</th>
<th class="cellrowborder" valign="top" width="32.97%" id="mcps1.1.4.1.3"><p id="p863410439478"><a name="p863410439478"></a><a name="p863410439478"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row14124221933"><td class="cellrowborder" valign="top" width="31.009999999999998%" headers="mcps1.1.4.1.1 "><p id="p17124172110319"><a name="p17124172110319"></a><a name="p17124172110319"></a>Gradle</p>
</td>
<td class="cellrowborder" valign="top" width="36.02%" headers="mcps1.1.4.1.2 "><p id="p101251821838"><a name="p101251821838"></a><a name="p101251821838"></a>7.3 (7.2 at minimum)</p>
</td>
<td class="cellrowborder" valign="top" width="32.97%" headers="mcps1.1.4.1.3 "><p id="p0634643124719"><a name="p0634643124719"></a><a name="p0634643124719"></a>DevEco Studio has Gradle 7.3 preinstalled. No separate installation is required.</p>
</td>
</tr>
<tr id="row1125172118320"><td class="cellrowborder" valign="top" width="31.009999999999998%" headers="mcps1.1.4.1.1 "><p id="p358213219512"><a name="p358213219512"></a><a name="p358213219512"></a>JDK</p>
</td>
<td class="cellrowborder" valign="top" width="36.02%" headers="mcps1.1.4.1.2 "><p id="p1412552119316"><a name="p1412552119316"></a><a name="p1412552119316"></a>11.0.x</p>
</td>
<td class="cellrowborder" valign="top" width="32.97%" headers="mcps1.1.4.1.3 "><p id="p76347438478"><a name="p76347438478"></a><a name="p76347438478"></a>DevEco Studio has JDK 11 preinstalled. No separate installation is required.</p>
</td>
</tr>
<tr id="row712518211231"><td class="cellrowborder" valign="top" width="31.009999999999998%" headers="mcps1.1.4.1.1 "><p id="p61257211232"><a name="p61257211232"></a><a name="p61257211232"></a>OpenHarmony SDK</p>
</td>
<td class="cellrowborder" valign="top" width="36.02%" headers="mcps1.1.4.1.2 "><p id="p141258211631"><a name="p141258211631"></a><a name="p141258211631"></a>3.1.0.0 (API Version 8 Beta)</p>
</td>
<td class="cellrowborder" valign="top" width="32.97%" headers="mcps1.1.4.1.3 "><p id="p363464312479"><a name="p363464312479"></a><a name="p363464312479"></a>This version is compatible with SDKs of earlier versions.</p>
</td>
</tr>
<tr id="row148771316264"><td class="cellrowborder" valign="top" width="31.009999999999998%" headers="mcps1.1.4.1.1 "><p id="p16276131516263"><a name="p16276131516263"></a><a name="p16276131516263"></a>Toolchinas</p>
</td>
<td class="cellrowborder" valign="top" width="36.02%" headers="mcps1.1.4.1.2 "><p id="p887713152611"><a name="p887713152611"></a><a name="p887713152611"></a>3.1.0.0</p>
</td>
<td class="cellrowborder" rowspan="3" valign="top" width="32.97%" headers="mcps1.1.4.1.3 "><p id="p14933418194918"><a name="p14933418194918"></a><a name="p14933418194918"></a>Update them to the latest version.</p>
</td>
</tr>
<tr id="row1792520182520"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p109251518258"><a name="p109251518258"></a><a name="p109251518258"></a>hap plug-in</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p14925111817513"><a name="p14925111817513"></a><a name="p14925111817513"></a>3.0.5.2</p>
</td>
</tr>
<tr id="row29251718254"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p109255186518"><a name="p109255186518"></a><a name="p109255186518"></a>decctest plug-in</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p15925121819513"><a name="p15925121819513"></a><a name="p15925121819513"></a>1.2.7.2</p>
</td>
</tr>
</tbody>
</table>
### Version Change History<a name="section1655415918226"></a>
<a name="simpletable154972061571"></a>
<table id="simpletable154972061571"><tr id="strow04971366576"><td valign="top" id="stentry164971967578"><p id="p949718615570"><a name="p949718615570"></a><a name="p949718615570"></a><strong id="b3206161751212"><a name="b3206161751212"></a><a name="b3206161751212"></a>New Features</strong></p>
<a name="ul1978261655712"></a><a name="ul1978261655712"></a><ul id="ul1978261655712"><li>Introduced the Chinese UI. By default, the UI is displayed in English. To enable the Chinese UI, go to <strong id="b121121320121217"><a name="b121121320121217"></a><a name="b121121320121217"></a>Settings</strong>, choose <strong id="b7112102015129"><a name="b7112102015129"></a><a name="b7112102015129"></a>Plugins</strong> &gt; <strong id="b5112152017128"><a name="b5112152017128"></a><a name="b5112152017128"></a>installed</strong>, and select <strong id="b9113182071210"><a name="b9113182071210"></a><a name="b9113182071210"></a>Chinese (Simplified)</strong>. Then, restart DevEco Studio for the settings to take effect.</li><li>Introduced support for OpenHarmony apps and services, with various debugging features, from breakpoint management and variable observation to stepping.</li></ul>
<p id="p49051145125817"><a name="p49051145125817"></a><a name="p49051145125817"></a></p>
<p id="p7511347135817"><a name="p7511347135817"></a><a name="p7511347135817"></a><strong id="b6867529171215"><a name="b6867529171215"></a><a name="b6867529171215"></a>Enhanced Features</strong></p>
<a name="ul311913348114"></a><a name="ul311913348114"></a><ul id="ul311913348114"><li>Updated the OpenHarmony SDK to 3.1.0.0, whose API version is API 8 Beta and corresponding compilation and building plugin is 3.0.5.2.</li><li>Added an ability template that supports low-code development: <strong id="b736929122019"><a name="b736929122019"></a><a name="b736929122019"></a>[Standard]Empty Ability</strong>.</li><li>Added eTS component preview: allows previewing of eTS components; requires compileSdkVersion 8 or later.</li><li>Added eTS livee preview: allows viewing of the attribute changes in real time as you make them; requires compileSdkVersion 8 or later.</li></ul>
</td>
</tr>
</table>
## V3.0 Beta1 \(2021-09-29\)<a name="section21092033115018"></a>
<a name="simpletable19435134375015"></a>
<table id="simpletable19435134375015"><tr id="strow1435543185020"><td valign="top" id="stentry64351943115013"><div class="p" id="p13974162220455"><a name="p13974162220455"></a><a name="p13974162220455"></a><strong id="b0838112318282"><a name="b0838112318282"></a><a name="b0838112318282"></a>New Features</strong><a name="ul11381034104515"></a><a name="ul11381034104515"></a><ul id="ul11381034104515"><li>Added support for OpenHarmony SDK management. You can use SDK Manager to download and manage OpenHarmony SDKs.</li><li>Allowed for building of a single module during HAP compilation and building to accelerate building for multi-module projects; allowed for one-click re-building of HAPs, by automatically conducting the Clean Project operation before a HAP build.</li></ul>
</div>
<div class="p" id="p556811306614"><a name="p556811306614"></a><a name="p556811306614"></a><strong id="b0183135142820"><a name="b0183135142820"></a><a name="b0183135142820"></a>Enhanced Features</strong><a name="ul834518400613"></a><a name="ul834518400613"></a><ul id="ul834518400613"><li>Updated the compilation and building plugin to version 3.0.3.2.</li><li>Improved the JSON editor, which now enables quick rectification of resource index errors and instant access to resource values.</li><li>Provided Ohos and Project (default) views for projects, which you can switch between easily.</li><li>Enabled OpenHarmony projects to support Ark build.</li><li>Moved the <strong id="b19966587296"><a name="b19966587296"></a><a name="b19966587296"></a>supportSystem "standard"</strong> field, which is exclusive to OpenHarmony projects, from the module-level <strong id="b596638162911"><a name="b596638162911"></a><a name="b596638162911"></a>build.gradle</strong> file to the project-level <strong id="b199671680295"><a name="b199671680295"></a><a name="b199671680295"></a>build.gradle</strong> file.</li></ul>
</div>
</td>
</tr>
</table>
# DevEco Studio \(OpenHarmony\) User Guide<a name="EN-US_TOPIC_0000001163049851"></a> # DevEco Studio \(OpenHarmony\) User Guide
- **[Overview](deveco-studio-overview.md)**
- **[Version Change History](deveco-studio-release-notes.md)**
- **[Configuring the OpenHarmony SDK](configuring-openharmony-sdk.md)**
- **[Creating an OpenHarmony Project](create-openharmony-project.md)**
- **[Configuring the OpenHarmony App Signature](configuring-openharmony-app-signature.md)**
- **[Installing and Running Your OpenHarmony App](installing-openharmony-app.md)**
# Importing a Sample to Create a Project<a name="EN-US_TOPIC_0000001163914943"></a>
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>This feature applies to OpenHarmony projects created using DevEco Studio 2.1 Release or later.
After the OpenHarmony SDK is configured, you can get started to develop your app by **importing a sample project**.
1. On the DevEco Studio welcome page, select **Configure** or click the ![](figures/en-us_image_0000001118018452.png) icon, and choose **Settings** \> **Version Control** \> **Git**. Then click **Test** to check whether the Git tool has been installed.
- If the tool has been installed, import a sample by following the instructions in Step 2.
![](figures/en-us_image_0000001118018088.png)
- If the tool hasn't been installed, click **Download and Install**. DevEco Studio will automatically download and install it. Then import a sample by following the instructions in Step 2.
![](figures/en-us_image_0000001164498191.png)
2. <a name="li5947194711181"></a>On the DevEco Studio welcome page, click **Import Sample** to import a sample project.
![](figures/en-us_image_0000001208006117.png)
3. Choose **OpenHarmony Samples** \> **common** \> **JsHelloWorld** \> **Next**.
![](figures/en-us_image_0000001152459178.png)
4. Configure **App Name** and **Project Location** and click **Finish**. Wait until the sample project is imported.
![](figures/en-us_image_0000001207744539.png)
5. When the project is successfully synced, start developing your OpenHarmony app.
![](figures/en-us_image_0000001163915523.png)
# Installing and Running Your OpenHarmony App<a name="EN-US_TOPIC_0000001115941596"></a>
You can install your OpenHarmony app in either of the following methods:
- DevEco Studio: Connect your device where the app is stored to DevEco Studio, and then click ![](figures/en-us_image_0000001239855207.png) to install the app.
- hdc: Run commands to install the app.
You can manually obtain the hdc tool from the open-source repository. Then, run the tool commands to install an HAP file on the device.
The tool commands are as follows:
- App installation
**install \[-r/-d/-g\] _package_**
Example:
```
hdc_std install E:\hwadmin.hap
```
- Log capturing
**hilog**
Example:
```
hdc_std hilog
```
For details about how to use hdc and the command format, see [hdc\_std Usage Guidelines](https://gitee.com/openharmony/docs/blob/master/en/device-dev/subsystems/subsys-toolchain-hdc-guide.md).
# Using the Project Wizard to Create a Project<a name="EN-US_TOPIC_0000001176969367"></a>
- [Prerequisites](#section13642104391619)
- [Procedure](#section132671712101714)
If you are using DevEco Studio 2.2 Beta1 or later, you can use the project wizard to create a project. If you are using DevEco Studio 2.1 Release, create a project by following instructions in [Importing a Sample to Create a Project](import-sample-to-create-project.md).
## Prerequisites<a name="section13642104391619"></a>
The OpenHarmony SDK has been installed. For details, see [Configuring the OpenHarmony SDK](configuring-openharmony-sdk.md).
## Procedure<a name="section132671712101714"></a>
1. Open the project wizard using either of the following methods:
- If no project is open, select **Create Project** on the welcome page.
- If a project is already open, choose **File** \> **New** \> **New Project** on the menu bar.
2. Select the **\[Standard\]Empty Ability** template and click **Next**.
![](figures/en-us_image_0000001162463400.png)
3. Click **Next** and configure the project.
- **Project name**: customized project name.
- **Project type**: project type, which can be an [atomic service](https://developer.harmonyos.com/en/docs/documentation/doc-guides/atomic-service-definition-0000001090840664) or an ordinary app that requires download before use.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>If you're creating an atomic service:
>- There is no app icon on the home screen while running or debugging an atomic service. Use the debugging and running functions of DevEco Studio as an alternative.
>- Atomic services are installation free. This is done by automatically adding the **installationFree** field to the **config.json** file, with its value set to **true**.
>- If the value of the **installationFree** field of the entry module is set to **true**, the value of the **installationFree** field of all the related HAP modules is **true** by default. If the** installationFree field** of the entry module is set to **false**, the **installationFree** field of all the related HAP modules can be set to **true** or **false**.
>- When compiling and building an app, make sure that the size of each HAP package does not exceed 10 MB.
- **Bundle name**: bundle name. By default, this name will also be used as your app ID. Your app must have a unique ID to be released. If **Project type** is set to **Atomic service**, the **Bundle name** must end with **.hmservice**.
- **Save location**: local path for storing the project file.
- **Development mode**: development mode. The **Super Visual** option is available if the project template supports low-code development.
- **Language**: supported programming language.
- **Compatible API version**: earliest SDK version compatible with your app.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>If **compileSdkVersion 7** or later is configured for the OpenHarmony project, the corresponding module will be compiled using ArkCompiler by default. To use a compiler other than ArkCompiler, add the **arkEnable false** field to the **ohos** closure in the module-level **build.gradle** file.
- **Device Type**: device type supported by the project template.
![](figures/en-us_image_0000001196050928.png)
4. Click **Finish**. DevEco Studio will automatically generate the sample code and resources that match your project type. Wait until the project is created.
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
- [WLAN](js-apis-wifi.md) - [WLAN](js-apis-wifi.md)
- [Bluetooth](js-apis-bluetooth.md) - [Bluetooth](js-apis-bluetooth.md)
- [RPC](js-apis-rpc.md) - [RPC](js-apis-rpc.md)
- [Upload and Download](js-apis-request.md)
- Device Management - Device Management
- [Sensor](js-apis-sensor.md) - [Sensor](js-apis-sensor.md)
- [Vibrator](js-apis-vibrator.md) - [Vibrator](js-apis-vibrator.md)
...@@ -80,6 +81,8 @@ ...@@ -80,6 +81,8 @@
- [Page Routing](js-apis-basic-features-routes.md) - [Page Routing](js-apis-basic-features-routes.md)
- [Timer](js-apis-basic-features-timer.md) - [Timer](js-apis-basic-features-timer.md)
- [Setting the System Time](js-apis-system-time.md) - [Setting the System Time](js-apis-system-time.md)
- [Wallpaper](js-apis-wallpaper.md)
- [Pasteboard](js-apis-pasteboard.md)
- [Animation](js-apis-basic-features-animator.md) - [Animation](js-apis-basic-features-animator.md)
- [WebGL](js-apis-webgl.md) - [WebGL](js-apis-webgl.md)
- [WebGL2](js-apis-webgl2.md) - [WebGL2](js-apis-webgl2.md)
......
# Pasteboard
> ![icon-note.gif](public_sys-resources/icon-note.gif) **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.
## Modules to Import
```
import pasteboard from '@ohos.pasteboard';
```
## Attributes
**System capability**: SystemCapability.MiscServices.Pasteboard
| Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- |
| MAX_RECORD_NUM<sup>7+</sup> | number | Yes | No | Maximum&nbsp;number&nbsp;of&nbsp;records&nbsp;allowed&nbsp;in&nbsp;a&nbsp;**PasteData**&nbsp;object. |
| MIMETYPE_TEXT_HTML<sup>7+</sup> | string | Yes | No | MIME&nbsp;type&nbsp;of&nbsp;the&nbsp;HTML&nbsp;text. |
| MIMETYPE_TEXT_WANT<sup>7+</sup> | string | Yes | No | MIME&nbsp;type&nbsp;of&nbsp;the&nbsp;Want&nbsp;text. |
| MIMETYPE_TEXT_PLAIN<sup>7+</sup> | string | Yes | No | MIME&nbsp;type&nbsp;of&nbsp;the&nbsp;plain&nbsp;text. |
| MIMETYPE_TEXT_URI<sup>7+</sup> | string | Yes | No | MIME&nbsp;type&nbsp;of&nbsp;the&nbsp;URI&nbsp;text. |
## pasteboard.createPlainTextData
createPlainTextData(text:string): PasteData
Creates a **PasteData** object for plain text.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| text | string | Yes | Plain&nbsp;text. |
- Return values
| Type | Description |
| -------- | -------- |
| [PasteData](#pastedata) | **PasteData**&nbsp;object&nbsp;with&nbsp;the&nbsp;specified&nbsp;content. |
- Example
```
var pasteData = pasteboard.createPlainTextData("content");
```
## pasteboard.createHtmlData<sup>7+</sup>
createHtmlData(htmlText:string): PasteData
Creates a **PasteData** object for HTML text.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| htmlText | string | Yes | HTML&nbsp;text. |
- Return values
| Type | Description |
| -------- | -------- |
| [PasteData](#pastedata) | **PasteData**&nbsp;object&nbsp;with&nbsp;the&nbsp;specified&nbsp;content. |
- Example
```
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var pasteData = pasteboard.createHtmlData(html);
```
## pasteboard.createWantData<sup>7+</sup>
createWantData(want:Want): PasteData
Creates a **PasteData** object for Want text.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#want) | Yes | Want&nbsp;text. |
- Return values
| Type | Description |
| -------- | -------- |
| [PasteData](#pastedata) | **PasteData**&nbsp;object&nbsp;with&nbsp;the&nbsp;specified&nbsp;content. |
- Example
```
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
var pasteData = pasteboard.createWantData(object);
```
## pasteboard.createUriData<sup>7+</sup>
createUriData(uri:string): PasteData
Creates a **PasteData** object for URI text.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;text. |
- Return values
| Type | Description |
| -------- | -------- |
| [PasteData](#pastedata) | **PasteData**&nbsp;object&nbsp;with&nbsp;the&nbsp;specified&nbsp;content. |
- Example
```
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
```
## pasteboard.createPlainTextRecord<sup>7+</sup>
createPlainTextRecord(text:string): PasteDataRecord
Creates a **PasteDataRecord** object of the plain text type.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| text | string | Yes | Plain&nbsp;text. |
- Return values
| Type | Description |
| -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New&nbsp;plain&nbsp;text&nbsp;record. |
- Example
```
var record = pasteboard.createPlainTextRecord("hello");
```
## pasteboard.createHtmlTextRecord<sup>7+</sup>
createHtmlTextRecord(htmlText:string): PasteDataRecord
Creates a **PasteDataRecord** object of the HTML text type.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| htmlText | string | Yes | HTML&nbsp;text. |
- Return values
| Type | Description |
| -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New&nbsp;HTML&nbsp;record. |
- Example
```
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var record = pasteboard.createHtmlTextRecord(html);
```
## pasteboard.createWantRecord<sup>7+</sup>
createWantRecord(want:Want): PasteDataRecord
Creates a **PasteDataRecord** object of the Want text type.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#want) | Yes | Want&nbsp;text. |
- Return values
| Type | Description |
| -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New&nbsp;Want&nbsp;record. |
- Example
```
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
var record = pasteboard.createWantRecord(object);
```
## pasteboard.createUriRecord<sup>7+</sup>
createUriRecord(uri:string): PasteDataRecord
Creates a **PasteDataRecord** object of the URI text type.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;text. |
- Return values
| Type | Description |
| -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New&nbsp;URI&nbsp;record. |
- Example
```
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
```
## PasteDataProperty<sup>7+</sup>
Defines the properties of all data records on the pasteboard, including the timestamp, data type, and additional data.
**System capability**: SystemCapability.MiscServices.Pasteboard
| Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- |
| additions | {[key:&nbsp;string]:&nbsp;object} | Yes | Yes | Additional&nbsp;property&nbsp;data. |
| mimeTypes | Array&lt;string&gt; | Yes | No | Non-repeating&nbsp;data&nbsp;types&nbsp;of&nbsp;the&nbsp;data&nbsp;records&nbsp;on&nbsp;the&nbsp;pasteboard. |
| tag | string | Yes | Yes | User-defined&nbsp;tag. |
| timestamp | number | Yes | No | Timestamp&nbsp;at&nbsp;which&nbsp;the&nbsp;data&nbsp;is&nbsp;written&nbsp;to&nbsp;the&nbsp;pasteboard,&nbsp;in&nbsp;milliseconds. |
| localOnly | boolean | Yes | Yes | Whether&nbsp;local&nbsp;access&nbsp;only&nbsp;is&nbsp;set&nbsp;for&nbsp;the&nbsp;pasteboard.<br/>-&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**true**.<br/>-&nbsp;**true**:&nbsp;The&nbsp;**PasteData**&nbsp;is&nbsp;set&nbsp;for&nbsp;local&nbsp;access&nbsp;only.<br/>-&nbsp;**false**:&nbsp;The&nbsp;**PasteData**&nbsp;can&nbsp;be&nbsp;shared&nbsp;between&nbsp;devices. |
## PasteDataRecord<sup>7+</sup>
A data record is an abstract definition of the content on the pasteboard. The pasteboard content consists of one or more plain text, HTML, URI, or Want records.
### Attributes
**System capability**: SystemCapability.MiscServices.Pasteboard
| Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- |
| htmlText<sup>7+</sup> | string | Yes | No | HTML&nbsp;text. |
| want<sup>7+</sup> | [Want](js-apis-featureAbility.md#want) | Yes | No | Want&nbsp;text. |
| mimeType<sup>7+</sup> | string | Yes | No | Data&nbsp;type. |
| plainText<sup>7+</sup> | string | Yes | No | Plain&nbsp;text. |
| uri<sup>7+</sup> | string | Yes | No | URI&nbsp;text. |
### convertToText<sup>7+</sup>
convertToText(): Promise&lt;string&gt;
Forcibly converts the content in this **PasteData** object to the plain text. This method uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;void&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result.&nbsp;If&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful,&nbsp;the&nbsp;plain&nbsp;text&nbsp;content&nbsp;after&nbsp;conversion&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;error&nbsp;information&nbsp;is&nbsp;returned. |
- Example
```
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
record.convertToText().then((data) => {
console.info('convertToText success data : ' + JSON.stringify(data));
}).catch((error) => {
console.error('convertToText failed because ' + JSON.stringify(error));
});
```
### convertToText<sup>7+</sup>
convertToText(callback: AsyncCallback&lt;string&gt;): void
Forcibly converts the content in this **PasteData** object to the plain text. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result.&nbsp;If&nbsp;this&nbsp;callback&nbsp;is&nbsp;successful,&nbsp;the&nbsp;plain&nbsp;text&nbsp;content&nbsp;after&nbsp;conversion&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;error&nbsp;information&nbsp;is&nbsp;returned. |
- Example
```
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
record.convertToText((err, data) => {
if (err) {
console.error('convertToText failed because ' + JSON.stringify(err));
return;
}
console.info('convertToText success data : ' + JSON.stringify(data));
});
```
## PasteData
Before calling any **PasteData** method, you must obtain a **PasteData** object.
**System capability**: SystemCapability.MiscServices.Pasteboard
### getPrimaryText
getPrimaryText(): string
Obtains the plain text of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
None
- Return values
| Type | Description |
| -------- | -------- |
| string | Plain&nbsp;text. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var plainText = pasteData.getPrimaryText();
```
### getPrimaryHtml<sup>7+</sup>
getPrimaryHtml(): string
Obtains the HTML text of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| string | HTML&nbsp;text. |
- Example
```
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var pasteData = pasteboard.createHtmlData(html);
var htmlText = pasteData.getPrimaryHtml();
```
### getPrimaryWant<sup>7+</sup>
getPrimaryWant(): Want
Obtains the **Want** object of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| [Want](js-apis-featureAbility.md#want) | Want&nbsp;object. |
- Example
```
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
var pasteData = pasteboard.createWantData(object);
var want = pasteData.getPrimaryWant();
```
### getPrimaryUri<sup>7+</sup>
getPrimaryUri(): string
Obtains the URI text of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| string | URI&nbsp;text. |
- Example
```
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
var uri = pasteData.getPrimaryUri();
```
### addTextRecord<sup>7+</sup>
addTextRecord(text: string): void
Adds a plain text record to this pasteboard, and adds **MIME_TEXT_PLAIN** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 128 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| text | string | Yes | Plain&nbsp;text. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
pasteData.addTextRecord("good");
```
### addHtmlRecord<sup>7+</sup>
addHtmlRecord(htmlText: string): void
Adds an HTML text record to this pasteboard, and adds **MIMETYPE_TEXT_HTML** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 128 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| htmlText | string | Yes | HTML&nbsp;text. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
pasteData.addHtmlRecord(html);
```
### addWantRecord<sup>7+</sup>
addWantRecord(want: Want): void
Adds a Want text record to this pasteboard, and adds **MIMETYPE_TEXT_WANT** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 128 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#want) | Yes | Want&nbsp;object. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
pasteData.addWantRecord(object);
```
### addUriRecord<sup>7+</sup>
addUriRecord(uri: string): void
Adds a URI text record to this pasteboard, and adds **MIMETYPE_TEXT_URI** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 128 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;text. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
pasteData.addUriRecord("dataability:///com.example.myapplication1?user.txt");
```
### addRecord<sup>7+</sup>
addRecord(record: PasteDataRecord): void
Adds a data record to this pasteboard, and adds its type to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 128 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| record | [PasteDataRecord](#pastedatarecord7) | Yes | Record&nbsp;to&nbsp;add. |
- Example
```
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
var textRecord = pasteboard.createPlainTextRecord("hello");
var html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
var htmlRecord = pasteboard.createHtmlTextRecord(html);
pasteData.addRecord(textRecord);
pasteData.addRecord(htmlRecord);
```
### getMimeTypes<sup>7+</sup>
getMimeTypes(): Array&lt;string&gt;
Obtains **mimeTypes** in [PasteDataProperty](#pastedataproperty7) from this pasteboard. If the pasteboard is empty, the returned list is also empty.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| Array&lt;string&gt; | List&nbsp;of&nbsp;non-duplicate&nbsp;MIME&nbsp;types. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var types = pasteData.getMimeTypes();
```
### getPrimaryMimeType<sup>7+</sup>
getPrimaryMimeType(): string
Obtains the data type of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| string | Data&nbsp;type&nbsp;of&nbsp;the&nbsp;primary&nbsp;record. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var type = pasteData.getPrimaryMimeType();
```
### getProperty<sup>7+</sup>
getProperty(): PasteDataProperty
Obtains the property description object.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| [PasteDataProperty](#pastedataproperty7) | Property&nbsp;description&nbsp;object. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var property = pasteData.getProperty();
```
### getRecordAt<sup>7+</sup>
getRecordAt(index: number): PasteDataRecord
Obtains the record with the specified index.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| index | number | Yes | Index&nbsp;of&nbsp;the&nbsp;specified&nbsp;record. |
- Return values
| Type | Description |
| -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | Record&nbsp;with&nbsp;the&nbsp;specified&nbsp;index. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var record = pasteData.getRecordAt(0);
```
### getRecordCount<sup>7+</sup>
getRecordCount(): number
Obtains the number of data records in this pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| number | Number&nbsp;of&nbsp;records. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var count = pasteData.getRecordCount();
```
### getTag<sup>7+</sup>
getTag(): string
Obtains the user-defined tag content. If the tag content is not set, null is returned.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| string | User-defined&nbsp;tag&nbsp;content&nbsp;if&nbsp;obtained&nbsp;and&nbsp;null&nbsp;if&nbsp;no&nbsp;tag&nbsp;is&nbsp;set. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var tag = pasteData.getTag();
```
### hasMimeType<sup>7+</sup>
hasMimeType(mimeType: string): boolean
Checks whether the content of this pasteboard contains the specified data type.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| mimeType | string | Yes | Type&nbsp;of&nbsp;the&nbsp;data&nbsp;to&nbsp;query. |
- Return values
| Type | Description |
| -------- | -------- |
| boolean | Returns&nbsp;**true**&nbsp;if&nbsp;the&nbsp;specified&nbsp;data&nbsp;type&nbsp;exists;&nbsp;returns&nbsp;**false**&nbsp;otherwise. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var hasType = pasteData.hasMimeType(pasteboard.MIMETYPE_TEXT_PLAIN);
```
### removeRecordAt<sup>7+</sup>
removeRecordAt(index: number): boolean
Removes the data record with a specified index from this pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| index | number | Yes | Specified&nbsp;index. |
- Return values
| Type | Description |
| -------- | -------- |
| boolean | Returns&nbsp;**true**&nbsp;if&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful;&nbsp;returns&nbsp;**false**&nbsp;otherwise. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var isRemove = pasteData.removeRecordAt(0);
```
### replaceRecordAt<sup>7+</sup>
replaceRecordAt(index: number, record: PasteDataRecord): boolean
Replaces the data record with a specified index in this pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| index | number | Yes | Specified&nbsp;index. |
| record | [PasteDataRecord](#pastedatarecord7) | Yes | New&nbsp;record. |
- Return values
| Type | Description |
| -------- | -------- |
| boolean | Returns&nbsp;**true**&nbsp;if&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful;&nbsp;returns&nbsp;**false**&nbsp;otherwise. |
- Example
```
var pasteData = pasteboard.createPlainTextData("hello");
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
var isReplace = pasteData.replaceRecordAt(0, record);
```
## pasteboard.getSystemPasteboard
getSystemPasteboard(): SystemPasteboard
Obtains the system pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| [SystemPasteboard](#systempasteboard) | System&nbsp;pasteboard. |
- Example
```
var systemPasteboard = pasteboard.getSystemPasteboard();
```
## SystemPasteboard
Before calling any **SystemPasteboard** method, you must obtain a **SystemPasteboard** object using [getSystemPasteboard](#pasteboardgetsystempasteboard).
```
var systemPasteboard = pasteboard.getSystemPasteboard();
```
### setPasteData
setPasteData(data:PasteData, callback:AsyncCallback&lt;void&gt;): void
Writes data to a pasteboard. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| data | [PasteData](#pastedata) | Yes | **PasteData**&nbsp;object. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;data&nbsp;write&nbsp;result. |
- Example
```
var pasteData = pasteboard.createPlainTextData("content");
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setPasteData(pasteData, (error, data) => {
if (error) {
console.error('Failed to setPasteData. Cause: ' + error.message);
return;
}
console.info('setPasteData successfully.');
});
```
### setPasteData
setPasteData(data:PasteData): Promise&lt;void&gt;
Writes data to a pasteboard. This method uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Description |
| -------- | -------- | -------- |
| data | [PasteData](#pastedata) | **PasteData**&nbsp;object. |
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;void&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;data&nbsp;write&nbsp;result. |
- Example
```
var pasteData = pasteboard.createPlainTextData("content");
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setPasteData(pasteData).then((data) => {
console.info('setPasteData success.');
}).catch((error) => {
console.error('Failed to setPasteData. Cause: ' + error.message);
});
```
### getPasteData
getPasteData( callback:AsyncCallback&lt;PasteData&gt;): void
Reads the system pasteboard content. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[PasteData](#pastedata)&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;system&nbsp;pasteboard&nbsp;data. |
- Example
```
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getPasteData((error, pasteData) => {
if (error) {
console.error('Failed to getPasteData. Cause: ' + error.message);
return;
}
var text = pasteData.getPrimaryText();
});
```
### getPasteData
getPasteData(): Promise&lt;PasteData&gt;
Reads the system pasteboard content. This method uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;[PasteData](#pastedata)&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;system&nbsp;pasteboard&nbsp;data. |
- Example
```
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getPasteData().then((pasteData) => {
var text = pasteData.getPrimaryText();
}).catch((error) => {
console.error('Failed to getPasteData. Cause: ' + error.message);
})
```
### on('update')<sup>7+</sup>
on(type: 'update', callback: () =&gt;void ): void
Subscribes to the content change event of the system pasteboard. If the pasteboard content changes, the callback is triggered.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Data&nbsp;type.&nbsp;The&nbsp;value&nbsp;**update**&nbsp;indicates&nbsp;the&nbsp;pasteboard&nbsp;content&nbsp;has&nbsp;changed. |
| callback | function | Yes | Callback&nbsp;invoked&nbsp;when&nbsp;the&nbsp;pasteboard&nbsp;content&nbsp;changes. |
- Example
```
var systemPasteboard = pasteboard.getSystemPasteboard();
var listener = ()=>{
console.info('The system pasteboard has changed');
};
systemPasteboard.on('update', listener);
```
### off('update')<sup>7+</sup>
off(type: 'update', callback? : () =&gt;void ): void
Unsubscribes from the system pasteboard content change event.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Data&nbsp;type.&nbsp;The&nbsp;value&nbsp;**update**&nbsp;indicates&nbsp;the&nbsp;pasteboard&nbsp;content&nbsp;has&nbsp;changed. |
| callback | function | No | Callback&nbsp;invoked&nbsp;when&nbsp;the&nbsp;pasteboard&nbsp;content&nbsp;changes. |
- Example
```
systemPasteboard.off('update', listener);
```
### hasPasteData<sup>7+</sup>
hasPasteData(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the system pasteboard contains content. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Returns&nbsp;**true**&nbsp;if&nbsp;the&nbsp;pasteboard&nbsp;contains&nbsp;content;&nbsp;returns&nbsp;**false**&nbsp;otherwise. |
- Example
```
systemPasteboard.hasPasteData((err, data) => {
if (err) {
console.error('failed to hasPasteData because ' + JSON.stringify(err));
return;
}
console.info('success hasPasteData : ' + JSON.stringify(data));
});
```
### hasPasteData<sup>7+</sup>
hasPasteData(): Promise&lt;boolean&gt;
Checks whether the system pasteboard contains content. This method uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;boolean&gt; | Returns&nbsp;**true**&nbsp;if&nbsp;the&nbsp;pasteboard&nbsp;contains&nbsp;content;&nbsp;returns&nbsp;**false**&nbsp;otherwise. |
- Example
```
systemPasteboard.hasPasteData().then((data) => {
console.info('Operation succeeded. ' + JSON.stringify(data));
}).catch((error) => {
console.error('failed to hasPasteData because ' + JSON.stringify(error));
});
```
### clear<sup>7+</sup>
clear(callback: AsyncCallback&lt;void&gt;): void
Clears the system pasteboard content. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
- Example
```
systemPasteboard.clear((err, data) => {
if (err) {
console.error('failed to clear because ' + JSON.stringify(err));
return;
}
console.info('success clear');
});
```
### clear<sup>7+</sup>
clear(): Promise&lt;void&gt;
Clears the system pasteboard content. This method uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;void&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
- Example
```
systemPasteboard.clear().then((data) => {
console.info('success clear');
}).catch((error) => {
console.error('failed to clear because ' + JSON.stringify(error));
});
```
# Upload and Download
> ![icon-note.gif](public_sys-resources/icon-note.gif) **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.
## Modules to Import
```
import request from '@ohos.request';
```
## Constraints
- HTTPS is supported by default. To support HTTP, you need to add **network** to the **config.json** file and set the **cleartextTraffic** attribute to **true**.
```
"deviceConfig": {
"default": {
"network": {
"cleartextTraffic": true
}
...
}
}
```
## Constants
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
| Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- |
| NETWORK_MOBILE | number | Yes | No | Whether&nbsp;download&nbsp;is&nbsp;allowed&nbsp;when&nbsp;the&nbsp;cellular&nbsp;network&nbsp;is&nbsp;used. |
| NETWORK_WIFI | number | Yes | No | Whether&nbsp;download&nbsp;is&nbsp;allowed&nbsp;when&nbsp;the&nbsp;WLAN&nbsp;is&nbsp;used. |
| ERROR_CANNOT_RESUME<sup>7+</sup> | number | Yes | No | Failure&nbsp;to&nbsp;resume&nbsp;the&nbsp;download&nbsp;due&nbsp;to&nbsp;an&nbsp;error. |
| ERROR_DEVICE_NOT_FOUND<sup>7+</sup> | number | Yes | No | Failure&nbsp;to&nbsp;find&nbsp;a&nbsp;storage&nbsp;device&nbsp;such&nbsp;as&nbsp;an&nbsp;SD&nbsp;card. |
| ERROR_FILE_ALREADY_EXISTS<sup>7+</sup> | number | Yes | No | Failure&nbsp;to&nbsp;download&nbsp;the&nbsp;file&nbsp;because&nbsp;it&nbsp;already&nbsp;exists. |
| ERROR_FILE_ERROR<sup>7+</sup> | number | Yes | No | File&nbsp;operation&nbsp;failure. |
| ERROR_HTTP_DATA_ERROR<sup>7+</sup> | number | Yes | No | HTTP&nbsp;transmission&nbsp;failure. |
| ERROR_INSUFFICIENT_SPACE<sup>7+</sup> | number | Yes | No | Insufficient&nbsp;storage&nbsp;space. |
| ERROR_TOO_MANY_REDIRECTS<sup>7+</sup> | number | Yes | No | Error&nbsp;caused&nbsp;by&nbsp;too&nbsp;many&nbsp;network&nbsp;redirections. |
| ERROR_UNHANDLED_HTTP_CODE<sup>7+</sup> | number | Yes | No | Unidentified&nbsp;HTTP&nbsp;code. |
| ERROR_UNKNOWN<sup>7+</sup> | number | Yes | No | Unknown&nbsp;error. |
| PAUSED_QUEUED_FOR_WIFI<sup>7+</sup> | number | Yes | No | Download&nbsp;paused&nbsp;and&nbsp;queuing&nbsp;for&nbsp;WLAN&nbsp;connection,&nbsp;because&nbsp;the&nbsp;file&nbsp;size&nbsp;exceeds&nbsp;the&nbsp;maximum&nbsp;value&nbsp;allowed&nbsp;by&nbsp;a&nbsp;cellular&nbsp;network&nbsp;session. |
| PAUSED_UNKNOWN<sup>7+</sup> | number | Yes | No | Download&nbsp;paused&nbsp;due&nbsp;to&nbsp;unknown&nbsp;reasons. |
| PAUSED_WAITING_FOR_NETWORK<sup>7+</sup> | number | Yes | No | Download&nbsp;paused&nbsp;due&nbsp;to&nbsp;a&nbsp;network&nbsp;connection&nbsp;problem,&nbsp;for&nbsp;example,&nbsp;network&nbsp;disconnection. |
| PAUSED_WAITING_TO_RETRY<sup>7+</sup> | number | Yes | No | Download&nbsp;paused&nbsp;and&nbsp;then&nbsp;retried. |
| SESSION_FAILED<sup>7+</sup> | number | Yes | No | Download&nbsp;failure&nbsp;without&nbsp;retry. |
| SESSION_PAUSED<sup>7+</sup> | number | Yes | No | Download&nbsp;paused. |
| SESSION_PENDING<sup>7+</sup> | number | Yes | No | Download&nbsp;pending. |
| SESSION_RUNNING<sup>7+</sup> | number | Yes | No | Download&nbsp;in&nbsp;progress. |
| SESSION_SUCCESSFUL<sup>7+</sup> | number | Yes | No | Successful&nbsp;download. |
## request.upload
upload(config: UploadConfig): Promise&lt;UploadTask&gt;
Uploads files. This method uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| config | [UploadConfig](#uploadconfig) | Yes | Configurations&nbsp;of&nbsp;the&nbsp;upload. |
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;[UploadTask](#uploadtask)&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;**UploadTask**&nbsp;object. |
- Example
```
request.upload({ url: 'https://patch' }).then((data) => {
uploadTask = data;
}).catch((err) => {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
})
```
## request.upload
upload(config: UploadConfig, callback: AsyncCallback&lt;UploadTask&gt;): void
Uploads files. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| config | [UploadConfig](#uploadconfig) | Yes | Configurations&nbsp;of&nbsp;the&nbsp;upload. |
| callback | AsyncCallback&lt;[UploadTask](#uploadtask)&gt; | No | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;**UploadTask**&nbsp;object. |
- Example
```
request.upload({ url: 'https://patch' }, (err, data) => {
if (err) {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
return;
}
uploadTask = data;
});
```
## UploadTask
Implements file uploads. Before using a method of this class, you must obtain an **UploadTask** object.
### on('progress')
on(type: 'progress', callback:(uploadedSize: number, totalSize: number) =&gt; void): void
Subscribes to the upload progress event. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;event&nbsp;to&nbsp;subscribe&nbsp;to.&nbsp;The&nbsp;value&nbsp;is&nbsp;**progress**&nbsp;(upload&nbsp;progress). |
| callback | function | Yes | Callback&nbsp;for&nbsp;the&nbsp;upload&nbsp;progress&nbsp;event. |
Parameters of the callback function
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| uploadedSize | number | Yes | Size&nbsp;of&nbsp;the&nbsp;uploaded&nbsp;files,&nbsp;in&nbsp;KB. |
| totalSize | number | Yes | Total&nbsp;size&nbsp;of&nbsp;the&nbsp;files&nbsp;to&nbsp;upload,&nbsp;in&nbsp;KB. |
- Example
```
uploadTask.on('progress', function callback(uploadedSize, totalSize) {
console.info("upload totalSize:" + totalSize + " uploadedSize:" + uploadedSize);
}
);
```
### on('headerReceive')<sup>7+</sup>
on(type: 'headerReceive', callback: (header: object) =&gt; void): void
Subscribes to the **headerReceive** event, which is triggered when an HTTP response header is received. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;event&nbsp;to&nbsp;subscribe&nbsp;to.&nbsp;The&nbsp;value&nbsp;is&nbsp;**headerReceive**&nbsp;(response&nbsp;header). |
| callback | function | Yes | Callback&nbsp;for&nbsp;the&nbsp;HTTP&nbsp;Response&nbsp;Header&nbsp;event. |
Parameters of the callback function
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| header | object | Yes | HTTP&nbsp;Response&nbsp;Header. |
- Example
```
uploadTask.on('headerReceive', function callback(headers){
console.info("upOnHeader headers:" + JSON.stringify(headers));
}
);
```
### off('progress')
off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) =&gt; void): void
Unsubscribes from the upload progress event. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;event&nbsp;to&nbsp;unsubscribe&nbsp;from.&nbsp;The&nbsp;value&nbsp;is&nbsp;**progress**&nbsp;(upload&nbsp;progress). |
| callback | function | No | Callback&nbsp;for&nbsp;the&nbsp;upload&nbsp;progress&nbsp;event. |
Parameters of the callback function
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| uploadedSize | number | Yes | Size&nbsp;of&nbsp;the&nbsp;uploaded&nbsp;files,&nbsp;in&nbsp;KB. |
| totalSize | number | Yes | Total&nbsp;size&nbsp;of&nbsp;the&nbsp;files&nbsp;to&nbsp;upload,&nbsp;in&nbsp;KB. |
- Example
```
uploadTask.off('progress', function callback(uploadedSize, totalSize) {
console.info('uploadedSize: ' + uploadedSize, 'totalSize: ' + totalSize);
}
);
```
### off('headerReceive')<sup>7+</sup>
off(type: 'headerReceive', callback?: (header: object) =&gt; void): void
Unsubscribes from the **headerReceive** event. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;event&nbsp;to&nbsp;unsubscribe&nbsp;from.&nbsp;The&nbsp;value&nbsp;is&nbsp;**headerReceive**&nbsp;(response&nbsp;header). |
| callback | function | No | Callback&nbsp;for&nbsp;the&nbsp;HTTP&nbsp;Response&nbsp;Header&nbsp;event. |
Parameters of the callback function
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| header | object | Yes | HTTP&nbsp;Response&nbsp;Header. |
- Example
```
uploadTask.off('headerReceive', function callback(headers) {
console.info("upOnHeader headers:" + JSON.stringify(headers));
}
);
```
### remove
remove(): Promise&lt;boolean&gt;
Removes this upload task. This method uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;task&nbsp;removal&nbsp;result.&nbsp;If&nbsp;**true**&nbsp;is&nbsp;returned,&nbsp;the&nbsp;task&nbsp;is&nbsp;removed.&nbsp;If&nbsp;**false**&nbsp;is&nbsp;returned,&nbsp;the&nbsp;task&nbsp;fails&nbsp;to&nbsp;be&nbsp;removed. |
- Example
```
uploadTask.remove().then((result) => {
if (result) {
console.info('Upload task removed successfully. ');
} else {
console.error('Failed to remove the upload task. ');
}
}).catch((err) => {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err));
});
```
### remove
remove(callback: AsyncCallback&lt;boolean&gt;): void
Removes this upload task. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
- Example
```
uploadTask.remove((err, result) => {
if (err) {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Upload task removed successfully.');
} else {
console.error('Failed to remove the upload task.');
}
});
```
## UploadConfig
**System capability**: SystemCapability.MiscServices.Upload
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| url | string | Yes | Resource&nbsp;URL. |
| header | object | No | HTTP&nbsp;or&nbsp;HTTPS&nbsp;header&nbsp;added&nbsp;to&nbsp;an&nbsp;upload&nbsp;request. |
| method | string | No | Request&nbsp;methods&nbsp;available:&nbsp;**POST**&nbsp;and&nbsp;**PUT**.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**POST**. |
| files | Array&lt;[File](#file)&gt; | Yes | List&nbsp;of&nbsp;files&nbsp;to&nbsp;upload,&nbsp;which&nbsp;is&nbsp;submitted&nbsp;through&nbsp;**multipart/form-data**. |
| data | Array&lt;[RequestData](#requestdata)&gt; | No | Form&nbsp;data&nbsp;in&nbsp;the&nbsp;request&nbsp;body. |
## File
**System capability**: SystemCapability.MiscServices.Upload
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| filename | string | No | File&nbsp;name&nbsp;in&nbsp;the&nbsp;header&nbsp;when&nbsp;**multipart**&nbsp;is&nbsp;used. |
| name | string | No | Name&nbsp;of&nbsp;a&nbsp;form&nbsp;item&nbsp;when&nbsp;**multipart**&nbsp;is&nbsp;used.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**file**. |
| uri | string | Yes | Local&nbsp;path&nbsp;for&nbsp;storing&nbsp;files.<br/>The&nbsp;**dataability**&nbsp;and&nbsp;**internal**&nbsp;protocol&nbsp;types&nbsp;are&nbsp;supported.&nbsp;However,&nbsp;the&nbsp;**internal**&nbsp;protocol&nbsp;type&nbsp;supports&nbsp;only&nbsp;temporary&nbsp;directories.&nbsp;The&nbsp;following&nbsp;is&nbsp;an&nbsp;example:<br/>dataability:///com.domainname.dataability.persondata/person/10/file.txt<br/>internal://cache/path/to/file.txt |
| type | string | No | Type&nbsp;of&nbsp;the&nbsp;file&nbsp;content.&nbsp;By&nbsp;default,&nbsp;the&nbsp;type&nbsp;is&nbsp;obtained&nbsp;based&nbsp;on&nbsp;the&nbsp;extension&nbsp;of&nbsp;the&nbsp;file&nbsp;name&nbsp;or&nbsp;URI. |
## RequestData
**System capability**: SystemCapability.MiscServices.Upload
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| name | string | Yes | Name&nbsp;of&nbsp;a&nbsp;form&nbsp;element. |
| value | string | Yes | Value&nbsp;of&nbsp;a&nbsp;form&nbsp;element. |
## request.download
download(config: DownloadConfig): Promise&lt;DownloadTask&gt;
Downloads files. This method uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| config | [DownloadConfig](#downloadconfig) | Yes | Configurations&nbsp;of&nbsp;the&nbsp;download. |
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;[DownloadTask](#downloadtask)&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
- Example
```
request.download({ url: 'https://xxxx/xxxx.hap' }).then((data) => {
downloadTask = data;
}).catch((err) => {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
})
```
## request.download
download(config: DownloadConfig, callback: AsyncCallback&lt;DownloadTask&gt;): void
Downloads files. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| config | [DownloadConfig](#downloadconfig) | Yes | Configurations&nbsp;of&nbsp;the&nbsp;download. |
| callback | AsyncCallback&lt;[DownloadTask](#downloadtask)&gt; | No | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
- Example
```
request.download({ 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;
});
```
## DownloadTask
Implements file downloads.
### on('progress')
on(type: 'progress', callback:(receivedSize: number, totalSize: number) =&gt; void): void
Subscribes to the download progress event. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;event&nbsp;to&nbsp;subscribe&nbsp;to.&nbsp;The&nbsp;value&nbsp;is&nbsp;**progress**&nbsp;(download&nbsp;progress). |
| callback | function | Yes | Callback&nbsp;for&nbsp;the&nbsp;download&nbsp;progress&nbsp;event. |
Parameters of the callback function
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| receivedSize | number | Yes | Size&nbsp;of&nbsp;the&nbsp;downloaded&nbsp;files,&nbsp;in&nbsp;KB. |
| totalSize | number | Yes | Total&nbsp;size&nbsp;of&nbsp;the&nbsp;files&nbsp;to&nbsp;download,&nbsp;in&nbsp;KB. |
- Example
```
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask = data;
downloadTask.on('progress', function download_callback(receivedSize, totalSize) {
console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize);
}
);
});
```
### off('progress')
off(type: 'progress', callback?: (receivedSize: number, totalSize: number) =&gt; void): void
Unsubscribes from the download progress event. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;event&nbsp;to&nbsp;unsubscribe&nbsp;from.&nbsp;The&nbsp;value&nbsp;is&nbsp;**progress**&nbsp;(download&nbsp;progress). |
| callback | function | No | Callback&nbsp;for&nbsp;the&nbsp;download&nbsp;progress&nbsp;event. |
Parameters of the callback function
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| receivedSize | number | Yes | Size&nbsp;of&nbsp;the&nbsp;downloaded&nbsp;files,&nbsp;in&nbsp;KB. |
| totalSize | number | Yes | Total&nbsp;size&nbsp;of&nbsp;the&nbsp;files&nbsp;to&nbsp;download,&nbsp;in&nbsp;KB. |
- Example
```
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask = data;
downloadTask .off('progress', function download_callback(receivedSize, totalSize) {
console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize);
}
);
});
```
### on('complete'|'pause'|'remove')<sup>7+</sup>
on(type: 'complete'|'pause'|'remove', callback:() =&gt; void): void
Subscribes to a download event. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Event&nbsp;type.<br/>-&nbsp;**complete**:&nbsp;download&nbsp;task&nbsp;completion&nbsp;event.<br/>-&nbsp;**pause**:&nbsp;download&nbsp;task&nbsp;pause&nbsp;event.<br/>-&nbsp;**remove**:&nbsp;download&nbsp;task&nbsp;removal&nbsp;event. |
| callback | function | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
- Example
```
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask= data;
downloadTask.on('complete', function callback() {
console.info('Download task completed.');
}
);
});
```
### off('complete'|'pause'|'remove')<sup>7+</sup>
off(type: 'complete'|'pause'|'remove', callback?:() =&gt; void): void
Unsubscribes from the download event. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Event&nbsp;type.<br/>-&nbsp;**complete**:&nbsp;download&nbsp;task&nbsp;completion&nbsp;event.<br/>-&nbsp;**pause**:&nbsp;download&nbsp;task&nbsp;pause&nbsp;event.<br/>-&nbsp;**remove**:&nbsp;download&nbsp;task&nbsp;removal&nbsp;event. |
| callback | function | No | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
- Example
```
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + JSON.stringify(err));
return;
}
downloadTask = data;
downloadTask.off('complete', function callback() {
console.info('Download task completed.');
}
);
});
```
### on('fail')<sup>7+</sup>
on(type: 'fail', callback: (err: number) =&gt; void): void
Subscribes to the download task failure event. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;subscribed&nbsp;event.&nbsp;The&nbsp;value&nbsp;is&nbsp;**fail**&nbsp;(download&nbsp;failure). |
| callback | function | Yes | Callback&nbsp;for&nbsp;the&nbsp;download&nbsp;task&nbsp;failure&nbsp;event. |
Parameters of the callback function
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| err | number | Yes | Error&nbsp;code&nbsp;of&nbsp;the&nbsp;download&nbsp;failure.&nbsp;For&nbsp;details&nbsp;about&nbsp;the&nbsp;error&nbsp;cause,&nbsp;see&nbsp;[ERROR_*](#constants). |
- Example
```
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask = data;
downloadTask.on('fail', function callBack(err) {
console.info('Download task failed. Cause:' + err);
}
);
});
```
### off('fail')<sup>7+</sup>
off(type: 'fail', callback?: (err: number) =&gt; void): void
Unsubscribes from the download task failure event. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;event&nbsp;to&nbsp;unsubscribe&nbsp;from.&nbsp;The&nbsp;value&nbsp;is&nbsp;**fail**&nbsp;(download&nbsp;failure). |
| callback | function | No | Callback&nbsp;for&nbsp;the&nbsp;download&nbsp;task&nbsp;failure&nbsp;event. |
Parameters of the callback function
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| err | number | Yes | Error&nbsp;code&nbsp;of&nbsp;the&nbsp;download&nbsp;failure.&nbsp;For&nbsp;details&nbsp;about&nbsp;the&nbsp;error&nbsp;cause,&nbsp;see&nbsp;[ERROR_*](#constants). |
- Example
```
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask = data;
downloadTask.off('fail', function callBack(err) {
console.info('Download task failed. Cause:' + err);
}
);
});
```
### remove
remove(): Promise&lt;boolean&gt;
Removes this download task. This method uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;task&nbsp;removal&nbsp;result. |
- Example
```
downloadTask.remove().then((result) => {
if (result) {
console.info('Download task removed.');
} else {
console.error('Failed to remove the download task.');
}
}).catch ((err) => {
console.error('Failed to remove the download task.');
});
```
### remove
remove(callback: AsyncCallback&lt;boolean&gt;): void
Removes this download task. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;task&nbsp;removal&nbsp;result. |
- Example
```
downloadTask.remove((err, result)=>{
if(err) {
console.error('Failed to remove the download task.');
return;
}
if (result) {
console.info('Download task removed.');
} else {
console.error('Failed to remove the download task.');
}
});
```
### query<sup>7+</sup>
query(): Promise&lt;DownloadInfo&gt;
Queries this download task. This method uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Type | Description |
| -------- | -------- |
| Promise&lt;[DownloadInfo](#downloadinfo7)&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;download&nbsp;task&nbsp;information. |
- Example
```
downloadTask.query().then((downloadInfo) => {
console.info('Download task queried. Data:' + JSON.stringify(downloadInfo))
}) .catch((err) => {
console.error('Failed to query the download task. Cause:' + err)
});
```
### query<sup>7+</sup>
query(callback: AsyncCallback&lt;DownloadInfo&gt;): void
Queries this download task. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[DownloadInfo](#downloadinfo7)&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;download&nbsp;task&nbsp;information. |
- Example
```
downloadTask.query((err, downloadInfo)=>{
if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err));
} else {
console.info('download query success. data:'+ JSON.stringify(downloadInfo));
}
});
```
### queryMimeType<sup>7+</sup>
queryMimeType(): Promise&lt;string&gt;
Queries **MimeType** of this download task. This method uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;string&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;**MimeType**&nbsp;of&nbsp;the&nbsp;download&nbsp;task. |
- Example
```
downloadTask.queryMimeType().then((data) => {
console.info('Download task queried. Data:' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to query the download MimeType. Cause:' + JSON.stringify(err))
});
```
### queryMimeType<sup>7+</sup>
queryMimeType(callback: AsyncCallback&lt;string&gt;): void;
Queries **MimeType** of this download task. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;**MimeType**&nbsp;of&nbsp;the&nbsp;download&nbsp;task. |
- Example
```
downloadTask.queryMimeType((err, data)=>{
if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err));
} else {
console.info('Download task queried. data:' + JSON.stringify(data));
}
});
```
### pause<sup>7+</sup>
pause(): Promise&lt;void&gt;
Pauses this download task. This method uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;void&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;download&nbsp;task&nbsp;pause&nbsp;result. |
- Example
```
downloadTask.pause().then((result) => {
if (result) {
console.info('Download task paused. ');
} else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result));
}
}).catch((err) => {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err));
});
```
### pause<sup>7+</sup>
pause(callback: AsyncCallback&lt;void&gt;): void
Pauses this download task. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
- Example
```
downloadTask.pause((err, result)=>{
if(err) {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err));
return;
}
if (result) {
console.info('Download task paused. ');
} else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result));
}
});
```
### resume<sup>7+</sup>
resume(): Promise&lt;void&gt;
Resumes this download task. This method uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Type | Description |
| -------- | -------- |
| Promise&lt;void&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
- Example
```
downloadTask.resume().then((result) => {
if (result) {
console.info('Download task resumed.')
} else {
console.error('Failed to resume the download task. ');
}
console.info('Download task resumed.')
}).catch((err) => {
console.error('Failed to resume the download task. Cause:' + err);
});
```
### resume<sup>7+</sup>
resume(callback: AsyncCallback&lt;void&gt;): void
Resumes this download task. This method uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
- Example
```
downloadTask.resume((err, result)=>{
if (err) {
console.error('Failed to resume the download task. Cause:' + err);
return;
}
if (result) {
console.info('Download task resumed.');
} else {
console.error('Failed to resume the download task.');
}
});
```
## DownloadConfig
**System capability**: SystemCapability.MiscServices.Download
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| url | string | Yes | Resource&nbsp;URL. |
| header | object | No | HTTP&nbsp;or&nbsp;HTTPS&nbsp;header&nbsp;added&nbsp;to&nbsp;a&nbsp;download&nbsp;request. |
| enableMetered | boolean | No | Download&nbsp;allowed&nbsp;in&nbsp;metered&nbsp;connections. |
| enableRoaming | boolean | No | Download&nbsp;allowed&nbsp;on&nbsp;a&nbsp;roaming&nbsp;network. |
| description | string | No | Description&nbsp;of&nbsp;the&nbsp;download&nbsp;session. |
| filePath<sup>7+</sup> | string | No | Download&nbsp;path.&nbsp;(The&nbsp;default&nbsp;path&nbsp;is&nbsp;[ERROR:Invalid&nbsp;link:en-us_topic_0000001135742582.xml#xref8132147102215,link:en-us_topic_0000001127125012.xml#section1856519365229](en-us_topic_0000001127125012.xml#section1856519365229)).<br/>-&nbsp;filePath:'workspace/test.txt':&nbsp;The&nbsp;**workspace**&nbsp;directory&nbsp;is&nbsp;created&nbsp;in&nbsp;the&nbsp;default&nbsp;path&nbsp;to&nbsp;store&nbsp;files.<br/>-&nbsp;filePath:'test.txt':&nbsp;Files&nbsp;are&nbsp;stored&nbsp;in&nbsp;the&nbsp;default&nbsp;path.<br/>-&nbsp;filePath:'workspace/':&nbsp;The&nbsp;**workspace**&nbsp;directory&nbsp;is&nbsp;created&nbsp;in&nbsp;the&nbsp;default&nbsp;path&nbsp;to&nbsp;store&nbsp;files. |
| networkType | number | No | Network&nbsp;type&nbsp;allowed&nbsp;for&nbsp;download. |
| title | string | No | Title&nbsp;of&nbsp;the&nbsp;download&nbsp;session. |
## DownloadInfo<sup>7+</sup>
**System capability**: SystemCapability.MiscServices.Download
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| downloadId | number | Yes | ID&nbsp;of&nbsp;the&nbsp;downloaded&nbsp;file. |
| failedReason | number | No | Download&nbsp;failure&nbsp;cause,&nbsp;which&nbsp;can&nbsp;be&nbsp;any&nbsp;constant&nbsp;of&nbsp;[ERROR_*](#constants). |
| fileName | string | Yes | Name&nbsp;of&nbsp;the&nbsp;downloaded&nbsp;file. |
| filePath | string | Yes | URI&nbsp;of&nbsp;the&nbsp;saved&nbsp;file. |
| pausedReason | number | No | Reason&nbsp;for&nbsp;session&nbsp;pause,&nbsp;which&nbsp;can&nbsp;be&nbsp;any&nbsp;constant&nbsp;of&nbsp;[PAUSED_*](#constants). |
| status | number | Yes | Download&nbsp;status&nbsp;code,&nbsp;which&nbsp;can&nbsp;be&nbsp;any&nbsp;constant&nbsp;of&nbsp;[SESSION_*](#constants). |
| targetURI | string | Yes | URI&nbsp;of&nbsp;the&nbsp;downloaded&nbsp;file. |
| downloadTitle | string | Yes | Title&nbsp;of&nbsp;the&nbsp;downloaded&nbsp;file. |
| downloadTotalBytes | number | Yes | Total&nbsp;size&nbsp;of&nbsp;the&nbsp;downloaded&nbsp;file&nbsp;(int&nbsp;bytes). |
| description | string | Yes | Description&nbsp;of&nbsp;the&nbsp;file&nbsp;to&nbsp;download. |
| downloadedBytes | number | Yes | Size&nbsp;of&nbsp;the&nbsp;files&nbsp;downloaded&nbsp;(int&nbsp;bytes). |
# Wallpaper
> ![icon-note.gif](public_sys-resources/icon-note.gif) **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.
## Modules to Import
```
import wallpaper from '@ohos.wallpaper';
```
## WallpaperType
Defines the wallpaper type.
**System capability**: SystemCapability.MiscServices.Wallpaper
| Name | Description |
| -------- | -------- |
| WALLPAPER_LOCKSCREEN | Lock&nbsp;screen&nbsp;wallpaper. |
| WALLPAPER_SYSTEM | Home&nbsp;screen&nbsp;wallpaper. |
## wallpaper.getColors
getColors(wallpaperType: WallpaperType, callback: AsyncCallback&lt;Array&lt;RgbaColor&gt;&gt;): void
Obtains the main color information of the wallpaper of a specified type.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes | Wallpaper&nbsp;type. |
| callback | AsyncCallback&lt;Array&lt;[RgbaColor](#rgbacolor)&gt;&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;main&nbsp;color&nbsp;information&nbsp;of&nbsp;the&nbsp;wallpaper. |
- Example
```
wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to getColors because: ` + JSON.stringify(error));
return;
}
console.log(`success to getColors.`);
});
```
## wallpaper.getColors
getColors(wallpaperType: WallpaperType): Promise&lt;Array&lt;RgbaColor&gt;&gt;
Obtains the main color information of the wallpaper of a specified type.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes | Wallpaper&nbsp;type. |
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;Array&lt;[RgbaColor](#rgbacolor)&gt;&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;main&nbsp;color&nbsp;information&nbsp;of&nbsp;the&nbsp;wallpaper. |
- Example
```
wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to getColors.`);
}).catch((error) => {
console.error(`failed to getColors because: ` + JSON.stringify(error));
});
```
## wallpaper.getId
getId(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void
Obtains the ID of the wallpaper of the specified type.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes | Wallpaper&nbsp;type. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;wallpaper&nbsp;ID.&nbsp;If&nbsp;the&nbsp;wallpaper&nbsp;of&nbsp;the&nbsp;specified&nbsp;type&nbsp;is&nbsp;configured,&nbsp;a&nbsp;number&nbsp;greater&nbsp;than&nbsp;or&nbsp;equal&nbsp;to&nbsp;**0**&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;**-1**&nbsp;is&nbsp;returned.&nbsp;The&nbsp;value&nbsp;ranges&nbsp;from&nbsp;-1&nbsp;to&nbsp;2^31-1. |
- Example
```
wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to getId because: ` + JSON.stringify(error));
return;
}
console.log(`success to getId: ` + JSON.stringify(data));
});
```
## wallpaper.getId
getId(wallpaperType: WallpaperType): Promise&lt;number&gt;
Obtains the ID of the wallpaper of the specified type.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes | Wallpaper&nbsp;type. |
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;number&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;wallpaper&nbsp;ID.&nbsp;If&nbsp;this&nbsp;type&nbsp;of&nbsp;wallpaper&nbsp;is&nbsp;configured,&nbsp;a&nbsp;number&nbsp;greater&nbsp;than&nbsp;or&nbsp;equal&nbsp;to&nbsp;**0**&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;**-1**&nbsp;is&nbsp;returned.&nbsp;The&nbsp;value&nbsp;ranges&nbsp;from&nbsp;-1&nbsp;to&nbsp;2^31-1. |
- Example
```
wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to getId: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to getId because: ` + JSON.stringify(error));
});
```
## wallpaper.getMinHeight
getMinHeight(callback: AsyncCallback&lt;number&gt;): void
Obtains the minimum height of the wallpaper.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;minimum&nbsp;wallpaper&nbsp;height,&nbsp;in&nbsp;pixels.&nbsp;If&nbsp;the&nbsp;return&nbsp;value&nbsp;is&nbsp;**0**,&nbsp;no&nbsp;wallpaper&nbsp;is&nbsp;set.&nbsp;In&nbsp;this&nbsp;case,&nbsp;the&nbsp;default&nbsp;height&nbsp;should&nbsp;be&nbsp;used&nbsp;instead. |
- Example
```
wallpaper.getMinHeight((error, data) => {
if (error) {
console.error(`failed to getMinHeight because: ` + JSON.stringify(error));
return;
}
console.log(`success to getMinHeight: ` + JSON.stringify(data));
});
```
## wallpaper.getMinHeight
getMinHeight(): Promise&lt;number&gt;
Obtains the minimum height of the wallpaper.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;number&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;minimum&nbsp;wallpaper&nbsp;height,&nbsp;in&nbsp;pixels.&nbsp;If&nbsp;the&nbsp;return&nbsp;value&nbsp;is&nbsp;**0**,&nbsp;no&nbsp;wallpaper&nbsp;is&nbsp;set.&nbsp;In&nbsp;this&nbsp;case,&nbsp;the&nbsp;default&nbsp;height&nbsp;should&nbsp;be&nbsp;used&nbsp;instead. |
- Example
```
wallpaper.getMinHeight().then((data) => {
console.log(`success to getMinHeight: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to getMinHeight because: ` + JSON.stringify(error));
});
```
## wallpaper.getMinWidth
getMinWidth(callback: AsyncCallback&lt;number&gt;): void
Obtains the minimum width of the wallpaper.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;minimum&nbsp;wallpaper&nbsp;width,&nbsp;in&nbsp;pixels.&nbsp;If&nbsp;the&nbsp;return&nbsp;value&nbsp;is&nbsp;**0**,&nbsp;no&nbsp;wallpaper&nbsp;is&nbsp;set.&nbsp;In&nbsp;this&nbsp;case,&nbsp;the&nbsp;default&nbsp;width&nbsp;should&nbsp;be&nbsp;used&nbsp;instead. |
- Example
```
wallpaper.getMinWidth((error, data) => {
if (error) {
console.error(`failed to getMinWidth because: ` + JSON.stringify(error));
return;
}
console.log(`success to getMinWidth: ` + JSON.stringify(data));
});
```
## wallpaper.getMinWidth
getMinWidth(): Promise&lt;number&gt;
Obtains the minimum width of the wallpaper.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;number&gt; | Promised&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;minimum&nbsp;wallpaper&nbsp;width,&nbsp;in&nbsp;pixels.&nbsp;If&nbsp;the&nbsp;return&nbsp;value&nbsp;is&nbsp;**0**,&nbsp;no&nbsp;wallpaper&nbsp;is&nbsp;set.&nbsp;In&nbsp;this&nbsp;case,&nbsp;the&nbsp;default&nbsp;width&nbsp;should&nbsp;be&nbsp;used&nbsp;instead. |
- Example
```
wallpaper.getMinWidth().then((data) => {
console.log(`success to getMinWidth: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to getMinWidth because: ` + JSON.stringify(error));
});
```
## wallpaper.isChangePermitted
isChangePermitted(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether to allow the application to change the wallpaper for the current user.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;queried&nbsp;result.&nbsp;Returns&nbsp;**true**&nbsp;if&nbsp;it&nbsp;is&nbsp;allowed;&nbsp;returns&nbsp;**false**&nbsp;otherwise. |
- Example
```
wallpaper.isChangePermitted((error, data) => {
if (error) {
console.error(`failed to isChangePermitted because: ` + JSON.stringify(error));
return;
}
console.log(`success to isChangePermitted: ` + JSON.stringify(data));
});
```
## wallpaper.isChangePermitted
isChangePermitted(): Promise&lt;boolean&gt;
Checks whether to allow the application to change the wallpaper for the current user.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;whether&nbsp;to&nbsp;allow&nbsp;the&nbsp;application&nbsp;to&nbsp;change&nbsp;the&nbsp;wallpaper&nbsp;for&nbsp;the&nbsp;current&nbsp;user.&nbsp;Returns&nbsp;**true**&nbsp;if&nbsp;it&nbsp;is&nbsp;allowed;&nbsp;returns&nbsp;**false**&nbsp;otherwise. |
- Example
```
wallpaper.isChangePermitted().then((data) => {
console.log(`success to isChangePermitted: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to isChangePermitted because: ` + JSON.stringify(error));
});
```
## wallpaper.isOperationAllowed
isOperationAllowed(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the user is allowed to set wallpapers.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;whether&nbsp;the&nbsp;user&nbsp;is&nbsp;allowed&nbsp;to&nbsp;set&nbsp;wallpapers.&nbsp;Returns&nbsp;**true**&nbsp;if&nbsp;it&nbsp;is&nbsp;allowed;&nbsp;returns&nbsp;**false**&nbsp;otherwise. |
- Example
```
wallpaper.isOperationAllowed((error, data) => {
if (error) {
console.error(`failed to isOperationAllowed because: ` + JSON.stringify(error));
return;
}
console.log(`success to isOperationAllowed: ` + JSON.stringify(data));
});
```
## wallpaper.isOperationAllowed
isOperationAllowed(): Promise&lt;boolean&gt;
Checks whether the user is allowed to set wallpapers.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;whether&nbsp;the&nbsp;user&nbsp;is&nbsp;allowed&nbsp;to&nbsp;set&nbsp;wallpapers.&nbsp;Returns&nbsp;**true**&nbsp;if&nbsp;it&nbsp;is&nbsp;allowed;&nbsp;returns&nbsp;**false**&nbsp;otherwise. |
- Example
```
wallpaper.isOperationAllowed().then((data) => {
console.log(`success to isOperationAllowed: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to isOperationAllowed because: ` + JSON.stringify(error));
});
```
## wallpaper.reset
reset(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
Removes a wallpaper of the specified type and restores the default one.
**Required permission**: ohos.permission.SET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes | Wallpaper&nbsp;type. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result.&nbsp;If&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful,&nbsp;the&nbsp;result&nbsp;of&nbsp;removal&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;error&nbsp;information&nbsp;is&nbsp;returned. |
- Example
```
wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to reset because: ` + JSON.stringify(error));
return;
}
console.log(`success to reset.`);
});
```
## wallpaper.reset
reset(wallpaperType: WallpaperType): Promise&lt;void&gt;
Removes a wallpaper of the specified type and restores the default one.
**Required permission**: ohos.permission.SET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes | Wallpaper&nbsp;type. |
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;void&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result.&nbsp;If&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful,&nbsp;the&nbsp;result&nbsp;of&nbsp;removal&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;error&nbsp;information&nbsp;is&nbsp;returned. |
- Example
```
wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to reset.`);
}).catch((error) => {
console.error(`failed to reset because: ` + JSON.stringify(error));
});
```
## wallpaper.setWallpaper
setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
Sets a specified source as the wallpaper of a specified type.
**Required permission**: ohos.permission.SET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| source | string&nbsp;\| [PixelMap](js-apis-image.md#pixelmap7) | Yes | Uri&nbsp;path&nbsp;of&nbsp;the&nbsp;JPEG&nbsp;or&nbsp;PNG&nbsp;file,&nbsp;or&nbsp;bitmap&nbsp;of&nbsp;the&nbsp;PNG&nbsp;file. |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes | Wallpaper&nbsp;type. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result.&nbsp;If&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful,&nbsp;the&nbsp;setting&nbsp;result&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;error&nbsp;information&nbsp;is&nbsp;returned. |
- Example
```
//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, data) => {
if (error) {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
return;
}
console.log(`success to setWallpaper.`);
});
//The source type is image.PixelMap.
import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = {
"desiredSize": {
"height": 3648,
"width": 2736
}
};
imageSource.createPixelMap(opts).then((pixelMap) => {
wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
return;
}
console.log(`success to setWallpaper.`);
});
}).catch((error) => {
console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
});
```
## wallpaper.setWallpaper
setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;
Sets a specified source as the wallpaper of a specified type.
**Required permission**: ohos.permission.SET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| source | string&nbsp;\|&nbsp;[PixelMap](js-apis-image.md#pixelmap7) | Yes | Uri&nbsp;path&nbsp;of&nbsp;the&nbsp;JPEG&nbsp;or&nbsp;PNG&nbsp;file,&nbsp;or&nbsp;bitmap&nbsp;of&nbsp;the&nbsp;PNG&nbsp;file. |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes | Wallpaper&nbsp;type. |
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;void&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result.&nbsp;If&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful,&nbsp;the&nbsp;setting&nbsp;result&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;error&nbsp;information&nbsp;is&nbsp;returned. |
- Example
```
//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((data) => {
console.log(`success to setWallpaper.`);
}).catch((error) => {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
});
//The source type is image.PixelMap.
import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = {
"desiredSize": {
"height": 3648,
"width": 2736
}
};
imageSource.createPixelMap(opts).then((pixelMap) => {
wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to setWallpaper.`);
}).catch((error) => {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
});
}).catch((error) => {
console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
});
```
## wallpaper.getFile<sup>8+</sup>
getFile(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void
Obtains the wallpaper of the specified type.
**Required permissions**: ohos.permission.GET_WALLPAPER and ohos.permission.READ_USER_STORAGE
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes | Wallpaper&nbsp;type. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result.&nbsp;If&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful,&nbsp;the&nbsp;file&nbsp;descriptor&nbsp;ID&nbsp;to&nbsp;the&nbsp;wallpaper&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;error&nbsp;information&nbsp;is&nbsp;returned. |
- Example
```
wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to getFile because: ` + JSON.stringify(error));
return;
}
console.log(`success to getFile: ` + JSON.stringify(data));
});
```
## wallpaper.getFile<sup>8+</sup>
getFile(wallpaperType: WallpaperType): Promise&lt;number&gt;
Obtains the wallpaper of the specified type.
**Required permissions**: ohos.permission.GET_WALLPAPER and ohos.permission.READ_USER_STORAGE
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes | Wallpaper&nbsp;type. |
- Return values
| Type | Description |
| -------- | -------- |
| Promise&lt;number&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result.&nbsp;If&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful,&nbsp;the&nbsp;file&nbsp;descriptor&nbsp;ID&nbsp;to&nbsp;the&nbsp;wallpaper&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;error&nbsp;information&nbsp;is&nbsp;returned. |
- Example
```
wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to getFile: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to getFile because: ` + JSON.stringify(error));
});
```
## wallpaper.on('colorChange')
on(type: 'colorChange', callback: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void
Subscribes to the wallpaper color change event.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;event&nbsp;to&nbsp;subscribe&nbsp;to.&nbsp;The&nbsp;value&nbsp;**colorChange**&nbsp;indicates&nbsp;subscribing&nbsp;to&nbsp;the&nbsp;wallpaper&nbsp;color&nbsp;change&nbsp;event. |
| callback | function | Yes | Callback&nbsp;triggered&nbsp;when&nbsp;the&nbsp;wallpaper&nbsp;color&nbsp;changes.&nbsp;The&nbsp;wallpaper&nbsp;type&nbsp;and&nbsp;main&nbsp;colors&nbsp;are&nbsp;returned.<br/>-&nbsp;colors<br/>&nbsp;&nbsp;Main&nbsp;color&nbsp;information&nbsp;of&nbsp;the&nbsp;wallpaper.&nbsp;For&nbsp;details,&nbsp;see&nbsp;[RgbaColor](#rgbacolor).<br/>-&nbsp;wallpaperType<br/>&nbsp;&nbsp;Wallpaper&nbsp;type. |
- Example
```
let listener = (colors, wallpaperType) => {
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange', listener);
```
## wallpaper.off('colorChange')
off(type: 'colorChange', callback?: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void
Unsubscribes from the wallpaper color change event.
**System capability**: SystemCapability.MiscServices.Wallpaper
- Parameters
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;event&nbsp;to&nbsp;unsubscribe&nbsp;from.&nbsp;The&nbsp;value&nbsp;**colorChange**&nbsp;indicates&nbsp;unsubscribing&nbsp;from&nbsp;the&nbsp;wallpaper&nbsp;color&nbsp;change&nbsp;event. |
| callback | function | No | &nbsp;&nbsp;Callback&nbsp;for&nbsp;the&nbsp;wallpaper&nbsp;color&nbsp;change&nbsp;event.&nbsp;If&nbsp;this&nbsp;parameter&nbsp;is&nbsp;not&nbsp;specified,&nbsp;all&nbsp;callbacks&nbsp;corresponding&nbsp;to&nbsp;the&nbsp;wallpaper&nbsp;color&nbsp;change&nbsp;event&nbsp;are&nbsp;invoked.<br/>-&nbsp;colors<br/>&nbsp;&nbsp;Main&nbsp;color&nbsp;information&nbsp;of&nbsp;the&nbsp;wallpaper.&nbsp;For&nbsp;details,&nbsp;see&nbsp;[RgbaColor](#rgbacolor).<br/>-&nbsp;wallpaperType<br/>&nbsp;&nbsp;Wallpaper&nbsp;type. |
- Example
```
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');
```
## RgbaColor
**System capability**: SystemCapability.MiscServices.Wallpaper
| Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- |
| red | number | Yes | Yes | Red&nbsp;color.&nbsp;The&nbsp;value&nbsp;ranges&nbsp;from&nbsp;0&nbsp;to&nbsp;255. |
| green | number | Yes | Yes | Green&nbsp;color.&nbsp;The&nbsp;value&nbsp;ranges&nbsp;from&nbsp;0&nbsp;to&nbsp;255. |
| blue | number | Yes | Yes | Blue&nbsp;color.&nbsp;The&nbsp;value&nbsp;ranges&nbsp;from&nbsp;0&nbsp;to&nbsp;255. |
| alpha | number | Yes | Yes | Alpha&nbsp;value.&nbsp;The&nbsp;value&nbsp;ranges&nbsp;from&nbsp;0&nbsp;to&nbsp;255. |
...@@ -61,7 +61,7 @@ Before creating a project, you need to install DevEco Studio. For details, see ...@@ -61,7 +61,7 @@ Before creating a project, you need to install DevEco Studio. For details, see
![](figures/en-us_image_0000001148858818.png) ![](figures/en-us_image_0000001148858818.png)
Before the installation, you must configure an application signature. For details, see [Configuring the OpenHarmony App Signature](../quick-start/configuring-openharmony-app-signature.md). After the installation is complete, click the **Run** icon on the screen to open the application. **Hello World** is displayed in the center of the screen. Before the installation, you must configure an application signature. For details, see [Configuring the OpenHarmony App Signature](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-debugging-and-running-0000001263040487#section17660437768). After the installation is complete, click the **Run** icon on the screen to open the application. **Hello World** is displayed in the center of the screen.
![](figures/en-us_image_0000001158896538.png) ![](figures/en-us_image_0000001158896538.png)
...@@ -2,17 +2,8 @@ ...@@ -2,17 +2,8 @@
- [Application Development Overview](application-dev-guide.md) - [Application Development Overview](application-dev-guide.md)
- Quick Start - Quick Start
- [Getting Started with Application Development](quick-start/Readme-EN.md)
- DevEco Studio (OpenHarmony) User Guide
- [Overview](quick-start/deveco-studio-overview.md)
- [Version Change History](quick-start/deveco-studio-release-notes.md)
- [Configuring the OpenHarmony SDK](quick-start/configuring-openharmony-sdk.md)
- [Creating an OpenHarmony Project](quick-start/create-openharmony-project.md)
- [Using the Project Wizard to Create a Project](quick-start/use-wizard-to-create-project.md)
- [Importing a Sample to Create a Project](quick-start/import-sample-to-create-project.md)
- [Configuring the OpenHarmony App Signature](quick-start/configuring-openharmony-app-signature.md)
- [Installing and Running Your OpenHarmony App](quick-start/installing-openharmony-app.md)
- [Directory Structure](quick-start/package-structure.md) - [Directory Structure](quick-start/package-structure.md)
- [Resource File Categories](quick-start/basic-resource-file-categories.md)
- Development - Development
- UI - UI
- JavaScript-based Web-Like Development Paradigm - JavaScript-based Web-Like Development Paradigm
...@@ -175,13 +166,7 @@ ...@@ -175,13 +166,7 @@
- [Overview of Application Event Logging](dfx/hiappevent-overview.md) - [Overview of Application Event Logging](dfx/hiappevent-overview.md)
- [Development Guidelines on Application Event Logging](dfx/hiappevent-guidelines.md) - [Development Guidelines on Application Event Logging](dfx/hiappevent-guidelines.md)
- Tools - Tools
- DevEco Studio (OpenHarmony) User Guide - [DevEco Studio (OpenHarmony) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md)
- [Overview](quick-start/deveco-studio-overview.md)
- [Version Change History](quick-start/deveco-studio-release-notes.md)
- [Configuring the OpenHarmony SDK](quick-start/configuring-openharmony-sdk.md)
- [Creating an OpenHarmony Project](quick-start/create-openharmony-project.md)
- [Configuring the OpenHarmony App Signature](quick-start/configuring-openharmony-app-signature.md)
- [Installing and Running Your OpenHarmony App](quick-start/installing-openharmony-app.md)
- Hands-On Tutorials - Hands-On Tutorials
- [Samples](https://gitee.com/openharmony/app_samples/blob/master/README.md) - [Samples](https://gitee.com/openharmony/app_samples/blob/master/README.md)
- API References - API References
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
### 工具 ### 工具
DevEco Studio工具是OpenHarmony应用开发的推荐IDE工具。 DevEco Studio工具是OpenHarmony应用开发的推荐IDE工具。
[工具](quick-start/deveco-studio-user-guide-for-openharmony.md)部分,讲解了DevEco Studio工具的详细用法,包括使用该工具进行工程创建、应用签名、应用调试、应用安装运行的指导。 [工具](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-deveco-studio-overview-0000001263280421)部分,讲解了DevEco Studio工具的详细用法,包括使用该工具进行工程创建、应用签名、应用调试、应用安装运行的指导。
### 示例教程 ### 示例教程
......
- [应用开发导读](application-dev-guide.md) - [应用开发导读](application-dev-guide.md)
- 快速开始 - 快速开始
- 应用开发快速入门
- DevEco Studio(OpenHarmony)使用指南 - 快速入门
- [概述](quick-start/deveco-studio-overview.md) - [前言](quick-start/start-overview.md)
- [版本变更说明](quick-start/deveco-studio-release-notes.md) - [使用eTS语言开发](quick-start/start-with-ets.md)
- [配置OpenHarmony SDK](quick-start/configuring-openharmony-sdk.md) - [使用JS语言开发(传统代码方式)](quick-start/start-with-js.md)
- 创建OpenHarmony工程 - [使用JS语言开发(低代码方式)](quick-start/start-with-js-low-code.md)
- [使用工程向导创建新工程](quick-start/use-wizard-to-create-project.md)
- [通过导入Sample方式创建新工程](quick-start/import-sample-to-create-project.md) - 开发基础知识
- [配置OpenHarmony应用签名信息](quick-start/configuring-openharmony-app-signature.md) - [应用开发包结构说明](quick-start/package-structure.md)
- [安装运行OpenHarmony应用](quick-start/installing-openharmony-app.md) - [资源文件的分类](quick-start/basic-resource-file-categories.md)
- 快速入门
- [前言](quick-start/start-overview.md)
- [使用eTS语言开发](quick-start/start-with-ets.md)
- [使用JS语言开发(传统代码方式)](quick-start/start-with-js.md)
- [使用JS语言开发(低代码方式)](quick-start/start-with-js-low-code.md)
- [应用开发包结构说明](quick-start/package-structure.md)
- [资源文件的分类](quick-start/basic-resource-file-categories.md)
- 开发 - 开发
- [Ability开发](ability/Readme-CN.md) - [Ability开发](ability/Readme-CN.md)
- [Ability框架概述](ability/ability-brief.md) - [Ability框架概述](ability/ability-brief.md)
...@@ -264,17 +259,14 @@ ...@@ -264,17 +259,14 @@
- [国际化开发概述](internationalization/international-overview.md) - [国际化开发概述](internationalization/international-overview.md)
- [Intl开发指导](internationalization/intl-guidelines.md) - [Intl开发指导](internationalization/intl-guidelines.md)
- [I18n开发指导](internationalization/i18n-guidelines.md) - [I18n开发指导](internationalization/i18n-guidelines.md)
- 工具 - 工具
- DevEco Studio(OpenHarmony)使用指南 - [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md)
- [概述](quick-start/deveco-studio-overview.md)
- [版本变更说明](quick-start/deveco-studio-release-notes.md)
- [配置OpenHarmony SDK](quick-start/configuring-openharmony-sdk.md)
- [创建OpenHarmony工程](quick-start/create-openharmony-project.md)
- [配置OpenHarmony应用签名信息](quick-start/configuring-openharmony-app-signature.md)
- [安装运行OpenHarmony应用](quick-start/installing-openharmony-app.md)
- 示例教程 - 示例教程
- [示例代码](https://gitee.com/openharmony/app_samples/blob/master/README_zh.md) - [示例代码](https://gitee.com/openharmony/app_samples/blob/master/README_zh.md)
- [Codelabs](https://gitee.com/openharmony/codelabs/blob/master/README.md) - [Codelabs](https://gitee.com/openharmony/codelabs/blob/master/README.md)
- API参考 - API参考
- 组件参考(基于JS扩展的类Web开发范式) - 组件参考(基于JS扩展的类Web开发范式)
- 组件 - 组件
...@@ -507,8 +499,6 @@ ...@@ -507,8 +499,6 @@
- [矩阵变换](reference/arkui-ts/ts-matrix-transformation.md) - [矩阵变换](reference/arkui-ts/ts-matrix-transformation.md)
- [插值计算](reference/arkui-ts/ts-interpolation-calculation.md) - [插值计算](reference/arkui-ts/ts-interpolation-calculation.md)
- 全局UI方法 - 全局UI方法
- [图片缓存](reference/arkui-ts/ts-methods-image-cache.md)
- [媒体查询](reference/arkui-ts/ts-methods-media-query.md)
- 弹窗 - 弹窗
- [警告弹窗](reference/arkui-ts/ts-methods-alert-dialog-box.md) - [警告弹窗](reference/arkui-ts/ts-methods-alert-dialog-box.md)
- [列表选择弹窗](reference/arkui-ts/ts-methods-action-sheet.md) - [列表选择弹窗](reference/arkui-ts/ts-methods-action-sheet.md)
...@@ -595,13 +585,13 @@ ...@@ -595,13 +585,13 @@
- [位置服务](reference/apis/js-apis-geolocation.md) - [位置服务](reference/apis/js-apis-geolocation.md)
- 基本功能 - 基本功能
- [应用上下文](reference/apis/js-apis-system-app.md) - [应用上下文](reference/apis/js-apis-system-app.md)
- [日志打印](reference/apis/js-apis-basic-features-logs.md) - [日志打印](reference/apis/js-apis-logs.md)
- [页面路由](reference/apis/js-apis-system-router.md) - [页面路由](reference/apis/js-apis-system-router.md)
- [弹窗](reference/apis/js-apis-system-prompt.md) - [弹窗](reference/apis/js-apis-system-prompt.md)
- [应用配置](reference/apis/js-apis-system-configuration.md) - [应用配置](reference/apis/js-apis-system-configuration.md)
- [定时器](reference/apis/js-apis-basic-features-timer.md) - [定时器](reference/apis/js-apis-timer.md)
- [设置系统时间](reference/apis/js-apis-system-time.md) - [设置系统时间](reference/apis/js-apis-system-time.md)
- [动画](reference/apis/js-apis-basic-features-animator.md) - [动画](reference/apis/js-apis-animator.md)
- [WebGL](reference/apis/js-apis-webgl.md) - [WebGL](reference/apis/js-apis-webgl.md)
- [WebGL2](reference/apis/js-apis-webgl2.md) - [WebGL2](reference/apis/js-apis-webgl2.md)
- [屏幕截图](reference/apis/js-apis-screenshot.md) - [屏幕截图](reference/apis/js-apis-screenshot.md)
......
# 入门 # 入门
- DevEco Studio(OpenHarmony)使用指南
- [概述](deveco-studio-overview.md)
- [版本变更说明](deveco-studio-release-notes.md)
- [配置OpenHarmony SDK](configuring-openharmony-sdk.md)
- 创建OpenHarmony工程
- [使用工程向导创建新工程](use-wizard-to-create-project.md)
- [通过导入Sample方式创建新工程](import-sample-to-create-project.md)
- [配置OpenHarmony应用签名信息](configuring-openharmony-app-signature.md)
- [安装运行OpenHarmony应用](installing-openharmony-app.md)
- 快速入门 - 快速入门
- [前言](start-overview.md) - [前言](start-overview.md)
- [使用eTS语言开发](start-with-ets.md) - [使用eTS语言开发](start-with-ets.md)
- [使用JS语言开发(传统代码方式)](start-with-js.md) - [使用JS语言开发(传统代码方式)](start-with-js.md)
- [使用JS语言开发(低代码方式)](start-with-js-low-code.md) - [使用JS语言开发(低代码方式)](start-with-js-low-code.md)
- [包结构说明](package-structure.md) - 开发基础知识
- [资源文件的分类](basic-resource-file-categories.md) - [包结构说明](package-structure.md)
- [资源文件的分类](basic-resource-file-categories.md)
# 配置OpenHarmony应用签名信息
使用真机设备运行和调试OpenHarmony应用前,需要对应用进行签名才能正常运行。该指导用于OpenHarmony应用的签名配置。除此章节以外,DevEco Studio的其余操作指导无差别,具体请访问[HUAWEI DevEco Studio使用指南](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/tools_overview-0000001053582387)。配置应用签名信息的流程如下图所示。
![zh-cn_image_0000001113808114](figures/zh-cn_image_0000001113808114.png)
## 生成密钥和证书请求文件
OpenHarmony应用通过数字证书(.cer文件)和Profile文件(.p7b文件)来保证应用的完整性,需要通过DevEco Studio来生成密钥文件(.p12文件)和证书请求文件(.csr文件)。同时,也可以使用命令行工具的方式来生成密钥文件和证书请求文件。
### 使用DevEco Studio生成
1. 在主菜单栏点击**Build &gt; Generate Keyand CSR**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 如果本地已有对应的密钥,无需新生成密钥,可以在**Generate Key**界面中点击下方的Skip跳过密钥生成过程,直接使用已有密钥生成证书请求文件。
2.**Key Store File**中,可以点击**Choose Existing**选择已有的密钥库文件(存储有密钥的.p12文件);如果没有密钥库文件,点击**New**进行创建。下面以新创建密钥库文件为例进行说明。
![zh-cn_image_0000001119560738](figures/zh-cn_image_0000001119560738.png)
3.**Create Key Store**窗口中,填写密钥库信息后,点击**OK**
- **Key Store File**:选择密钥库文件存储路径。
- **Password**:设置密钥库密码,必须由大写字母、小写字母、数字和特殊符号中的两种以上字符的组合,长度至少为8位。请记住该密码,后续签名配置需要使用。
- **Confirm Password**:再次输入密钥库密码。
![zh-cn_image_0000001152674854](figures/zh-cn_image_0000001152674854.png)
4.**Generate Key**界面中,继续填写密钥信息后,点击**Next**
- **Alias**:密钥的别名信息,用于标识密钥名称。请记住该别名,后续签名配置需要使用。
- **Password**:密钥对应的密码,与密钥库密码保持一致,无需手动输入。
- **Validity**:证书有效期,建议设置为25年及以上,覆盖应用/服务的完整生命周期。
- **Certificate**:输入证书基本信息,如组织、城市或地区、国家码等。
![zh-cn_image_0000001117639668](figures/zh-cn_image_0000001117639668.png)
5.**Generate CSR**界面,选择密钥和设置CSR文件存储路径。
![zh-cn_image_0000001117479776](figures/zh-cn_image_0000001117479776.png)
6. 点击**OK**按钮,创建CSR文件成功,可以在存储路径下获取生成的密钥库文件(.p12)和证书请求文件(.csr)。
![zh-cn_image_0000001163839541](figures/zh-cn_image_0000001163839541.png)
### 使用命令行工具生成
使用Open JDK携带的Keytool工具生成证书请求文件。
1. 使用管理员身份运行命令行工具。
![zh-cn_image_0000001248045243](figures/zh-cn_image_0000001248045243.png)
2. 切换到keytool工具所在路径,实际路径请根据安装目录进行修改。
![zh-cn_image_0000001247125297](figures/zh-cn_image_0000001247125297.png)
3. 执行如下命令,生成公私钥文件。例如,生成的密钥库名称为ide_demo_app.p12,存储到D盘根目录下。
```
keytool -genkeypair -alias "ide_demo_app" -keyalg EC -sigalg SHA256withECDSA -dname "C=CN,O=Organization,OU=Unit,CN=ide_demo_app" -keystore d:\\idedemokey.p12 -storetype pkcs12 -validity 9125 -storepass 123456Abc -keypass 123456Abc
```
生成公私钥文件的参数说明如下:
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 请记录**下alias、storepass**和**keypass**的值,在后续[配置应用签名信息](#配置应用签名信息)操作会使用到。
- **alias**:密钥的别名信息,用于标识密钥名称。
- **sigalg**:签名算法,固定为**SHA256withECDSA**
- **dname**:按照操作界面提示进行输入。
- C:国家/地区代码,如CN。
- O:组织名称,如Organization。
- OU:组织单位名称,如Unit。
- CN:名字与姓氏,建议与别名一致。
- **validity**:证书有效期,建议设置为9125(25年)。
- **storepass**:设置密钥库密码,必须由大写字母、小写字母、数字和特殊符号中的两种以上字符的组合,长度至少为8位。请记住该密码,后续签名配置需要使用。
- **keypass**:设置密钥的密码,请与**storepass**保持一致。
4. 执行如下命令,执行后需要输入**storepass**密码,生成证书请求文件,后缀格式为.csr。
```
keytool -certreq -alias "ide_demo_app" -keystore d:\\idedemokey.p12 -storetype pkcs12 -file d:\\idedemokey.csr
```
生成证书请求文件的参数说明如下:
- **alias**:与3中输入的alias保持一致。
- **file**:生成的证书请求文件名称,后缀为.csr。
## 生成应用证书文件
使用[生成密钥和证书请求文件](#生成密钥和证书请求文件)中生成的证书请求文件,来生成应用签名所需的数字证书文件。生成方法如下:
进入DevEco Studio安装目录的**Sdk\toolchains\lib**文件夹下(该SDK目录只能是OpenHarmony SDK,配置方法可参考[配置OpenHarmony SDK](../quick-start/configuring-openharmony-sdk.md)),打开命令行工具,执行如下命令(如果keytool命令不能执行,请在系统环境变量中添加JDK的环境变量)。其中,只需要修改输入和输出即可快速生成证书文件,即修改**-infile**指定证书请求文件csr文件路径,**-outfile**指定输出证书文件名及路径。
```
keytool -gencert -alias "OpenHarmony Application CA" -infile myApplication_ohos.csr -outfile myApplication_ohos.cer -keystore OpenHarmony.p12 -sigalg SHA384withECDSA -storepass 123456 -ext KeyUsage:"critical=digitalSignature" -validity 3650 -rfc
```
关于该命令的参数说明如下:
- **alias**:用于签发证书的CA私钥别名,OpenHarmony社区CA私钥存于OpenHarmony.p12密钥库文件中,该参数不能修改。
- **infile**:证书请求(CSR)文件的路径。
- **outfile**:输出证书链文件名及路径。
- **keystore**:签发证书的CA密钥库路径,OpenHarmony密钥库文件名为OpenHarmony.p12,文件在OpenHarmony SDK中**Sdk\toolchains\lib**路径下,该参数不能修改。请注意,该OpenHarmony.p12文件并不是[生成密钥和证书请求文件](#生成密钥和证书请求文件)中生成的.p12文件。
- **sigalg**:证书签名算法,该参数不能修改。
- **storepass**:密钥库密码,密码为123456,该参数不能修改。
- **ext**:证书扩展项,该参数不能修改。
- **validity**:证书有效期,自定义天数。
- **rfc**:输出文件格式指定,该参数不能修改。
## 生成应用Profile文件
Profile文件包含OpenHarmony应用的包名、数字证书信息、描述应用允许申请的证书权限列表,以及允许应用调试的设备列表(如果应用类型为Release类型,则设备列表为空)等内容,每个应用包中均必须包含一个Profile文件。
进入**Sdk\toolchains\lib**目录下,打开命令行工具,执行如下命令。
```
java -jar provisionsigtool.jar sign --in UnsgnedReleasedProfileTemplate.json --out myApplication_ohos_Provision.p7b --keystore OpenHarmony.p12 --storepass 123456 --alias "OpenHarmony Application Profile Release" --sigAlg SHA256withECDSA --cert OpenHarmonyProfileRelease.pem --validity 365 --developer-id ohosdeveloper --bundle-name 包名 --permission 受限权限名(可选) --permission 受限权限名(可选) --distribution-certificate myApplication_ohos.cer
```
关于该命令的参数说明如下:
- **provisionsigtool**:Profile文件生成工具,文件在OpenHarmony SDK的**Sdk\toolchains\lib**路径下。
- **in**:Profile模板文件所在路径,文件在OpenHarmony SDK中**Sdk\toolchains\lib**路径下,该参数不能修改。
- **out**:输出的Profile文件名和路径。
- **keystore**:签发证书的密钥库路径,OpenHarmony密钥库文件名为OpenHarmony.p12,文件在OpenHarmony SDK中**Sdk\toolchains\lib**路径下,该参数不能修改。
- **storepass**:密钥库密码,密码为123456,该参数不能修改。
- **alias**:用于签名Profile私钥别名,OpenHarmony社区CA私钥存于OpenHarmony.p12密钥库文件中,该参数不能修改。
- **sigalg**:证书签名算法,该参数不能修改。
- **cert**:签名Profile的证书文件路径,文件在OpenHarmony SDK中**Sdk\toolchains\lib**路径下,该参数不能修改。
- **validity**:证书有效期,自定义天数。
- **developer-id**:开发者标识符,自定义一个字符串。
- **bundle-name**:填写应用包名。
- **permission**:可选字段,如果不需要,则可以不用填写此字段;如果需要添加多个受限权限,则如示例所示重复输入。受限权限列表如下:ohos.permission.READ_CONTACTS、ohos.permission.WRITE_CONTACTS。
- **distribution-certificate**[生成应用证书文件](#生成应用证书文件)中生成的证书文件。
## 配置应用签名信息
在真机设备上调试前,需要使用到制作的私钥(.p12)文件、证书(.cer)文件和Profile(.p7b)文件对调试的模块进行签名。
打开**File &gt; Project Structure**,点击**Project &gt; Signing Configs &gt; debug**窗口中,去除勾选“Automatically generate signing”,然后配置指定模块的调试签名信息。
- **Store File**:选择密钥库文件,文件后缀为.p12,该文件为[生成密钥和证书请求文件](#生成密钥和证书请求文件)中生成的.p12文件。
- **Store Password**:输入密钥库密码,该密码为[生成密钥和证书请求文件](#生成密钥和证书请求文件)中填写的密钥库密码保持一致。
- **Key Alias**:输入密钥的别名信息,与[生成密钥和证书请求文件](#生成密钥和证书请求文件)中填写的别名保持一致。
- **Key Password**:输入密钥的密码,与**Store Password**保持一致。
- **Sign Alg**:签名算法,固定为SHA256withECDSA。
- **Profile File**:选择[生成应用Profile文件](#生成应用profile文件)中生成的Profile文件,文件后缀为.p7b。
- **Certpath File**:选择[生成应用证书文件](#生成应用证书文件)中生成的数字证书文件,文件后缀为.cer。
![zh-cn_image_0000001155643492](figures/zh-cn_image_0000001155643492.png)
设置完签名信息后,点击**OK**进行保存,然后可以在工程下的build.gradle中查看签名的配置信息。
![zh-cn_image_0000001202722349](figures/zh-cn_image_0000001202722349.png)
默认情况下,DevEco Studio编译hap包的类型为debug类型,如果需要编译release类型的hap包,请打开工程左下角的OhosBuild Variants,设置模块的编译构建类型为release。关于编译构建hap的详细说明请参考[HUAWEI DevEco Studio使用指南](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/build_hap-0000001053342418)
![zh-cn_image_0000001115066116](figures/zh-cn_image_0000001115066116.png)
编译完成后,OpenHarmony应用的Hap包可以从工程的bulid目录下获取。
![zh-cn_image_0000001163918627](figures/zh-cn_image_0000001163918627.png)
# 配置OpenHarmony SDK
在设置OpenHarmony应用开发环境时,需要开发者在DevEco Studio中配置对应的SDK信息。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 请注意,OpenHarmony SDK版本精简了部分工具链,因此不适用于HarmonyOS应用开发。
## 前提条件
已下载并安装好DevEco Studio 3.0 Beta1及以上版本,点击[链接下载](https://developer.harmonyos.com/cn/develop/deveco-studio#download)
## 配置SDK信息
DevEco Studio通过SDK Manager统一管理SDK及工具链,OpenHarmony包含如下SDK包:
| 类别 | 包名 | 说明 |
| -------- | -------- | -------- |
| SDK | JS | JS语言SDK包。 |
| eTS | eTS(Extended&nbsp;TypeScript)&nbsp;SDK包。 |
| SDK&nbsp;Tool | Toolchains | SDK工具链,OpenHarmony应用开发必备工具集,包括编译、打包、签名、数据库管理等工具的集合。 |
| Previewer | OpenHarmony应用预览器,可以在应用开发过程中查看界面UI布局效果。 |
1. 运行已安装的DevEco Studio,首次使用,请选择**Do not import settings**,点击OK。
2. 进入配置向导页面,设置**npm registry**,DevEco Studio已预置对应的仓,直接点击**Start using DevEco Studio**进入下一步。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 如果配置向导界面出现的是设置**Set up HTTP Proxy**界面,说明网络受限,请根据[参考信息](#参考信息)配置DevEco Studio代理、NPM代理和Gradle代理后,再下载OpenHarmony SDK。
![zh-cn_image_0000001163314102](figures/zh-cn_image_0000001163314102.png)
3. DevEco Studio向导指引开发者下载SDK,默认下载OpenHarmony SDK。SDK下载到user目录下,也可以指定对应的存储路径,SDK存储路径不支持中文字符,然后点击**Next**
![zh-cn_image_0000001208394019](figures/zh-cn_image_0000001208394019.png)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 如果不是首次安装DevEco Studio,可能无法查看进入该界面,可通过欢迎页的**Configure (或**![zh-cn_image_0000001208274069](figures/zh-cn_image_0000001208274069.png)**图标)&gt; Settings &gt; SDK Manager &gt; OpenHarmony SDK**界面,点击**OpenHarmony SDK Location**加载SDK。
4. 在弹出的SDK下载信息页面,点击**Next**,并在弹出的**License Agreement**窗口,点击**Accept**开始下载SDK。
![zh-cn_image_0000001163472654](figures/zh-cn_image_0000001163472654.png)
5. 等待OpenHarmony SDK及工具下载完成,点击**Finish**,界面会进入到DevEco Studio欢迎页。
![zh-cn_image_0000001163632602](figures/zh-cn_image_0000001163632602.png)
## 参考信息
DevEco Studio开发环境需要依赖于网络环境,需要连接上网络才能确保工具的正常使用。
一般来说,如果使用的是个人或家庭网络,是不需要设置代理信息的;只有部分企业网络受限的情况下,才需要设置代理信息。
如果是第一次打开DevEco Studio,配置向导界面出现设置**Set up HTTP Proxy**界面,说明网络受限,可以通过配置代理的方式来解决,需要配置DevEco Studio代理、NPM代理和Gradle代理。
![zh-cn_image_0000001166582138](figures/zh-cn_image_0000001166582138.png)
### 配置DevEco Studio代理
1. 启动DevEco Studio,配置向导进入**Set up HTTP Proxy**界面,勾选**Manual proxy configuration**,设置DevEco Studio的HTTP Proxy。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 如果非首次设置向导进入HTTP Proxy,可以通过如下方式进入HTTP Proxy配置界面:
>
> - 在欢迎页点击**Configure(或**![zh-cn_image_0000001212142015](figures/zh-cn_image_0000001212142015.png)**图标) &gt; Settings &gt; Appearance &amp; Behavior &gt; System Settings &gt; HTTP Proxy**进入HTTP Proxy设置界面(Mac系统为**Configure &gt; Preferences &gt; Appearance &amp; Behavior &gt; System Settings &gt; HTTP Proxy**)。
>
> - 在打开了工程的情况下,可以点击**File &gt; Settings &gt; Appearance &amp; Behavior &gt; System Settings &gt; HTTP Proxy**进入HTTP Proxy设置界面(Mac系统为**DevEco Studio &gt; Preferences &gt; Appearance &amp; Behavior &gt; System Settings &gt; HTTP Proxy**)
- **HTTP**配置项,设置代理服务器信息。**如果不清楚代理服务器信息,可以咨询你们的网络管理人员**
- **Host name**:代理服务器主机名或IP地址。
- **Port number**:代理服务器对应的端口号。
- **No proxy for**:不需要通过代理服务器访问的URL或者IP地址(地址之间用英文逗号分隔)。
- **Proxy authentication**配置项,如果代理服务器需要通过认证鉴权才能访问,则需要设置。否则,请跳过该配置项。
- **Login**:访问代理服务器的用户名。
- **Password**:访问代理服务器的密码。
- **Remember**:勾选,记住密码。
![zh-cn_image_0000001212062065](figures/zh-cn_image_0000001212062065.png)
2. 配置完成后,点击**Check connection**,输入网络地址(如:https://developer.harmonyos.com),检查网络连通性。提示Connection successful表示代理设置成功。
3. 点击**Next: Configure npm**继续设置NPM代理信息,请参考[配置NPM代理](#配置npm代理)
### 配置NPM代理
通过DevEco Studio的设置向导设置NPM代理信息,代理信息将写入用户“users/用户名/”目录下的**.npmrc**文件。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 该向导只有第一次安装DevEco Studio才会出现。如果未出现该向导,可以直接在“users/用户名/”目录下的**.npmrc**文件中,添加代理配置信息。
- npm registry:设置npm仓的地址信息,建议勾选。
- HTTP proxy:代理服务器信息,默认会与DevEco Studio的HTTP proxy设置项保持一致。
- Enable Https Proxy:同步设置HTTPS Proxy配置信息,建议勾选。
![zh-cn_image_0000001164577336](figures/zh-cn_image_0000001164577336.png)
然后点击**Start using DevEco Studio**继续下一步操作。
如果代理服务器需要认证(需要用户名和密码),请先根据如下指导配置代理服务器的用户名和密码信息,然后再下载OpenHarmony SDK;否则,请跳过该操作,参考[配置SDK信息](#配置sdk信息)进行操作即可。
![zh-cn_image_0000001209817299](figures/zh-cn_image_0000001209817299.png)
1. 进入用户的users目录,打开**.npmrc**文件。
2. 修改npm代理信息,在proxy和https-proxy中,增加user和password字段,具体取值请以实际代理信息为准。示例如下所示:
```
proxy=http://user:password@proxy.server.com:80
https-proxy=http://user:password@proxy.server.com:80
```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 如果password中存在特殊字符,如\@、\#、\*等符号,可能导致配置不生效,建议将特殊字符替换为ASCII码,并在ASCII码前加百分号%。常用符号替换为ASCII码对照表如下:
>
> - !:%21
>
> - \@:%40
>
> - \#:%23
>
> - ¥:%24
>
> - &amp;:%26
>
> - \*:%2A
3. 代理设置完成后,打开命令行工具,执行如下命令进行验证网络是否正常。
```
npm info express
```
执行结果如下图所示,则说明代理设置成功。
![zh-cn_image_0000001164417356](figures/zh-cn_image_0000001164417356.png)
4. 网络设置完成后,然后再[配置SDK信息](#配置sdk信息)
### 设置Gradle代理
1. 打开“此电脑”,在文件夹地址栏中输入**%userprofile%**(Mac系统请点击**前往 &gt; 个人**),进入个人用户文件夹。
![zh-cn_image_0000001166740700](figures/zh-cn_image_0000001166740700.png)
2. 创建一个文件夹,命名为**.gradle**。如果已有.gradle文件夹,请跳过此操作。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> macOS系统创建.gradle文件夹前,请将系统设置为“显示隐藏文件”。
3. 进入.gradle文件夹,新建一个文本文档,命名为**gradle**,并修改后缀为**.properties**
4. 打开**gradle.properties**文件中,添加如下脚本,然后保存。
其中代理服务器、端口、用户名、密码和不使用代理的域名,请根据实际代理情况进行修改。其中不使用代理的nonProxyHosts的配置间隔符是 “|”。
```
systemProp.http.proxyHost=proxy.server.com
systemProp.http.proxyPort=8080
systemProp.http.nonProxyHosts=*.company.com|10.*|100.*
systemProp.http.proxyUser=userId
systemProp.http.proxyPassword=password
systemProp.https.proxyHost=proxy.server.com
systemProp.https.proxyPort=8080
systemProp.https.nonProxyHosts=*.company.com|10.*|100.*
systemProp.https.proxyUser=userId
systemProp.https.proxyPassword=password
```
# 创建OpenHarmony工程
- **[使用工程向导创建新工程](use-wizard-to-create-project.md)**
- **[通过导入Sample方式创建新工程](import-sample-to-create-project.md)**
\ No newline at end of file
# 概述
## 总体说明
DevEco Studio是HarmonyOS的配套的开发IDE,因为HarmonyOS是基于OpenHarmony开发的,因此,使用DevEco Studio(配套HarmonyOS)也可以进行OpenHarmony的应用开发。
使用DevEco Studio开发OpenHarmony应用的流程与开发HarmonyOS的流程完全一样,本文档仅描述OpenHarmony应用开发与HarmonyOS应用开发的差异点。
- **搭建开发环境差异**:OpenHarmony应用开发环境需要先安装OpenHarmony SDK,具体可参考[配置OpenHarmony SDK](../quick-start/configuring-openharmony-sdk.md)章节。
- **创建OpenHarmony工程**:OpenHarmony应用开发,可以通过工程向导创建一个新工程,或通过导入Sample工程的方式来创建一个新工程,具体可参考[使用工程向导创建新工程](../quick-start/use-wizard-to-create-project.md)
- **调试签名配置**:OpenHarmony应用运行在真机设备上,需要对应用进行签名,关于OpenHarmony应用的签名指导请参考[配置OpenHarmony应用签名信息](../quick-start/configuring-openharmony-app-signature.md)
- **在真机设备上运行应用**:将OpenHarmony的hap包推送到真机设备上进行安装,具体可参考[安装运行OpenHarmony应用](../quick-start/installing-openharmony-app.md)
关于DevEco Studio的详细操作指导,请访问[HUAWEI DevEco Studio使用指南](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/tools_overview-0000001053582387)
## 使用约束
- OpenHarmony只支持使用eTS、JS语言开发应用,不支持Java、C/C++语言。
- OpenHarmony开发环境DevEco Studio暂只支持Windows系统。
OpenHarmony与HarmonyOS的开发工具都是DevEco Studio,下表为OpenHarmony相比HarmonyOS不支持的功能说明:
| 特性名称 | HarmonyOS版本 | OpenHarmony版本 |
| -------- | -------- | -------- |
| 服务卡片 | **√** | **X** |
| 自动化签名 | **√** | **X** |
| 远程模拟器 | **√** | **X** |
| 本地模拟器 | **√** | **X** |
| 使用DevEco&nbsp;Studio进行日志查看、调优 | **√** | **X** |
| 云测试 | **√** | **X** |
| 安全测试 | **√** | **X** |
## DevEco Studio演进路标
Huawei DevEco Studio分阶段支持OpenHarmony应用开发的演进路标如下:
![zh-cn_image_0000001210018359](figures/zh-cn_image_0000001210018359.png)
# 版本变更说明
## V3.0 Beta2(2021-12-31)
### 版本兼容性
DevEco Studio 3.0 Beta2版本兼容性配套关系如下表所示。
| 组件 | 版本要求 | 说明 |
| -------- | -------- | -------- |
| Gradle | 7.3(最低版本要求7.2) | DevEco&nbsp;Studio已自带了Gradle7.3版本,开发者无需单独安装。 |
| JDK | 11.0.x | DevEco&nbsp;Studio已自带了JDK&nbsp;11版本,开发者无需单独安装。 |
| OpenHarmony&nbsp;SDK | 3.1.0.0(API&nbsp;Version&nbsp;8&nbsp;Beta) | 兼容历史版本SDK。 |
| Toolchinas | 3.1.0.0 | 建议更新至最新版本。 |
| hap插件 | 3.0.5.2 | 建议更新至最新版本。 |
| decctest插件 | 1.2.7.2 | 建议更新至最新版本。 |
### 版本变更说明
| |
| -------- |
| **新增特性:**<br/>-&nbsp;新增DevEco&nbsp;Studio支持界面功能菜单的汉化版本,默认显示为英文,如需开启汉化版本,请打开DevEco&nbsp;Studio的**Settings**界面,在**Plugins&nbsp;&gt;&nbsp;installed**中手动勾选“Chinese(Simplified)”插件,然后重新启动DevEco&nbsp;Studio即可生效。<br/>-&nbsp;新增支持OpenHarmony应用或服务的调试和运行,支持断点管理、变量查看、Step&nbsp;Into\Step&nbsp;Over\Step&nbsp;Out等单步调试功能。<br/>**增强特性:**<br/>-&nbsp;OpenHarmony&nbsp;SDK更新至3.1.0.0版本(API&nbsp;Version&nbsp;8&nbsp;Beta),配套的hap编译构建插件版本更新至3.0.5.2。<br/>-&nbsp;工程模板新增支持低代码开发的[Standard]Empty&nbsp;Ability模板。<br/>-&nbsp;支持eTS组件预览,要求compileSdkVersion为8或以上。<br/>-&nbsp;eTS实时预览支持边修改属性边展示预览效果,无需保存修改才生效,要求compileSdkVersion为8或以上。 |
## V3.0 Beta1(2021-09-29)
| |
| -------- |
| **新增特性:**<br/>-&nbsp;新增支持OpenHarmony&nbsp;SDK的管理,开发者可通过DevEco&nbsp;Studio的SDK&nbsp;Manager功能来下载和管理OpenHarmony&nbsp;SDK。<br/>-&nbsp;在编译构建HAP包时,新增支持对单个Module进行编译,对于多Module工程中只需要编译其中一个Module的场景,可以提升编译构建速度;同时还新增支持一键重构建HAP包,即在编译构建HAP前,会自动执行Clean&nbsp;Project操作。<br/>**增强特性:**<br/>-&nbsp;编译构建插件更新至3.0.3.2版本。<br/>-&nbsp;Json编辑器增强,资源索引错误支持快速修复,并支持快速查看资源的取值。<br/>-&nbsp;工程视图支持Ohos视图,默认视图为Project视图,开发者可手动切换。<br/>-&nbsp;OpenHarmony工程支持ark方舟编译。<br/>-&nbsp;OpenHarmony工程类型标识字段supportSystem&nbsp;"standard",由模块级build.gradle调整至工程级build.gradle。 |
...@@ -2,14 +2,19 @@ ...@@ -2,14 +2,19 @@
- **[概述](deveco-studio-overview.md)** HUAWEI DevEco Studio For OpenHarmony(以下简称DevEco Studio)是基于IntelliJ IDEA Community开源版本打造,面向OpenHarmony全场景多设备的一站式集成开发环境(IDE),为开发者提供工程模板创建、开发、编译、调试、发布等E2E的OpenHarmony应用/服务开发。
- **[版本变更说明](deveco-studio-release-notes.md)** DevEco Studio 3.0 Beta3(于2022-3-30日发布)作为支撑Openharmony应用和服务开发的IDE,具有以下能力特点:
- **[配置OpenHarmony SDK](configuring-openharmony-sdk.md)** - 支持一站式的信息获取平台
- 提供多设备工程模板
- 高效的代码编辑
- 支持可视化的界面UI开发
- 双向、极速的界面UI预览
- 全新的编译工具Hvigor
- 支持基于设备系统能力集Syscap进行应用开发
- 支持全自动化的应用签名机制
- 丰富的代码调试调优能力
- **[创建OpenHarmony工程](create-openharmony-project.md)** 更多工具体验和使用指导请见:[DevEco Studio (OpenHarmony) 使用指南](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-deveco-studio-overview-0000001263280421)
- **[配置OpenHarmony应用签名信息](configuring-openharmony-app-signature.md)**
- **[安装运行OpenHarmony应用](installing-openharmony-app.md)**
\ No newline at end of file
# 通过导入Sample方式创建新工程
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 该功能适用于通过DevEco Studio 2.1 Release及以上版本,创建OpenHarmony工程。
OpenHarmony SDK配置完成后,便可以启动应用开发。针对OpenHarmony应用开发,**可以通过导入Sample工程的方式来创建一个新工程**
1. 在DevEco Studio的欢迎页,进入**Configure (或**![zh-cn_image_0000001118018452](figures/zh-cn_image_0000001118018452.png)**图标) &gt; Settings &gt; Version Control &gt; Git**界面,点击Test按钮检测是否安装Git工具。
- 已安装,请根据**步骤2**开始导入Sample。
![zh-cn_image_0000001118018088](figures/zh-cn_image_0000001118018088.png)
- 未安装,请点击**Download and Install**,DevEco Studio会自动下载并安装。安装完成后,请根据**步骤2**开始导入Sample。
![zh-cn_image_0000001164498191](figures/zh-cn_image_0000001164498191.png)
2. 在DevEco Studio的欢迎页,点击**Import Sample**按钮,导入Sample工程。
![zh-cn_image_0000001208006117](figures/zh-cn_image_0000001208006117.png)
3. 选择OpenHarmony Samples &gt; common下的**JsHelloWorld**工程,然后点击**Next**
![zh-cn_image_0000001152459178](figures/zh-cn_image_0000001152459178.png)
4. 设置**App Name****Project Location**,然后点击**Finish**,等待Sample工程导入完成。
![zh-cn_image_0000001207744539](figures/zh-cn_image_0000001207744539.png)
5. 等待工程同步完成,同步成功后,便可以进行OpenHarmony应用开发了。
![zh-cn_image_0000001163915523](figures/zh-cn_image_0000001163915523.png)
# 安装运行OpenHarmony应用
安装OpenHarmony应用可以通过DevEco Studio安装,也可以通过使用hdc工具进行手动安装。
- 通过DevEco Studio安装:将设备连接上DevEco Studio后,点击![zh-cn_image_0000001239855207](figures/zh-cn_image_0000001239855207.png)按钮即可安装。
- 通过hdc工具安装:手动执行命令行完成应用的安装。
hdc工具本身需要手动从开源仓中获取。然后使用工具将编译后的本地hap包发送至设备侧并完成安装。
相关命令如下:
- 安装命令
**install [-r/-d/-g] _package_**
命令示例:
```
hdc_std install E:\hwadmin.hap
```
- 日志抓取命令
**hilog**
命令示例:
```
hdc_std hilog
```
完整的hdc工具使用指导及命令格式请参见[hdc_std使用指导](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-toolchain-hdc-guide.md)
# 前言 # 开发准备
本文档适用于OpenHarmony应用开发的初学者。通过构建一个简单的具有页面跳转/返回功能的应用(如下图所示),快速了解工程目录的主要文件,熟悉OpenHarmony应用开发流程。 本文档适用于OpenHarmony应用开发的初学者。通过构建一个简单的具有页面跳转/返回功能的应用(如下图所示),快速了解工程目录的主要文件,熟悉OpenHarmony应用开发流程。
...@@ -15,23 +14,23 @@ ...@@ -15,23 +14,23 @@
### UI框架 ### UI框架
OpenHarmony提供了一套UI开发框架,即方舟开发框架(ArkUI框架)。方舟开发框架可为开发者提供进行应用UI开发时所必须的能力,比如多种组件、布局计算、动画能力、UI交互、绘制等等。 OpenHarmony提供了一套UI开发框架,即方舟开发框架(ArkUI框架)。方舟开发框架可为开发者提供应用UI开发所必须的能力,比如多种组件、布局计算、动画能力、UI交互、绘制等等。
方舟开发框架针对不同目的和技术背景的开发者提供了两种开发范式,分别是基于JS扩展的类Web开发范式(简称“类Web开发范式”)和基于TS扩展的声明式开发范式(简称“声明式开发范式”)。以下是两种开发范式的简单对比。 方舟开发框架针对不同目的和技术背景的开发者提供了两种开发范式,分别是基于JS扩展的类Web开发范式(简称“类Web开发范式”)和基于TS扩展的声明式开发范式(简称“声明式开发范式”)。以下是两种开发范式的简单对比。
| **开发范式名称** | **语言生态** | **UI更新方式** | **适用场景** | **适用人群** | | **开发范式名称** | **语言生态** | **UI更新方式** | **适用场景** | **适用人群** |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| 类Web开发范式 | JS语言 | 数据驱动更新 | 界面较为简单的类小程序应用和卡片 | Web前端开发人员 | | 类Web开发范式 | JS语言 | 数据驱动更新 | 界面较为简单的程序应用和卡片 | Web前端开发人员 |
| 声明式开发范式 | 扩展的TS语言(eTS) | 数据驱动更新 | 复杂度较大、团队合作度较高的程序 | 移动系统应用开发人员、系统应用开发人员 | | 声明式开发范式 | 扩展的TS语言(eTS) | 数据驱动更新 | 复杂度较大、团队合作度较高的程序 | 移动系统应用开发人员、系统应用开发人员 |
对于DevEco Studio V2.2 Beta1及更高版本,在使用JS语言开发时,除传统代码方式外,还支持使用低代码方式。OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS开发规范](../reference/apis),通过可视化界面开发方式快速构建布局,可有效降低用户的上手成本并提升用户构建UI界面的效率。 对于DevEco Studio V2.2 Beta1及更高版本,在使用JS语言开发时,除传统代码方式外,还支持使用低代码方式。OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS开发规范](../references/apis),通过可视化界面开发方式快速构建布局,可有效降低用户的上手成本并提升用户构建UI界面的效率。
### Ability ### Ability
[Ability](../ability/ability-brief.md)是应用所具备能力的抽象,也是应用程序的重要组成部分。一个应用可以具备多种能力(即可以包含多个Ability)。OpenHarmony支持应用以Ability为单位进行部署。 [Ability](../ability/ability-brief.md)是应用所具备能力的抽象,也是应用程序的重要组成部分。一个应用可以具备多种能力(即可以包含多个Ability)。OpenHarmony支持应用以Ability为单位进行部署。
Ability可以分为[FA(Feature Ability)](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/glossary/glossary.md#f)[PA(Particle Ability)](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/glossary/glossary.md#p)两种类型,每种类型为开发者提供了不同的模板,以便实现不同的业务功能。其中,FA支持[Page Ability](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/ability/fa-pageability.md)模板,以提供与用户交互的能力。一个Page Ability可以含有一个或多个页面(即Page),Page Ability与Page的关系如下图所示: Ability可以分为[FA(Feature Ability)](../../glossary.md#f)[PA(Particle Ability)](../../glossary.md#p)两种类型,每种类型为开发者提供了不同的模板,以便实现不同的业务功能。其中,FA支持[Page Ability](../ability/fa-pageability.md)模板,以提供与用户交互的能力。一个Page Ability可以含有一个或多个页面(即Page),Page Ability与Page的关系如下图所示:
![zh-cn_image_0000001215206886](figures/zh-cn_image_0000001215206886.png) ![zh-cn_image_0000001215206886](figures/zh-cn_image_0000001215206886.png)
...@@ -42,6 +41,6 @@ Ability可以分为[FA(Feature Ability)](https://gitee.com/openharmony/docs/ ...@@ -42,6 +41,6 @@ Ability可以分为[FA(Feature Ability)](https://gitee.com/openharmony/docs/
1. 安装最新版[DevEco Studio](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta) 1. 安装最新版[DevEco Studio](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)
2. 请参考[配置OpenHarmony SDK](configuring-openharmony-sdk.md),完成**DevEco Studio**的安装和开发环境配置。 2. 请参考[配置OpenHarmony SDK](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-setting-up-environment-0000001263160443),完成**DevEco Studio**的安装和开发环境配置。
完成上述操作及基本概念的理解后,可参照[使用eTS语言开发](start-with-ets.md)[使用JS语言开发(传统代码方式)](start-with-js.md)[使用JS语言开发(低代码方式)](start-with-js-low-code.md)中的任一章节进行下一步体验和学习。 完成上述操作及基本概念的理解后,可参照[使用eTS语言开发](start-with-ets.md)[使用JS语言开发(传统代码方式)](start-with-js.md)[使用JS语言开发(低代码方式)](start-with-js-low-code.md)中的任一章节进行下一步体验和学习。
...@@ -4,33 +4,35 @@ ...@@ -4,33 +4,35 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 请使用**DevEco Studio V3.0.0.601 Beta1**及更高版本。 > 请使用**DevEco Studio V3.0.0.601 Beta1**及更高版本。
> >
> 为确保运行效果,本文以使用**DevEco Studio V3.0.0.900 Beta2**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。 > 为确保运行效果,本文以使用**DevEco Studio V3.0.0.900 Beta3**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。
## 创建eTS工程 ## 创建eTS工程
1. 打开**DevEco Studio**,点击**File** &gt; **New &gt; Create Project**,选择模板“**Empty Ability**”,点击**Next**进行下一步配置。 1. 打开**DevEco Studio**,点击**File** &gt; **New &gt; Create Project**,选择模板“**Empty Ability**”,点击**Next**进行下一步配置。
![zh-cn_image_0000001260189591](figures/zh-cn_image_0000001260189591.png) ![zh-cn_image_0000001223556342](figures/zh-cn_image_0000001223556342.png)
2. 进入配置工程界面,**UI Syntax**选择“**eTS**”,其他参数保持默认设置即可。 2. 进入配置工程界面,**UI Syntax**选择“**eTS**”,其他参数保持默认设置即可。
![zh-cn_image_0000001217063248](figures/zh-cn_image_0000001217063248.png) ![zh-cn_image_0000001223716826](figures/zh-cn_image_0000001223716826.png)
3. 点击**Finish**,工具会自动生成示例代码和相关资源,等待工程创建完成。 3. 点击**Finish**,工具会自动生成示例代码和相关资源,等待工程创建完成。
## eTS工程项目文件 ## eTS工程项目文件
- **entry** :OpenHarmony工程模块,编译构建生成一个Hap包。 - **entry**:OpenHarmony工程模块,编译构建生成一个Hap包。
- **src &gt; main &gt; ets** :用于存放ets源码。 - **src &gt; main &gt; ets**:用于存放ets源码。
- **src &gt; main &gt; ets &gt; MainAbility** :应用/服务的入口。 - **src &gt; main &gt; ets &gt; MainAbility**:应用/服务的入口。
- **src &gt; main &gt; ets &gt; MainAbility &gt; pages** :MainAbility包含的页面。 - **src &gt; main &gt; ets &gt; MainAbility &gt; pages**:MainAbility包含的页面。
- **src &gt; main &gt; ets &gt; MainAbility &gt; app.ets** :承载Ability生命周期。 - **src &gt; main &gt; ets &gt; MainAbility &gt; app.ets**:承载Ability生命周期。
- **src &gt; main &gt; resources** :用于存放应用/服务所用到的资源文件,如图形、多媒体、字符串、布局文件等。 - **src &gt; main &gt; resources**:用于存放应用/服务所用到的资源文件,如图形、多媒体、字符串、布局文件等。
- **src &gt; main &gt;config.json** :模块配置文件。主要包含HAP包的配置信息、应用在具体设备上的配置信息以及应用的全局配置信息。 - **src &gt; main &gt; config.json**:模块配置文件。主要包含HAP包的配置信息、应用在具体设备上的配置信息以及应用的全局配置信息。
- **build-profile.json5** :模块的模块信息 、编译信息配置项,包括 buildOption target配置等。 - **build-profile.json5**:模块的模块信息 、编译信息配置项,包括 buildOption target配置等。
- **hvigorfile.js** :模块级编译构建任务脚本,开发者可以自定义相关任务和代码实现。 - **hvigorfile.js**:模块级编译构建任务脚本,开发者可以自定义相关任务和代码实现。
- **build-profile.json5** :应用级配置信息,包括签名、产品配置等。
- **hvigorfile.js** :应用级编译构建任务脚本。 - **build-profile.json5**:应用级配置信息,包括签名、产品配置等。
- **hvigorfile.js**:应用级编译构建任务脚本。
## 构建第一个页面 ## 构建第一个页面
...@@ -76,13 +78,14 @@ ...@@ -76,13 +78,14 @@
.fontSize(50) .fontSize(50)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
// 添加按钮,以接受用户点击 // 添加按钮,以接受用户点击
Button(){ Button() {
Text('Next') Text('Next')
.fontSize(30) .fontSize(30)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }
.type(ButtonType.Capsule)
.margin({ .margin({
top:20 top: 20
}) })
.backgroundColor('#0D9FFB') .backgroundColor('#0D9FFB')
.width('40%') .width('40%')
...@@ -95,8 +98,7 @@ ...@@ -95,8 +98,7 @@
} }
``` ```
3. **在编辑窗口右上角的侧边工具栏,点击Previewer,打开预览器。** 第一个页面效果如下图所示: 3. **在编辑窗口右上角的侧边工具栏,点击Previewer,打开预览器。**第一个页面效果如下图所示:
![zh-cn_image_0000001216239356](figures/zh-cn_image_0000001216239356.png) ![zh-cn_image_0000001216239356](figures/zh-cn_image_0000001216239356.png)
...@@ -105,39 +107,41 @@ ...@@ -105,39 +107,41 @@
1. **创建第二个页面。** 1. **创建第二个页面。**
在“**Project**”窗口,打开“**entry &gt; src &gt; main &gt; ets &gt; MainAbility**”,右键点击“**pages**”文件夹,选择“**New &gt; Page**”,命名为“**second**”,点击“**Finish**”,即完成第二个页面的创建。可以看到文件目录结构如下: 在“**Project**”窗口,打开“**entry &gt; src &gt; main &gt; ets &gt; MainAbility**”,右键点击“**pages**”文件夹,选择“**New &gt; Page**”,命名为“**second**”,点击“**Finish**”,即完成第二个页面的创建。可以看到文件目录结构如下:
![zh-cn_image_0000001261233671](figures/zh-cn_image_0000001261233671.png) ![zh-cn_image_0000001223397122](figures/zh-cn_image_0000001223397122.png)
2. **添加文本及按钮。** 2. **添加文本及按钮。**
参照第一个页面,在第二个页面添加Text组件、Button组件等,并设置其样式。“**second.ets**”文件的示例如下: 参照第一个页面,在第二个页面添加Text组件、Button组件等,并设置其样式。“**second.ets**”文件的示例如下:
``` ```
@Entry @Entry
@Component @Component
struct Second { struct Second {
@State message: string = 'Hi there' @State message: string = 'Hi there'
build() {
Row() { build() {
Column() { Row() {
Text(this.message) Column() {
.fontSize(50) Text(this.message)
.fontWeight(FontWeight.Bold) .fontSize(50)
Button() {
Text('Back')
.fontSize(25)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) Button() {
.margin({ Text('Back')
top: 20 .fontSize(25)
}) .fontWeight(FontWeight.Bold)
.backgroundColor('#0D9FFB') }
.width('40%') .type(ButtonType.Capsule)
.height('5%') .margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('40%')
.height('5%')
}
.width('100%')
} }
.width('100%') .height('100%')
} }
.height('100%')
}
} }
``` ```
...@@ -165,20 +169,21 @@ ...@@ -165,20 +169,21 @@
.fontSize(50) .fontSize(50)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
// 添加按钮,以接受用户点击 // 添加按钮,以接受用户点击
Button(){ Button() {
Text('Next') Text('Next')
.fontSize(30) .fontSize(30)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }
.type(ButtonType.Capsule)
.margin({ .margin({
top:20 top: 20
}) })
.backgroundColor('#0D9FFB') .backgroundColor('#0D9FFB')
.width('40%') .width('40%')
.height('5%') .height('5%')
// 跳转按钮绑定onClick事件,点击按钮时跳转到第二页 // 跳转按钮绑定onClick事件,点击时跳转到第二页
.onClick(()=>{ .onClick(() => {
router.push({uri:'pages/second'}) router.push({ uri: 'pages/second' })
}) })
} }
.width('100%') .width('100%')
...@@ -198,37 +203,39 @@ ...@@ -198,37 +203,39 @@
@Entry @Entry
@Component @Component
struct Second { struct Second {
@State message: string = 'Hi there' @State message: string = 'Hi there'
build() {
Row() { build() {
Column() { Row() {
Text(this.message) Column() {
.fontSize(50) Text(this.message)
.fontWeight(FontWeight.Bold) .fontSize(50)
Button() { .fontWeight(FontWeight.Bold)
Text('Back') Button() {
.fontSize(25) Text('Back')
.fontWeight(FontWeight.Bold) .fontSize(25)
}.type(ButtonType.Capsule) .fontWeight(FontWeight.Bold)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('40%')
.height('5%')
// 返回按钮绑定onClick事件,点击按钮时返回到第一页
.onClick(()=>{
router.back()
})
}
.width('100%')
} }
.height('100%') .type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('40%')
.height('5%')
// 返回按钮绑定onClick事件,点击按钮时返回到第一页
.onClick(() => {
router.back()
})
}
.width('100%')
} }
.height('100%')
}
} }
``` ```
3. **打开index.ets文件,点击预览器中的** ![zh-cn_image_0000001262219043](figures/zh-cn_image_0000001262219043.png) **按钮进行刷新。** 效果如下图所示: 3. **打开index.ets文件,点击预览器中的**![zh-cn_image_0000001262219043](figures/zh-cn_image_0000001262219043.png)**按钮进行刷新。**效果如下图所示:
![zh-cn_image_0000001260684127](figures/zh-cn_image_0000001260684127.png) ![zh-cn_image_0000001260684127](figures/zh-cn_image_0000001260684127.png)
...@@ -236,10 +243,10 @@ ...@@ -236,10 +243,10 @@
1. 将搭载OpenHarmony标准系统的开发板与电脑连接。 1. 将搭载OpenHarmony标准系统的开发板与电脑连接。
2. 点击**File &gt;Project Structure** &gt; **Project &gt; Signing**界面勾选“**Automatically generate signing**”,等待自动签名完成即可,点击“**OK**”。如下图所示: 2. 点击**File &gt;Project Structure** &gt; **Project &gt; SigningConfigs**界面勾选“**Automatically generate signing**”,等待自动签名完成即可,点击“**OK**”。如下图所示:
![zh-cn_image_0000001217365030](figures/zh-cn_image_0000001217365030.png) ![zh-cn_image_0000001268077317](figures/zh-cn_image_0000001268077317.png)
3. 在编辑窗口右上角的工具栏,点击![zh-cn_image_0000001262206247](figures/zh-cn_image_0000001262206247.png) 按钮运行。效果如下图所示: 3. 在编辑窗口右上角的工具栏,点击![zh-cn_image_0000001262206247](figures/zh-cn_image_0000001262206247.png)按钮运行。效果如下图所示:
![zh-cn_image_0000001217526428](figures/zh-cn_image_0000001217526428.png) ![zh-cn_image_0000001217526428](figures/zh-cn_image_0000001217526428.png)
恭喜您已经使用eTS语言开发完成了第一个OpenHarmony应用,来[探索更多的OpenHarmony功能](../application-dev-guide.md)吧。 恭喜您已经使用eTS语言开发完成了第一个OpenHarmony应用,[探索更多的OpenHarmony功能](../application-dev-guide.md)吧。
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 该特性在**DevEco Studio V2.2 Beta1**及更高版本中支持。 > 该特性在**DevEco Studio V2.2 Beta1**及更高版本中支持。
> >
> 为确保运行效果,本文以使用**DevEco Studio V3.0.0.900 Beta2**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。 > 为确保运行效果,本文以使用**DevEco Studio V3.0.0.900 Beta3**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。
OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS开发规范](../reference/apis/),通过可视化界面开发方式快速构建布局,可有效降低用户的上手成本并提升用户构建UI界面的效率。 OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS开发规范](../reference/apis),通过可视化界面开发方式快速构建布局,可有效降低用户的上手成本并提升用户构建UI界面的效率。
使用低代码开发应用或服务有以下两种开发方式: 使用低代码开发应用或服务有以下两种开发方式:
...@@ -24,10 +24,10 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS ...@@ -24,10 +24,10 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS
> 该功能在DevEco Studio 3.0 Beta2及更高版本中支持,且compileSdkVersion必须为7或以上。 > 该功能在DevEco Studio 3.0 Beta2及更高版本中支持,且compileSdkVersion必须为7或以上。
1. 打开**DevEco Studio**,点击**File** &gt; **New &gt; Create Project**,选择模板“**Empty Ability**”,点击**Next**进行下一步配置。 1. 打开**DevEco Studio**,点击**File** &gt; **New &gt; Create Project**,选择模板“**Empty Ability**”,点击**Next**进行下一步配置。
![zh-cn_image_0000001259949659](figures/zh-cn_image_0000001259949659.png) ![zh-cn_image_0000001268198893](figures/zh-cn_image_0000001268198893.png)
2. 进入配置工程界面,打开“**Super Visual Enable**”开关, **UI Syntax** 选择“**JS**”,其他参数保持默认设置即可。 2. 进入配置工程界面,打开“**Enable Visual Enable**”开关**,UI Syntax**选择“**JS**”,其他参数保持默认设置即可。
![zh-cn_image_0000001261786055](figures/zh-cn_image_0000001261786055.png) ![zh-cn_image_0000001223717294](figures/zh-cn_image_0000001223717294.png)
3. 点击**Finish**,工具会自动生成示例代码和相关资源,等待工程创建完成。 3. 点击**Finish**,工具会自动生成示例代码和相关资源,等待工程创建完成。
...@@ -36,14 +36,13 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS ...@@ -36,14 +36,13 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS
工程同步完成后,自动生成以下目录结构: 工程同步完成后,自动生成以下目录结构:
![zh-cn_image_0000001216753776](figures/zh-cn_image_0000001216753776.png) ![zh-cn_image_0000001223558810](figures/zh-cn_image_0000001223558810.png)
- **pages &gt; index &gt; index.js**:低代码页面的逻辑描述文件,定义了页面里所用到的所有的逻辑关系,比如数据、事件等,详情请参考[JS语法参考](../ui/js-framework-syntax-js.md)。如果创建了多个低代码页面,则pages目录下会生成多个页面文件夹及对应的js文件。 - **entry &gt; src &gt; main &gt; js &gt; MainAbility &gt; pages &gt; index &gt; index.js**:低代码页面的逻辑描述文件,定义了页面里所用到的所有的逻辑关系,比如数据、事件等,详情请参考[JS语法参考](../ui/js-framework-syntax-js.md)。如果创建了多个低代码页面,则pages目录下会生成多个页面文件夹及对应的js文件。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 使用低代码页面开发时,其关联js文件的同级目录中不能包含hml和css页面,例如上图中的**js &gt; MainAbility &gt; pages &gt; index**目录下不能包含hml与css文件,否则会出现编译报错。 > 使用低代码页面开发时,其关联js文件的同级目录中不能包含hml和css页面,例如上图中的**js &gt; MainAbility &gt; pages &gt; index**目录下不能包含hml与css文件,否则会出现编译报错。
- **pages &gt; index &gt; index.visual**:visual文件存储低代码页面的数据模型,双击该文件即可打开低代码页面,进行可视化开发设计。如果创建了多个低代码页面,则pages目录下会生成多个页面文件夹及对应的visual文件。 - **entry &gt; src &gt; main &gt; supervisual &gt; MainAbility &gt; pages &gt; index &gt; index.visual**:visual文件存储低代码页面的数据模型,双击该文件即可打开低代码页面,进行可视化开发设计。如果创建了多个低代码页面,则pages目录下会生成多个页面文件夹及对应的visual文件。
## 构建第一个页面 ## 构建第一个页面
...@@ -58,7 +57,7 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS ...@@ -58,7 +57,7 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS
![zh-cn_image_0000001216600980](figures/zh-cn_image_0000001216600980.gif) ![zh-cn_image_0000001216600980](figures/zh-cn_image_0000001216600980.gif)
2. **添加容器,设置Div容器的样式和属性。**<a name = add_container></a> 2. **添加容器,设置Div容器的样式和属性。**<a name = add_container></a>
选中UI Control中的Div组件,将其拖至画布。点击右侧属性样式栏中的样式图标![zh-cn_image_0000001260226691](figures/zh-cn_image_0000001260226691.png)(General),设置Div组件的高度Height为100%,使其占满屏幕;点击右侧属性样式栏中的样式图标![zh-cn_image_0000001215226858](figures/zh-cn_image_0000001215226858.png)(Flex),设置Div组件的FlexDirection样式为column,使Div的主轴垂直;设置Div组件的JustifyContent样式为center,使得其子组件在主轴上居中显示;设置Div组件的AlignItems样式为center,使得其子组件在交叉轴上居中显示。操作如下所示: 选中UI Control中的Div组件,将其拖至画布。点击右侧属性样式栏中的样式图标![zh-cn_image_0000001260226691](figures/zh-cn_image_0000001260226691.png)(General),设置Div组件的高度Height为100%,使其占满屏幕;点击右侧属性样式栏中的样式图标![zh-cn_image_0000001215226858](figures/zh-cn_image_0000001215226858.png)(Flex,设置Div组件的FlexDirection样式为column,使Div的主轴垂直;设置Div组件的JustifyContent样式为center,使得其子组件在主轴上居中显示;设置Div组件的AlignItems样式为center,使得其子组件在交叉轴上居中显示。操作如下所示:
![zh-cn_image_0000001216448880](figures/zh-cn_image_0000001216448880.gif) ![zh-cn_image_0000001216448880](figures/zh-cn_image_0000001216448880.gif)
...@@ -72,7 +71,7 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS ...@@ -72,7 +71,7 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS
![zh-cn_image_0000001260928361](figures/zh-cn_image_0000001260928361.gif) ![zh-cn_image_0000001260928361](figures/zh-cn_image_0000001260928361.gif)
5. **在编辑窗口右上角的侧边工具栏,点击Previewer,打开预览器。** 第一个页面效果如下图所示: 5. **在编辑窗口右上角的侧边工具栏,点击Previewer,打开预览器。**第一个页面效果如下图所示:
![zh-cn_image_0000001216288558](figures/zh-cn_image_0000001216288558.png) ![zh-cn_image_0000001216288558](figures/zh-cn_image_0000001216288558.png)
...@@ -81,11 +80,11 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS ...@@ -81,11 +80,11 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS
1. **创建第二个页面。** 1. **创建第二个页面。**
在“**Project**”窗口,打开“**entry &gt; src &gt; main &gt; js &gt; MainAbility**”,右键点击“**pages**”文件夹,选择“**New &gt; Visual**”,命名为“**second**”,单击“**Finish**”,即完成第二个页面的创建。可以看到文件目录结构如下: 在“**Project**”窗口,打开“**entry &gt; src &gt; main &gt; js &gt; MainAbility**”,右键点击“**pages**”文件夹,选择“**New &gt; Visual**”,命名为“**second**”,单击“**Finish**”,即完成第二个页面的创建。可以看到文件目录结构如下:
![zh-cn_image_0000001261129245](figures/zh-cn_image_0000001261129245.png) ![zh-cn_image_0000001223882030](figures/zh-cn_image_0000001223882030.png)
2. **[删除画布原有模板组件。](#delete_origin_content)** 2. **[删除画布原有模板组件。](#delete_origin_content)**
3. **[添加容器,设置Div容器的样式和属性](#add_container)** 3. **[添加容器,设置Div容器的样式和属性](#add_container)**
4. **添加文本。** 4. **添加文本。**
选中Text组件,拖至Div组件的中央区域。点击右侧属性样式栏中的属性图标![zh-cn_image_0000001260227453](figures/zh-cn_image_0000001260227453.png)(Properties),设置Text组件的Content属性为“Hi there”;点击右侧属性样式栏中的样式图标![zh-cn_image_0000001260107497](figures/zh-cn_image_0000001260107497.png)(Feature),设置组件的FontSize样式为60px;设置组件的TextAlign样式为center。再选中画布上的Text组件,拖动放大。操作如下所示: 选中Text组件,拖至Div组件的中央区域。点击右侧属性样式栏中的属性图标![zh-cn_image_0000001260227453](figures/zh-cn_image_0000001260227453.png)(Properties),设置Text组件的Content属性为“Hi there”;点击右侧属性样式栏中的样式图标![zh-cn_image_0000001260107497](figures/zh-cn_image_0000001260107497.png)(Feature),设置组件的FontSize样式为60px;设置组件的TextAlign样式为center。再选中画布上的Text组件,拖动放大。操作如下所示:
...@@ -104,7 +103,6 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS ...@@ -104,7 +103,6 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS
1. **第一个页面跳转到第二个页面。** 1. **第一个页面跳转到第二个页面。**
在第一个页面中,跳转按钮绑定onclick方法,点击按钮时跳转到第二页。需同时处理js文件及visual文件。 在第一个页面中,跳转按钮绑定onclick方法,点击按钮时跳转到第二页。需同时处理js文件及visual文件。
-**index.js**”示例如下: -**index.js**”示例如下:
``` ```
...@@ -119,10 +117,9 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS ...@@ -119,10 +117,9 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS
} }
``` ```
-**index.viusal**”: 打开index.visual,选中画布上的Button组件。点击右侧属性样式栏中的事件图标![zh-cn_image_0000001215388136](figures/zh-cn_image_0000001215388136.png)(Events),鼠标点击Click事件的输入框,选择onclick,如下所示: -**index.viusal**”: 打开index.visual,选中画布上的Button组件。点击右侧属性样式栏中的事件图标![zh-cn_image_0000001215388136](figures/zh-cn_image_0000001215388136.png)(Events),鼠标点击Click事件的输入框,选择onclick,如下所示:
![zh-cn_image_0000001223722586](figures/zh-cn_image_0000001223722586.png)
![zh-cn_image_0000001261137889](figures/zh-cn_image_0000001261137889.png)
2. **第二个页面返回到第一个页面。** 2. **第二个页面返回到第一个页面。**
在第二个页面中,返回按钮绑定back方法,点击按钮时返回到第一页。 在第二个页面中,返回按钮绑定back方法,点击按钮时返回到第一页。
...@@ -141,9 +138,9 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS ...@@ -141,9 +138,9 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS
``` ```
-**second.viusal**”: 打开second.visual,选中画布上的Button组件。点击右侧属性样式栏中的事件图标![zh-cn_image_0000001215388262](figures/zh-cn_image_0000001215388262.png)(Events),鼠标点击Click事件的输入框,选择back,如下所示: -**second.viusal**”: 打开second.visual,选中画布上的Button组件。点击右侧属性样式栏中的事件图标![zh-cn_image_0000001215388262](figures/zh-cn_image_0000001215388262.png)(Events),鼠标点击Click事件的输入框,选择back,如下所示:
![zh-cn_image_0000001216618320](figures/zh-cn_image_0000001216618320.png) ![zh-cn_image_0000001268082945](figures/zh-cn_image_0000001268082945.png)
3. **打开index.visual或index.js文件,点击预览器中的** ![zh-cn_image_0000001261979271](figures/zh-cn_image_0000001261979271.png) **按钮进行刷新。** 效果如下图所示: 3. **打开index.visual或index.js文件,点击预览器中的**![zh-cn_image_0000001261979271](figures/zh-cn_image_0000001261979271.png)**按钮进行刷新。**效果如下图所示:
![zh-cn_image_0000001261142799](figures/zh-cn_image_0000001261142799.png) ![zh-cn_image_0000001261142799](figures/zh-cn_image_0000001261142799.png)
...@@ -151,11 +148,10 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS ...@@ -151,11 +148,10 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,遵循[JS
1. 将搭载OpenHarmony标准系统的开发板与电脑连接。 1. 将搭载OpenHarmony标准系统的开发板与电脑连接。
2. 点击**File &gt;Project Structure** &gt; **Project &gt; Signing**界面勾选“**Automatically generate signing**”,等待自动签名完成即可,点击“**OK**”。如下图所示: 2. 点击**File &gt;Project Structure** &gt; **Project &gt; Signing Configs**界面勾选“**Automatically generate signing**”,等待自动签名完成即可,点击“**OK**”。如下图所示:
![zh-cn_image_0000001217527948](figures/zh-cn_image_0000001217527948.png) ![zh-cn_image_0000001268283201](figures/zh-cn_image_0000001268283201.png)
3. 在编辑窗口右上角的工具栏,点击![zh-cn_image_0000001262207811](figures/zh-cn_image_0000001262207811.png)按钮运行效果如下图所示:
3. 在编辑窗口右上角的工具栏,点击![zh-cn_image_0000001262207811](figures/zh-cn_image_0000001262207811.png)按钮运行。效果如下图所示:
![zh-cn_image_0000001262127855](figures/zh-cn_image_0000001262127855.png) ![zh-cn_image_0000001262127855](figures/zh-cn_image_0000001262127855.png)
恭喜您已经使用JS语言开发(低代码方式)完成了第一个OpenHarmony应用,来[探索更多的OpenHarmony功能](../application-dev-guide.md)吧。 恭喜您已经使用JS语言开发(低代码方式)完成了第一个OpenHarmony应用,[探索更多的OpenHarmony功能](../application-dev-guide.md)吧。
...@@ -2,34 +2,37 @@ ...@@ -2,34 +2,37 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 为确保运行效果,本文以使用**DevEco Studio V3.0.0.900 Beta2**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。 > 为确保运行效果,本文以使用**DevEco Studio V3.0.0.900 Beta3**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。
## 创建JS工程 ## 创建JS工程
1. 打开**DevEco Studio**,点击**File** &gt; **New &gt; Create Project**,选择模板“**Empty Ability**”,点击**Next**进行下一步配置。 1. 打开**DevEco Studio**,点击**File** &gt; **New &gt; Create Project**,选择模板“**Empty Ability**”,点击**Next**进行下一步配置。
![zh-cn_image_0000001215029852](figures/zh-cn_image_0000001215029852.png) ![zh-cn_image_0000001223558814](figures/zh-cn_image_0000001223558814.png)
2. 进入配置工程界面,**UI Syntax**选择“**JS**”,其他参数保持默认设置即可。 2. 进入配置工程界面,**UI Syntax**选择“**JS**”,其他参数保持默认设置即可。
![zh-cn_image_0000001217384890](figures/zh-cn_image_0000001217384890.png) ![zh-cn_image_0000001223877162](figures/zh-cn_image_0000001223877162.png)
3. 点击**Finish**,工具会自动生成示例代码和相关资源,等待工程创建完成。 3. 点击**Finish**,工具会自动生成示例代码和相关资源,等待工程创建完成。
## JS工程项目文件 ## JS工程项目文件
- **entry:** OpenHarmony工程模块,编译构建生成一个Hap包。 - **entry**:OpenHarmony工程模块,编译构建生成一个Hap包。
- **src &gt; main &gt; js** :用于存放js源码。 - **src &gt; main &gt; js**:用于存放js源码。
- **src &gt; main &gt; js &gt; MainAbility** :应用/服务的入口。 - **src &gt; main &gt; js &gt; MainAbility**:应用/服务的入口。
- **src &gt; main &gt; js &gt; MainAbility &gt; i18n** :用于配置不同语言场景资源内容,比如应用文本词条、图片路径资源等。 - **src &gt; main &gt; js &gt; MainAbility &gt; i18n**:用于配置不同语言场景资源内容,比如应用文本词条、图片路径等资源。
- **src &gt; main &gt; js &gt; MainAbility &gt; pages** :MainAbility包含的页面。 - **src &gt; main &gt; js &gt; MainAbility &gt; pages**:MainAbility包含的页面。
- **src &gt; main &gt; js &gt; MainAbility &gt; app.js** :承载Ability生命周期。 - **src &gt; main &gt; js &gt; MainAbility &gt; app.js**:承载Ability生命周期。
- **src &gt; main &gt; resources** :用于存放应用/服务所用到的资源文件,如图形、多媒体、字符串、布局文件等。
- **src &gt; main &gt; config.json** :模块配置文件。主要包含HAP包的配置信息、应用在具体设备上的配置信息以及应用的全局配置信息。 - **src &gt; main &gt; resources**:用于存放应用/服务所用到的资源文件,如图形、多媒体、字符串、布局文件等。
- **build-profile.json5** :模块的模块信息 、编译信息配置项,包括 buildOption target配置等。 - **src &gt; main &gt; config.json**:模块配置文件。主要包含HAP包的配置信息、应用在具体设备上的配置信息以及应用的全局配置信息。
- **hvigorfile.js** :模块级编译构建任务脚本,开发者可以自定义相关任务和代码实现。 - **build-profile.json5**:模块的模块信息 、编译信息配置项,包括 buildOption target配置等。
- **build-profile.json5** :应用级配置信息,包括签名、产品配置等。 - **hvigorfile.js**:模块级编译构建任务脚本,开发者可以自定义相关任务和代码实现。
- **hvigorfile.js** :应用级编译构建任务脚本。
- **build-profile.json5**:应用级配置信息,包括签名、产品配置等。
- **hvigorfile.js**:应用级编译构建任务脚本。
## 构建第一个页面 ## 构建第一个页面
...@@ -55,7 +58,8 @@ ...@@ -55,7 +58,8 @@
<text class="title"> <text class="title">
Hello World Hello World
</text> </text>
<!-- 添加按钮,值为Next,并绑定onclick方法-->
<!-- 添加按钮,值为Next,并绑定onclick方法-->
<input class="btn" type="button" value="Next" onclick="onclick"></input> <input class="btn" type="button" value="Next" onclick="onclick"></input>
</div> </div>
``` ```
...@@ -83,7 +87,8 @@ ...@@ -83,7 +87,8 @@
width: 100%; width: 100%;
margin: 10px; margin: 10px;
} }
.btn{
.btn {
font-size: 60px; font-size: 60px;
font-weight: bold; font-weight: bold;
text-align: center; text-align: center;
...@@ -93,7 +98,7 @@ ...@@ -93,7 +98,7 @@
} }
``` ```
4. **在编辑窗口右上角的侧边工具栏,点击Previewer,打开预览器。** 第一个页面效果如下图所示: 4. **在编辑窗口右上角的侧边工具栏,点击Previewer,打开预览器。**第一个页面效果如下图所示:
![zh-cn_image_0000001216084724](figures/zh-cn_image_0000001216084724.png) ![zh-cn_image_0000001216084724](figures/zh-cn_image_0000001216084724.png)
...@@ -103,7 +108,7 @@ ...@@ -103,7 +108,7 @@
1. **创建第二个页面。** 1. **创建第二个页面。**
在“**Project**”窗口,打开“**entry &gt; src &gt; main &gt; js &gt; MainAbility**”,右键点击“**pages**”文件夹,选择“**New &gt; Page**”,命名为“**second**”,点击“**Finish**”,即完成第二个页面的创建。可以看到文件目录结构如下: 在“**Project**”窗口,打开“**entry &gt; src &gt; main &gt; js &gt; MainAbility**”,右键点击“**pages**”文件夹,选择“**New &gt; Page**”,命名为“**second**”,点击“**Finish**”,即完成第二个页面的创建。可以看到文件目录结构如下:
![zh-cn_image_0000001261233695](figures/zh-cn_image_0000001261233695.png) ![zh-cn_image_0000001223877210](figures/zh-cn_image_0000001223877210.png)
2. **添加文本及按钮。** 2. **添加文本及按钮。**
参照第一个页面,在第二个页面添加文本、按钮及点击按钮绑定页面返回等。“**second.hml**”文件的示例如下: 参照第一个页面,在第二个页面添加文本、按钮及点击按钮绑定页面返回等。“**second.hml**”文件的示例如下:
...@@ -111,11 +116,12 @@ ...@@ -111,11 +116,12 @@
``` ```
<div class="container"> <div class="container">
<text class="title"> <text class="title">
Hi there Hi there
</text> </text>
<!-- 添加按钮,值为Back,并绑定back方法-->
<input class="btn" type="button" value="Back" onclick="back"></input> <!-- 添加按钮,值为Back,并绑定back方法-->
<input class="btn" type="button" value="Back" onclick="back"></input>
</div> </div>
``` ```
...@@ -123,37 +129,38 @@ ...@@ -123,37 +129,38 @@
``` ```
.container { .container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
left: 0px; left: 0px;
top: 0px; top: 0px;
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.title { .title {
font-size: 100px; font-size: 100px;
font-weight: bold; font-weight: bold;
text-align: center; text-align: center;
width: 100%; width: 100%;
margin: 10px; margin: 10px;
} }
.btn{
font-size: 60px; .btn {
font-weight: bold; font-size: 60px;
text-align: center; font-weight: bold;
width: 40%; text-align: center;
height: 5%; width: 40%;
margin-top: 20px; height: 5%;
margin-top: 20px;
} }
``` ```
## 实现页面间的跳转 ## 实现页面间的跳转
页面间的导航可以通过[页面路由router](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/ui-js-building-ui-routes.md)来实现。页面路由router根据页面uri找到目标页面,从而实现跳转。使用页面路由请导入router模块。 页面间的导航可以通过[页面路由router](../ui/ui-js-building-ui-routes.md)来实现。页面路由router根据页面uri找到目标页面,从而实现跳转。使用页面路由请导入router模块。
1. **第一个页面跳转到第二个页面。** 1. **第一个页面跳转到第二个页面。**
在第一个页面中,跳转按钮绑定onclick方法,点击按钮时跳转到第二页。“**index.js**”示例如下: 在第一个页面中,跳转按钮绑定onclick方法,点击按钮时跳转到第二页。“**index.js**”示例如下:
...@@ -185,7 +192,7 @@ ...@@ -185,7 +192,7 @@
} }
``` ```
3. **打开index文件夹下的任意一个文件,点击预览器中的** ![zh-cn_image_0000001262339067](figures/zh-cn_image_0000001262339067.png) **按钮进行刷新。** 效果如下图所示: 3. **打开index文件夹下的任意一个文件,点击预览器中的**![zh-cn_image_0000001262339067](figures/zh-cn_image_0000001262339067.png)**按钮进行刷新。**效果如下图所示:
![zh-cn_image_0000001216269940](figures/zh-cn_image_0000001216269940.png) ![zh-cn_image_0000001216269940](figures/zh-cn_image_0000001216269940.png)
...@@ -193,10 +200,10 @@ ...@@ -193,10 +200,10 @@
1. 将搭载OpenHarmony标准系统的开发板与电脑连接。 1. 将搭载OpenHarmony标准系统的开发板与电脑连接。
2. 点击**File &gt;Project Structure** &gt; **Project &gt; Signing**界面勾选“**Automatically generate signing**”,等待自动签名完成即可,点击“**OK**”。如下图所示: 2. 点击**File &gt;Project Structure** &gt; **Project &gt; Signing Configs**界面勾选“**Automatically generate signing**”,等待自动签名完成即可,点击“**OK**”。如下图所示:
![zh-cn_image_0000001262327095](figures/zh-cn_image_0000001262327095.png) ![zh-cn_image_0000001223557290](figures/zh-cn_image_0000001223557290.png)
3. 在编辑窗口右上角的工具栏,点击![zh-cn_image_0000001217047316](figures/zh-cn_image_0000001217047316.png) 按钮运行。效果如下图所示: 3. 在编辑窗口右上角的工具栏,点击![zh-cn_image_0000001217047316](figures/zh-cn_image_0000001217047316.png)按钮运行。效果如下图所示:
![zh-cn_image_0000001217527892](figures/zh-cn_image_0000001217527892.png) ![zh-cn_image_0000001217527892](figures/zh-cn_image_0000001217527892.png)
恭喜您已经使用JS语言开发(传统代码方式)完成了第一个OpenHarmony应用,来[探索更多的OpenHarmony功能](../application-dev-guide.md)吧。 恭喜您已经使用JS语言开发(传统代码方式)完成了第一个OpenHarmony应用,[探索更多的OpenHarmony功能](../application-dev-guide.md)吧。
# 使用工程向导创建新工程
- [前提条件](#前提条件)
- [操作步骤](#操作步骤)
通过工程向导创建一个OpenHarmony工程,该功能只有DevEco Studio 2.2 Beta1及以上版本支持。如果是DevEco Studio 2.1 Release版本,请根据[通过导入Sample方式创建新工程](../quick-start/import-sample-to-create-project.md)进行操作。
## 前提条件
已安装OpenHarmony SDK,具体请参考[配置OpenHarmony SDK](../quick-start/configuring-openharmony-sdk.md)
## 操作步骤
1. 通过如下两种方式,打开工程创建向导界面。
- 如果当前未打开任何工程,可以在DevEco Studio的欢迎页,选择**Create Project**开始创建一个新工程。
- 如果已经打开了工程,可以在菜单栏选择**File &gt; New &gt; New Project**来创建一个新工程。
2. 根据工程创建向导,选择“[Standard]Empty Ability”模板,点击**Next**
![zh-cn_image_0000001162463400](figures/zh-cn_image_0000001162463400.png)
3. 点击**Next**,进入到工程配置阶段,需要根据向导配置工程的基本信息。
- **Project name**:工程的名称,可以自定义。
- **Project type**:工程的类型,标识该工程是一个[原子化服务](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/atomic-service-definition-0000001090840664)(Service)或传统方式的需要安装的应用(Application)。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 如果是创建的原子化服务,则:
>
> - 原子化服务调试、运行时,在设备桌面上没有应用图标,请使用DevEco Studio的调试和运行功能,来启动原子化服务。
>
> - 原子化服务是免安装的,config.json中自动添加**installationFree**字段,取值为“true”。
>
> - 如果entry模块的**installationFree**字段为true,则其相关的所有hap模块的**installationFree**字段都默认为true;如果entry模块的**installationFree**字段为false,则其相关的所有hap模块可以配置为true或false。
>
> - 编译构建App时,每个hap包大小不能超过10MB。
- **Bundle name**:软件包名称,默认情况下,应用ID也会使用该名称,应用发布时,应用ID需要唯一。如果“Project Type”选择了Atomic Service,则Bundle Name的后缀名必须是.hmservice。
- **Save Location**:工程文件本地存储路径。
- **Development mode**:选择开发模式,部分模板支持低代码开发,可选择Super Visual。
- **Language**:支持的开发语言。
- **Compatible API Version**:兼容的SDK最低版本。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> OpenHarmony工程如果配置了compileSdkVersion 7以上,对应模块默认使用方舟编译器进行编译,如果要修改编译方式为非方舟编译,在模块级build.gradle的**ohos**闭包中添加**arkEnable false**字段。
- **Device Type**:该工程模板支持的设备类型。
![zh-cn_image_0000001196050928](figures/zh-cn_image_0000001196050928.png)
4. 点击**Finish**,工具会自动生成示例代码和相关资源,等待工程创建完成。
...@@ -76,7 +76,7 @@ ATM(AccessTokenManager)是OpenHarmony上基于AccessToken构建的统一的应 ...@@ -76,7 +76,7 @@ ATM(AccessTokenManager)是OpenHarmony上基于AccessToken构建的统一的应
默认情况下,应用的APL等级都为normal等级,如果应用需要将自身的APL等级声明为system_basic及以上的APL等级,需要进行以下步骤: 默认情况下,应用的APL等级都为normal等级,如果应用需要将自身的APL等级声明为system_basic及以上的APL等级,需要进行以下步骤:
- 申请应用市场审核并通过。 - 申请应用市场审核并通过。
- 开发应用安装包时,需要修改应用的profile文件,在文件的"apl"字段声明应用的APL等级,并使用profile签名工具生成证书。具体签名流程可以查看页面[配置OpenHarmony应用签名信息](../quick-start/configuring-openharmony-app-signature.md) - 开发应用安装包时,需要修改应用的profile文件,在文件的"apl"字段声明应用的APL等级,并使用profile签名工具生成证书。具体签名流程可以查看页面[配置OpenHarmony应用签名信息](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-debugging-and-running-0000001263040487#section17660437768)
### 权限等级说明 ### 权限等级说明
...@@ -173,7 +173,7 @@ ACL方式的工作流程可以参考[ACL方式使用说明](#ACL方式使用说 ...@@ -173,7 +173,7 @@ ACL方式的工作流程可以参考[ACL方式使用说明](#ACL方式使用说
**ACL申请方式须知** **ACL申请方式须知**
* 申请应用市场审核并通过。 * 申请应用市场审核并通过。
* 开发应用安装包时,需要修改应用的profile文件,在文件的"acl"字段声明目标的访问控制列表,并使用profile签名工具生成证书。具体签名流程可以查看页面[配置OpenHarmony应用签名信息](../quick-start/configuring-openharmony-app-signature.md) * 开发应用安装包时,需要修改应用的profile文件,在文件的"acl"字段声明目标的访问控制列表,并使用profile签名工具生成证书。具体签名流程可以查看页面[配置OpenHarmony应用签名信息](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-debugging-and-running-0000001263040487#section17660437768)
## 权限定义列表 ## 权限定义列表
......
...@@ -61,6 +61,6 @@ ...@@ -61,6 +61,6 @@
8. 应用安装到手机上运行应用。将手机连接电脑,等IDE识别到物理设备后,点击Run 'entry'按钮。 8. 应用安装到手机上运行应用。将手机连接电脑,等IDE识别到物理设备后,点击Run 'entry'按钮。
![zh-cn_image_0000001148858818](figures/zh-cn_image_0000001148858818.png) ![zh-cn_image_0000001148858818](figures/zh-cn_image_0000001148858818.png)
在安装之前,需要配置应用签名,[配置应用签名教程](../quick-start/configuring-openharmony-app-signature.md)。安装成功后,点击屏幕上的Run图标打开应用,可以看到居中加粗显示的“Hello World”。 在安装之前,需要[配置应用签名](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-debugging-and-running-0000001263040487#section17660437768)。安装成功后,点击屏幕上的Run图标打开应用,可以看到居中加粗显示的“Hello World”。
![zh-cn_image_0000001158896538](figures/zh-cn_image_0000001158896538.png) ![zh-cn_image_0000001158896538](figures/zh-cn_image_0000001158896538.png)
# OpenHarmony应用开发文档 # OpenHarmony应用开发文档
- [应用开发导读](application-dev-guide.md) - [应用开发导读](application-dev-guide.md)
- 快速开始 - 快速开始
- 应用开发快速入门
- DevEco Studio(OpenHarmony)使用指南 - 快速入门
- [概述](quick-start/deveco-studio-overview.md) - [前言](quick-start/start-overview.md)
- [版本变更说明](quick-start/deveco-studio-release-notes.md) - [使用eTS语言开发](quick-start/start-with-ets.md)
- [配置OpenHarmony SDK](quick-start/configuring-openharmony-sdk.md) - [使用JS语言开发(传统代码方式)](quick-start/start-with-js.md)
- 创建OpenHarmony工程 - [使用JS语言开发(低代码方式)](quick-start/start-with-js-low-code.md)
- [使用工程向导创建新工程](quick-start/use-wizard-to-create-project.md)
- [通过导入Sample方式创建新工程](quick-start/import-sample-to-create-project.md) - 开发基础知识
- [配置OpenHarmony应用签名信息](quick-start/configuring-openharmony-app-signature.md) - [应用开发包结构说明](quick-start/package-structure.md)
- [安装运行OpenHarmony应用](quick-start/installing-openharmony-app.md) - [资源文件的分类](quick-start/basic-resource-file-categories.md)
- 快速入门
- [前言](quick-start/start-overview.md)
- [使用eTS语言开发](quick-start/start-with-ets.md)
- [使用JS语言开发(传统代码方式)](quick-start/start-with-js.md)
- [使用JS语言开发(低代码方式)](quick-start/start-with-js-low-code.md)
- [应用开发包结构说明](quick-start/package-structure.md)
- [资源文件的分类](quick-start/basic-resource-file-categories.md)
- 开发 - 开发
- Ability开发 - Ability开发
- [Ability框架概述](ability/ability-brief.md) - [Ability框架概述](ability/ability-brief.md)
...@@ -88,7 +83,7 @@ ...@@ -88,7 +83,7 @@
- [Qrcode开发指导](ui/ui-js-components-qrcode.md) - [Qrcode开发指导](ui/ui-js-components-qrcode.md)
- [Search开发指导](ui/ui-js-components-search.md) - [Search开发指导](ui/ui-js-components-search.md)
- Canvas开发指导 - Canvas开发指导
- [Canvas对象](ui-js-components-canvas.md) - [Canvas对象](ui/ui-js-components-canvas.md)
- [CanvasRenderingContext2D对象](ui/ui-js-components-canvasrenderingcontext2d.md) - [CanvasRenderingContext2D对象](ui/ui-js-components-canvasrenderingcontext2d.md)
- [Path2D对象](ui/ui-js-components-path2d.md) - [Path2D对象](ui/ui-js-components-path2d.md)
- [OffscreenCanvas对象](ui/ui-js-components-offscreencanvas.md) - [OffscreenCanvas对象](ui/ui-js-components-offscreencanvas.md)
...@@ -275,17 +270,14 @@ ...@@ -275,17 +270,14 @@
- [国际化开发概述](internationalization/international-overview.md) - [国际化开发概述](internationalization/international-overview.md)
- [Intl开发指导](internationalization/intl-guidelines.md) - [Intl开发指导](internationalization/intl-guidelines.md)
- [I18n开发指导](internationalization/i18n-guidelines.md) - [I18n开发指导](internationalization/i18n-guidelines.md)
- 工具 - 工具
- DevEco Studio(OpenHarmony)使用指南 - [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md)
- [概述](quick-start/deveco-studio-overview.md)
- [版本变更说明](quick-start/deveco-studio-release-notes.md)
- [配置OpenHarmony SDK](quick-start/configuring-openharmony-sdk.md)
- [创建OpenHarmony工程](quick-start/create-openharmony-project.md)
- [配置OpenHarmony应用签名信息](quick-start/configuring-openharmony-app-signature.md)
- [安装运行OpenHarmony应用](quick-start/installing-openharmony-app.md)
- 示例教程 - 示例教程
- [示例代码](https://gitee.com/openharmony/app_samples/blob/master/README_zh.md) - [示例代码](https://gitee.com/openharmony/app_samples/blob/master/README_zh.md)
- [Codelabs](https://gitee.com/openharmony/codelabs/blob/master/README.md) - [Codelabs](https://gitee.com/openharmony/codelabs/blob/master/README.md)
- API参考 - API参考
- 组件参考(基于JS扩展的类Web开发范式) - 组件参考(基于JS扩展的类Web开发范式)
- 组件 - 组件
...@@ -611,10 +603,10 @@ ...@@ -611,10 +603,10 @@
- [升级](reference/apis/js-apis-update.md) - [升级](reference/apis/js-apis-update.md)
- [USB管理](reference/apis/js-apis-usb.md) - [USB管理](reference/apis/js-apis-usb.md)
- [位置服务](reference/apis/js-apis-geolocation.md) - [位置服务](reference/apis/js-apis-geolocation.md)
- [输入设备](js-apis-inputdevice.md) - [输入设备](reference/apis/js-apis-inputdevice.md)
- [组合按键](js-apis-inputconsumer.md) - [组合按键](reference/apis/js-apis-inputconsumer.md)
- [输入监听](js-apis-inputmonitor.md) - [输入监听](reference/apis/js-apis-inputmonitor.md)
- [事件注入](js-apis-inputeventclient.md) - [事件注入](reference/apis/js-apis-inputeventclient.md)
- 基本功能 - 基本功能
- [应用上下文](reference/apis/js-apis-system-app.md) - [应用上下文](reference/apis/js-apis-system-app.md)
- [日志打印](reference/apis/js-apis-logs.md) - [日志打印](reference/apis/js-apis-logs.md)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册