提交 c8287b7b 编写于 作者: L lijialang

Merge branch 'OpenHarmony-3.2-Beta5' of https://gitee.com/lijialang/docs into OpenHarmony-3.2-Beta5

......@@ -42,13 +42,13 @@ arkXtest is divided into two parts: unit test framework and UI test framework.
- The feature availability of the unit test framework varies by version. For details about the mappings between the features and versions, see [arkXtest](https://gitee.com/openharmony/testfwk_arkxtest/blob/master/README_en.md).
## Environment preparations
## Preparing the Environment
### Environment Requirements
Software for writing test scripts: DevEco Studio 3.0 or later
Hardware for running test scripts: PC connected to a OpenHarmony device, such as the RK3568 development board
Hardware for running test scripts: PC connected to an OpenHarmony device, such as the RK3568 development board
### Setting Up the Environment
......@@ -63,8 +63,8 @@ Hardware for running test scripts: PC connected to a OpenHarmony device, such as
## Writing a Unit Test Script
```TS
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import abilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
const delegator = abilityDelegatorRegistry.getAbilityDelegator()
export default function abilityTest() {
......@@ -72,7 +72,7 @@ export default function abilityTest() {
it('testUiExample',0, async function (done) {
console.info("uitest: TestUiExample begin");
//start tested ability
await delegator.executeShellCommand('aa start -b com.ohos.uitest -a MainAbility').then(result =>{
await delegator.executeShellCommand('aa start -b com.ohos.uitest -a EntryAbility').then(result =>{
console.info('Uitest, start ability finished:' + result)
}).catch(err => {
console.info('Uitest, start ability failed: ' + err)
......@@ -81,7 +81,7 @@ export default function abilityTest() {
//check top display ability
await delegator.getCurrentTopAbility().then((Ability)=>{
console.info("get top ability");
expect(Ability.context.abilityInfo.name).assertEqual('MainAbility');
expect(Ability.context.abilityInfo.name).assertEqual('EntryAbility');
})
done();
})
......@@ -119,7 +119,7 @@ export default function abilityTest() {
it('testUiExample',0, async function (done) {
console.info("uitest: TestUiExample begin");
//start tested ability
await delegator.executeShellCommand('aa start -b com.ohos.uitest -a MainAbility').then(result =>{
await delegator.executeShellCommand('aa start -b com.ohos.uitest -a EntryAbility').then(result =>{
console.info('Uitest, start ability finished:' + result)
}).catch(err => {
console.info('Uitest, start ability failed: ' + err)
......@@ -128,7 +128,7 @@ export default function abilityTest() {
//check top display ability
await delegator.getCurrentTopAbility().then((Ability)=>{
console.info("get top ability");
expect(Ability.context.abilityInfo.name).assertEqual('MainAbility');
expect(Ability.context.abilityInfo.name).assertEqual('EntryAbility');
})
//ui test code
//init uidriver
......@@ -154,20 +154,180 @@ export default function abilityTest() {
## Running the Test Script
### In DevEco Studio
You can run a test script in DevEco Studio in any of the following modes:
- Test package level: All test cases in the test package are executed.
- Test suite level: All test cases defined in the **describe** method are executed.
- Test method level: The specified **it** method, that is, a single test case, is executed.
1. Test package level: All test cases in the test package are executed.
2. Test suite level: All test cases defined in the **describe** method are executed.
3. Test method level: The specified **it** method, that is, a single test case, is executed.
![](figures/Execute.PNG)
## Viewing the Test Result
**Viewing the Test Result**
After the test is complete, you can view the test result in DevEco Studio, as shown in the following figure.
![](figures/TestResult.PNG)
### In the CLI
To run a test script in the CLI, execute **aa** commands with different execution control keywords.
Parameters in aa test commands
| Keyword | Abbreviation| Description | Example |
| ------------- | ------------ | -------------------------------------- | ---------------------------------- |
| --bundleName | -b | Application bundle name. | - b com.test.example |
| --packageName | -p | Application module name, which is applicable to applications developed in the FA model. | - p com.test.example.entry |
| --moduleName | -m | Application module name, which is applicable to applications developed in the stage model. | -m entry |
| NA | -s | \<key, value> pair.| - s unittest OpenHarmonyTestRunner |
The framework supports multiple test case execution modes, which are triggered by the key-value pair following the **-s** keyword. The table below lists the available keys and values.
| Key | Description | Value | Parameter |
| ------------ | ----------------------------------------------------------------------------- | ------------------------------------------------------------ | ----------------------------------------- |
| unittest | OpenHarmonyTestRunner object used for test case execution. | **OpenHarmonyTestRunner** or custom runner name. | - s unittest OpenHarmonyTestRunner |
| class | Test suite or test case to be executed. | {describeName}#{itName}, {describeName} | -s class attributeTest#testAttributeIt |
| notClass | Test suite or test case that does not need to be executed. | {describeName}#{itName}, {describeName} | -s notClass attributeTest#testAttributeIt |
| itName | Test case to be executed. | {itName} | -s itName testAttributeIt |
| timeout | Timeout interval for executing a test case. | Positive integer (unit: ms). If no value is set, the default value 5000 is used. | -s timeout 15000 |
| breakOnError | Whether to enable break-on-error mode. When this mode is enabled, the test execution process exits if a test assertion error or any other error occurs.| **true**/**false** (default value) | -s breakOnError true |
| testType | Type of the test case to be executed. | function, performance, power, reliability, security, global, compatibility, user, standard, safety, resilience| -s testType function |
| level | Level of the test case to be executed. | 0, 1, 2, 3, 4 | -s level 0 |
| size | Size of the test case to be executed. | small, medium, large | -s size small |
| stress | Number of times that the test case is executed. | Positive integer | -s stress 1000 |
**Running Commands**
> Configure hdc-related environment variables, and then perform the following:
- Open the CLI.
- Run the **aa test** commands.
Example 1: Execute all test cases.
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner
```
Example 2: Execute cases in the specified test suites, separated by commas (,).
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s class s1,s2
```
Example 3: Execute specified cases in the specified test suites, separated by commas (,).
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s class testStop#stop_1,testStop1#stop_0
```
Example 4: Execute all test cases except the specified ones, separated by commas (,).
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s notClass testStop
```
Example 5: Execute specified test cases, separated by commas (,).
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s itName stop_0
```
Example 6: Set the timeout interval for executing a test case.
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s timeout 15000
```
Example 7: Enable break-on-error mode.
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s breakOnError true
```
Example 8: Execute test cases of the specified type.
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s testType function
```
Example 9: Execute test cases at the specified level.
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s level 0
```
Example 10: Execute test cases with the specified size.
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s size small
```
Example 11: Execute test cases for a specified number of times.
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s stress 1000
```
**Viewing the Test Result**
- During test execution in the CLI, the log information similar to the following is displayed:
```
OHOS_REPORT_STATUS: class=testStop
OHOS_REPORT_STATUS: current=1
OHOS_REPORT_STATUS: id=JS
OHOS_REPORT_STATUS: numtests=447
OHOS_REPORT_STATUS: stream=
OHOS_REPORT_STATUS: test=stop_0
OHOS_REPORT_STATUS_CODE: 1
OHOS_REPORT_STATUS: class=testStop
OHOS_REPORT_STATUS: current=1
OHOS_REPORT_STATUS: id=JS
OHOS_REPORT_STATUS: numtests=447
OHOS_REPORT_STATUS: stream=
OHOS_REPORT_STATUS: test=stop_0
OHOS_REPORT_STATUS_CODE: 0
OHOS_REPORT_STATUS: consuming=4
```
| Log Field | Description |
| ------- | -------------------------|
| OHOS_REPORT_SUM | Total number of test cases in the current test suite.|
| OHOS_REPORT_STATUS: class | Name of the test suite that is being executed.|
| OHOS_REPORT_STATUS: id | Case execution language. The default value is JS. |
| OHOS_REPORT_STATUS: numtests | Total number of test cases in the test package.|
| OHOS_REPORT_STATUS: stream | Error information of the current test case.|
| OHOS_REPORT_STATUS: test| Name of the current test case.|
| OHOS_REPORT_STATUS_CODE | Execution result of the current test case. The options are as follows:<br>**0**: pass<br>**1**: error<br>**2**: fail|
| OHOS_REPORT_STATUS: consuming | Execution duration of the current test case.|
- After the commands are executed, the log information similar to the following is displayed:
```
OHOS_REPORT_RESULT: stream=Tests run: 447, Failure: 0, Error: 1, Pass: 201, Ignore: 245
OHOS_REPORT_CODE: 0
OHOS_REPORT_RESULT: breakOnError model, Stopping whole test suite if one specific test case failed or error
OHOS_REPORT_STATUS: taskconsuming=16029
```
| Log Field | Description |
| ------------------| -------------------------|
| run | Total number of test cases in the current test package.|
| Failure | Number of failed test cases.|
| Error | Number of test cases whose execution encounters errors. |
| Pass | Number of passed test cases.|
| Ignore | Number of test cases not executed.|
| taskconsuming| Total time spent in executing the current test case.|
> When an error occurs in break-on-error mode, check the **Ignore** and interrupt information.
## FAQs
### FAQs About Unit Test Cases
......@@ -182,7 +342,7 @@ The logs added to the test case are displayed after the test case execution, rat
More than one asynchronous interface is called in the test case.<br>In principle, logs in the test case are printed before the test case execution is complete.
**Solution**
**Solution**
If more than one asynchronous interface is called, you are advised to encapsulate the interface invoking into the promise mode
......@@ -209,14 +369,18 @@ After the test case execution is complete, the console displays the error messag
**Possible Causes**
1. The test case is executed through an asynchronous interface, but the **done** function is not executed during the execution. As a result, the test case execution does not end until it times out.
2. The time taken for API invocation is longer than the timeout interval set for test case execution.
3. Test assertion fails, and a failure exception is thrown. As a result, the test case execution does not end until the timeout expires.
**Solution**
1. Check the code logic of the test case to ensure that the **done** function is executed even if the assertion fails.
2. Modify the case execution timeout settings under **Run/Debug Configurations** in DevEco Studio.
3. Check the code logic and assertion result of the test case and make sure that the assertion is passed.
### FAQs About UI Test Cases
#### The failure log contains "Get windows failed/GetRootByWindow failed"
......@@ -237,11 +401,11 @@ Run the following command, restart the device, and execute the test case again:
hdc shell param set persist.ace.testmode.enabled 1
```
#### The failure log contains "uitest-api dose not allow calling concurrently"
#### The failure log contains "uitest-api does not allow calling concurrently"
**Problem**
The UI test case fails to be executed. The HiLog file contains the error message "uitest-api dose not allow calling concurrently".
The UI test case fails to be executed. The HiLog file contains the error message "uitest-api does not allow calling concurrently".
**Possible Causes**
......@@ -255,11 +419,11 @@ The UI test case fails to be executed. The HiLog file contains the error message
2. Do not execute UI test cases in multiple processes.
#### The failure log contains "dose not exist on current UI! Check if the UI has changed after you got the widget object"
#### The failure log contains "does not exist on current UI! Check if the UI has changed after you got the widget object"
**Problem**
The UI test case fails to be executed. The HiLog file contains the error message "dose not exist on current UI! Check if the UI has changed after you got the widget object".
The UI test case fails to be executed. The HiLog file contains the error message "does not exist on current UI! Check if the UI has changed after you got the widget object".
**Possible Causes**
......
......@@ -271,10 +271,10 @@ Creates a **KVManager** instance to manage KV stores.
Stage model:
```js
import AbilityStage from '@ohos.application.Ability'
import UIAbility from '@ohos.app.ability.UIAbility'
let kvManager;
export default class MyAbilityStage extends AbilityStage {
export default class EntryAbility extends UIAbility {
onCreate() {
console.log("MyAbilityStage onCreate")
let context = this.context
......@@ -2847,7 +2847,7 @@ try {
### get
get(key: string, callback: AsyncCallback<boolean | string| number | Uint8Array>): void
get(key: string, callback: AsyncCallback&lt;boolean | string | number | Uint8Array&gt;): void
Obtains the value of the specified key. This API uses an asynchronous callback to return the result.
......@@ -2898,7 +2898,7 @@ try {
### get
get(key: string): Promise&lt;boolean | string| number | Uint8Array&gt;
get(key: string): Promise&lt;boolean | string | number | Uint8Array&gt;
Obtains the value of the specified key. This API uses a promise to return the result.
......@@ -4849,7 +4849,7 @@ Before calling any method in **DeviceKVStore**, you must use [getKVStore](#getkv
### get
get(key: string, callback: AsyncCallback<boolean | string| number | Uint8Array>): void
get(key: string, callback: AsyncCallback&lt;boolean | string | number | Uint8Array&gt;): void
Obtains the value of the specified key for this device. This API uses an asynchronous callback to return the result.
......@@ -4900,7 +4900,7 @@ try {
### get
get(key: string): Promise&lt;boolean | string| number | Uint8Array&gt;
get(key: string): Promise&lt;boolean | string | number | Uint8Array&gt;
Obtains the value of the specified key for this device. This API uses a promise to return the result.
......@@ -4952,7 +4952,7 @@ try {
### get
get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): void
get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean | string | number | Uint8Array&gt;): void
Obtains a string value that matches the specified device ID and key. This API uses an asynchronous callback to return the result.
......@@ -5004,7 +5004,7 @@ try {
### get
get(deviceId: string, key: string): Promise&lt;boolean|string|number|Uint8Array&gt;
get(deviceId: string, key: string): Promise&lt;boolean | string | number | Uint8Array&gt;
Obtains a string value that matches the specified device ID and key. This API uses a promise to return the result.
......
# @system.storage (Data Storage)
> **NOTE**<br/>
> **NOTE**
>
> - The APIs of this module are no longer maintained since API Version 6, and you are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API Version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md).
> - The APIs of this module are no longer maintained since API version 6, and you are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md).
>
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs of this module can be used only in the FA model.
## Modules to Import
```js
import storage from '@system.storage';
```
## storage.get
get(Object): void
get(options: GetStorageOptions): void
Reads the value stored in the cache based on the specified key.
......@@ -25,13 +24,9 @@ Reads the value stored in the cache based on the specified key.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data to read.|
| default | string | No| Default value returned when the **key** does not exist.|
| success | Function | No| Called to return the value obtained when **storage.get()** is successful.|
| fail | Function | No| Called when **storage.get()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when **storage.get()** is complete.|
| Name | Type | Mandatory| Description |
| ------- | -------------------- | ---- | ---------- |
| options | [GetStorageOptions](#getstorageoptions) | Yes | API configuration.|
**Example**
......@@ -54,10 +49,9 @@ export default {
}
```
## storage.set
set(Object): void
set(options: SetStorageOptions): void
Sets the value in the cache based on the specified key.
......@@ -65,13 +59,9 @@ Sets the value in the cache based on the specified key.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data to set.|
| value | string | Yes| New value to set. The length must be less than 128 bytes.|
| success | Function | No| Called when **storage.set()** is successful.|
| fail | Function | No| Called when **storage.set()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when **storage.set()** is complete.|
| Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ---------- |
| options | [SetStorageOptions](#setstorageoptions) | Yes | API configuration.|
**Example**
......@@ -92,10 +82,9 @@ export default {
}
```
## storage.clear
clear(Object): void
clear(options?: ClearStorageOptions): void
Clears the key-value pairs from the cache.
......@@ -103,11 +92,9 @@ Clears the key-value pairs from the cache.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| success | Function | No| Called when **storage.clear()** is successful.|
| fail | Function | No| Called when **storage.clear()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when **storage.clear()** is complete.|
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------------- | ---- | -------------- |
| options | [ClearStorageOptions](#clearstorageoptions) | No | API configuration.|
**Example**
......@@ -126,10 +113,9 @@ export default {
}
```
## storage.delete
delete(Object): void
delete(options: DeleteStorageOptions): void
Deletes the key-value pair based on the specified key.
......@@ -137,12 +123,9 @@ Deletes the key-value pair based on the specified key.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data to delete.|
| success | Function | No| Called when **storage.delete()** is successful.|
| fail | Function | No| Called when **storage.delete()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when **storage.delete()** is complete.|
| Name | Type | Mandatory| Description |
| ------- | --------------------------------------------- | ---- | -------------- |
| options | [DeleteStorageOptions](#deletestorageoptions) | Yes | API configuration.|
**Example**
......@@ -161,3 +144,52 @@ export default {
}
}
```
## GetStorageOptions
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
| Name | Type | Mandatory| Description |
| -------- | ---------------- | ---- | ------------------- |
| key | string | Yes | Key of the target data. |
| default | string | No | Default value returned when the specified key does not exist. |
| success | (data: any) => void | No | Called to return the result when **storage.get()** is called successfully. **data** is the value indexed by the specified key. |
| fail | (data: string, code: number) => void | No | Called to return the result when **storage.get()** fails to be called. **data** is the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when **storage.get()** is complete. |
## SetStorageOptions
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
| Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | -------------------- |
| key | string | Yes | Key of the data to set. |
| value | string | Yes | New value to set. The length must be less than 128 bytes. |
| success | () => void | No | Called when **storage.set()** is called successfully. |
| fail | (data: string, code: number) => void | No | Called to return the result when **storage.set()** fails to be called. **data** is the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when **storage.set()** is complete. |
## ClearStorageOptions
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- |
| success | () => void | No | Called when **storage.clear()** is called successfully. |
| fail | (data: string, code: number) => void | No | Called to return the result when **storage.clear()** fails to be called. **data** is the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when **storage.clear()** is complete. |
## DeleteStorageOptions
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------ |
| key | string | Yes | Key of the data to delete. |
| success | () => void | No | Called when **storage.delete()** is called successfully. |
| fail | (data: string, code: number) => void | No | Called to return the result when **storage.delete()** fails to be called. **data** is the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when **storage.delete()** is complete. |
......@@ -305,6 +305,7 @@ struct WebComponent {
Button('loadUrl')
.onClick(() => {
try {
// The URL to be loaded is of the string type.
this.controller.loadUrl('www.example.com');
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
......@@ -316,6 +317,69 @@ struct WebComponent {
}
```
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Button('loadUrl')
.onClick(() => {
try {
// The headers parameter is carried.
this.controller.loadUrl('www.example.com', [{headerKey: "headerKey", headerValue: "headerValue"}]);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
.webDebuggingAccess(true)
}
}
}
```
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Button('loadUrl')
.onClick(() => {
try {
// The URL to be loaded is of the Resource type.
this.controller.loadUrl($rawfile('xxx.html'));
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
```html
<!-- xxx.html -->
<!DOCTYPE html>
<html>
<body>
<p>Hello World</p>
</body>
</html>
```
### loadData
loadData(data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string): void
......@@ -987,7 +1051,7 @@ Executes a JavaScript script. This API uses a promise to return the script execu
| Type | Description |
| --------------- | --------------------------------------------------- |
| Promise\<string> | Callback used to return the result. Returns **null** if the JavaScript script fails to be executed|
| Promise\<string> | Promise used to return the result. Returns **null** if the JavaScript script fails to be executed|
**Error codes**
......@@ -4101,7 +4165,7 @@ Checks whether any saved HTTP authentication credentials exist. This API returns
| Type | Description |
| ------- | ------------------------------------------------------------ |
| boolean | Whether any saved HTTP authentication credentials exist. Returns **true** if any saved HTTP authentication credentials exist exists; returns **false** otherwise.|
| boolean | Whether any saved HTTP authentication credentials exist. Returns **true** if any saved HTTP authentication credentials exist; returns **false** otherwise. |
**Example**
......
......@@ -21,6 +21,7 @@ Web(options: { src: ResourceStr, controller: WebController | WebviewController})
> **NOTE**
>
> Transition animation is not supported.
> Different **\<Web>** components on the same page must be bound to different **WebController**s.
**Parameters**
......@@ -526,7 +527,7 @@ Sets whether to enable the multi-window permission.
horizontalScrollBarAccess(horizontalScrollBar: boolean)
Sets whether to display the horizontal scrollbar, including the system default scrollbar and custom scrollbar. By default, the horizontal scrollbar is displayed.
Sets whether to display the horizontal scrollbar, including the default system scrollbar and custom scrollbar. By default, the horizontal scrollbar is displayed.
**Parameters**
......@@ -577,7 +578,7 @@ Sets whether to display the horizontal scrollbar, including the system default s
verticalScrollBarAccess(verticalScrollBar: boolean)
Sets whether to display the vertical scrollbar, including the system default scrollbar and custom scrollbar. By default, the vertical scrollbar is displayed.
Sets whether to display the vertical scrollbar, including the default system scrollbar and custom scrollbar. By default, the vertical scrollbar is displayed.
**Parameters**
......@@ -1539,7 +1540,7 @@ onDownloadStart(callback: (event?: { url: string, userAgent: string, contentDisp
onErrorReceive(callback: (event?: { request: WebResourceRequest, error: WebResourceError }) => void)
Called when an error occurs during web page loading. For better results, simplify the implementation logic in the callback.
Called when an error occurs during web page loading. For better results, simplify the implementation logic in the callback. This API is called when there is no network connection.
**Parameters**
......@@ -1764,7 +1765,7 @@ Called when the document title of the web page is changed.
onRefreshAccessedHistory(callback: (event?: { url: string, isRefreshed: boolean }) => void)
Called when loading of the web page is complete. This API is used by an application to update the historical link it accessed..
Called when loading of the web page is complete. This API is used by an application to update the historical link it accessed.
**Parameters**
......@@ -1950,7 +1951,7 @@ Called when the display ratio of this page changes.
onUrlLoadIntercept(callback: (event?: { data:string | WebResourceRequest }) => boolean)
Called when the **\<Web>** component is about to access a URL. This API is used to determine whether to block the access.
Called when the **\<Web>** component is about to access a URL. This API is used to determine whether to block the access, which is allowed by default.
**Parameters**
......@@ -2326,8 +2327,8 @@ Called when the scrollbar of the page scrolls.
| Name | Type | Description |
| ------- | ------ | ------------ |
| xOffset | number | Position of the scrollbar on the x-axis.|
| yOffset | number | Position of the scrollbar on the y-axis.|
| xOffset | number | Position of the scrollbar on the x-axis relative to the leftmost of the web page.|
| yOffset | number | Position of the scrollbar on the y-axis relative to the top of the web page.|
**Example**
......@@ -2668,7 +2669,7 @@ Called when the old page is not displayed and the new page is about to be visibl
onInterceptKeyEvent(callback: (event: KeyEvent) => boolean)
Called when the key event is intercepted, before being consumed by the Webview.
Called when the key event is intercepted and before it is consumed by the Webview.
**Parameters**
......
......@@ -8,10 +8,12 @@ Create a **\<Web>** component in the .ets file under **main/ets/MainAbility/page
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController();
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Web({ src: 'https://www.example.com', controller: this.controller })
......@@ -26,11 +28,13 @@ When using the **\<Web>** component, you must specify the styles and attributes.
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
fileAccess: boolean = true;
controller: WebController = new WebController();
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Text('Hello world!')
......@@ -54,13 +58,15 @@ Add the **onProgressChange** event for the **\<Web>** component, which is trigge
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
@State progress: number = 0;
@State hideProgress: boolean = true;
fileAccess: boolean = true;
controller: WebController = new WebController();
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Text('Hello world!')
......@@ -93,14 +99,17 @@ Add the **runJavaScript** method to the **onPageEnd** event. The **onPageEnd** e
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
@State progress: number = 0;
@State hideProgress: boolean = true;
@State webResult: string = ''
fileAccess: boolean = true;
// Define the controller for the \<Web> component.
controller: WebController = new WebController();
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Text('Hello world!')
......@@ -124,8 +133,23 @@ struct WebComponent {
})
.onPageEnd(e => {
// test() is defined in index.html.
this.controller.runJavaScript({ script: 'test()' });
try {
this.controller.runJavaScript(
'test()',
(error, result) => {
if (error) {
console.info(`run JavaScript error: ` + JSON.stringify(error))
return;
}
if (result) {
this.webResult = result
console.info(`The test() return value is: ${result}`)
}
});
console.info('url: ', e.url);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Text('End')
.fontSize(20)
......@@ -160,10 +184,12 @@ The configuration procedure is as follows:
1. Set the **webDebuggingAccess** attribute of the **\<Web>** component to **true**.
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
......@@ -189,20 +215,30 @@ In this example, you'll implement a **\<Web>** component where videos can be pla
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController();
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Row() {
Button('onActive').onClick(() => {
console.info("Web Component onActive");
try {
this.controller.onActive();
} catch (error) {
console.error(`Errorcode: ${error.code}, Message: ${error.message}`);
}
})
Button('onInactive').onClick(() => {
console.info("Web Component onInactive");
try {
this.controller.onInactive();
} catch (error) {
console.error(`Errorcode: ${error.code}, Message: ${error.message}`);
}
})
}
Web({ src: $rawfile('index.html'), controller: this.controller })
......
......@@ -42,6 +42,4 @@ The adaptation process is divided into four steps: porting preparation, kernel p
| Subsystem| A subsystem, as a logical concept, consists of one or more components. OpenHarmony is designed with a layered architecture, which consists of the kernel layer, system service layer, framework layer, and application layer from the bottom up. System functions are built from components, subsystems, and then to the system. In a multi-device deployment, you can customize subsystems and components as required.|
| Component| A component is a reusable, configurable, and tailorable function unit. Each component has an independent directory, and can be built and tested independently and developed concurrently. |
| hb | hb is an OpenHarmony command line tool used to execute build commands.|
| HOBT | HOBT is short for HiLink SDK OHOS Basic Test. It is used to test the basic functions of the interfaces on which the HiLink SDK depends.|
| Kit&nbsp;Framework | Kit Framework is the basic framework of Kit. It contains the security components of OpenHarmony and cannot be tailored.|
| KV | A key-value pair (KV) is a format of data storage.|
......@@ -110,5 +110,5 @@
- [Hiview Development](subsys-dfx-hiview.md)
- R&D Tools
- [bytrace](subsys-toolchain-bytrace-guide.md)
- [hdc_std](subsys-toolchain-hdc-guide.md)
- [hdc](subsys-toolchain-hdc-guide.md)
- [hiperf](subsys-toolchain-hiperf.md)
......@@ -44,7 +44,7 @@ Kconfig visual configuration has the following advantages:
4. Set parameters.
For details about the parameters, see [productdefine/common/base/base_product.json](https://gitee.com/openharmony/productdefine_common/blob/master/base/base_product.json).
For details about the parameters, see productdefine/common/base/base_product.json.
![Setting parameters](./figure/kconfig_set_parameters.gif)
......@@ -99,7 +99,7 @@ Kconfig visual configuration has the following advantages:
### Latest Components Not Displayed in the Menu List
The component list [productdefine/common/base/base_product.json](https://gitee.com/openharmony/productdefine_common/blob/master/base/base_product.json) is updated with product updates and iterations. The Kconfig menu does not contain the latest components.
The component list productdefine/common/base/base_product.json is updated with product updates and iterations. The Kconfig menu does not contain the latest components.
**Solution**
......
......@@ -522,7 +522,7 @@
- [xDevice User Guide](device-test/xdevice.md)
- R&D Tools
- [bytrace](subsystems/subsys-toolchain-bytrace-guide.md)
- [hdc\_std](subsystems/subsys-toolchain-hdc-guide.md)
- [hdc](subsystems/subsys-toolchain-hdc-guide.md)
- [hiperf](subsystems/subsys-toolchain-hiperf.md)
- Tools
......
......@@ -70,7 +70,7 @@ struct Index {
```
当PageAbility的启动模式设置为标准模式或为首次启动单例模式的PageAbility时(具体设置方法和典型场景示例见[PageAbility的启动模式](pageability-launch-type.md)),在调用方PageAbility中,通过want中的parameters参数传递要启动的指定页面的pages信息,调用startAbility()方法启动PageAbility。被调用方可以在onCreate中使用featrueAbility的getWant方法获取want,再通过调用router.push实现启动指定页面。
当PageAbility的启动模式设置为标准模式或为首次启动单例模式的PageAbility时(具体设置方法和典型场景示例见[PageAbility的启动模式](pageability-launch-type.md)),在调用方PageAbility中,通过want中的parameters参数传递要启动的指定页面的pages信息,调用startAbility()方法启动PageAbility。被调用方可以在onCreate中使用featureAbility的getWant方法获取want,再通过调用router.push实现启动指定页面。
调用方的页面中实现按钮点击触发startAbility方法启动目标端PageAbility,startAbility方法的入参want中携带指定页面信息,示例代码如下:
......@@ -119,7 +119,7 @@ struct Index {
```
目标端PageAbility的onCreate生命周期回调中通过featrueAbility的getWant方法获取want,并对参数进行解析,实现指定页面拉起:
目标端PageAbility的onCreate生命周期回调中通过featureAbility的getWant方法获取want,并对参数进行解析,实现指定页面拉起:
```ts
import featureAbility from '@ohos.ability.featureAbility';
......
......@@ -134,7 +134,7 @@ export default function abilityTest() {
//init driver
var driver = await Driver.create();
await driver.delayMs(1000);
//find button on text 'Next'
//find button by text 'Next'
var button = await driver.findComponent(ON.text('Next'));
//click button
await button.click();
......
......@@ -38,7 +38,50 @@ DataShare即数据共享模块,提供了向其他应用共享以及管理其
### 数据提供方应用的开发(仅限系统应用)
1. 导入基础依赖包。
[DataShareExtensionAbility](../reference/apis/js-apis-application-dataShareExtensionAbility.md)提供以下API,根据需要重写对应回调方法。
- **onCreate**
DataShare客户端连接DataShareExtensionAbility服务端时,服务端回调此接口,执行初始化业务逻辑操作。该方法可以选择性重写。
- **insert**
业务函数,客户端请求插入数据时回调此接口,服务端需要在此回调中实现插入数据功能,该方法可以选择性重写。
- **update**
业务函数,客户端请求更新数据时回调此接口,服务端需要在此回调中实现更新数据功能,该方法可以选择性重写。
- **delete**
业务函数,客户端请求删除数据时回调此接口,服务端需要在此回调中实现删除数据功能,该方法可以选择性重写。
- **query**
业务函数,客户端请求查询数据时回调此接口,服务端需要在此回调中实现查询数据功能,该方法可以选择性重写。
- **batchInsert**
业务函数,客户端请求批量插入数据时回调此接口,服务端需要在此回调中实现批量插入数据数据功能,该方法可以选择性重写。
- **normalizeUri**
业务函数,客户端给定的URI转换为服务端使用的URI时回调此接口,该方法可以选择性重写。
- **denormalizeUri**
业务函数,服务端使用的URI转换为客户端传入的初始URI时服务端回调此接口,该方法可以选择性重写。
开发者在实现一个数据共享服务时,需要在DevEco Studio工程中手动新建一个DataShareExtensionAbility,具体步骤如下。
1. 在工程Module对应的ets目录下,右键选择“New &gt; Directory”,新建一个目录并命名为DataShareAbility。
2. 在DataShareAbility目录,右键选择“New &gt; TypeScript File”,新建一个TypeScript文件并命名为DataShareAbility.ts。
3. 在DataShareAbility.ts文件中,增加导入DataShareExtensionAbility的依赖包,开发者可根据应用需求选择性重写其业务实现。例如数据提供方只提供插入、删除和查询服务,则可只重写这些接口。
4. 导入基础依赖包。
```ts
import Extension from '@ohos.application.DataShareExtensionAbility';
......@@ -47,9 +90,9 @@ DataShare即数据共享模块,提供了向其他应用共享以及管理其
import dataSharePredicates from '@ohos.data.dataSharePredicates';
```
2. 数据提供方(也称服务端)继承于DataShareExtensionAbility,开发者可根据应用需求选择性重写其业务实现。例如数据提供方只提供查询服务,则可只重写查询接口。
5. 数据提供方(也称服务端)继承于DataShareExtensionAbility,开发者可根据应用需求选择性重写其业务实现。例如数据提供方只提供查询服务,则可只重写查询接口。
3. 数据提供方的业务实现由开发者自定义。例如可以通过数据库、读写文件或访问网络等各方式实现数据提供方的数据存储。
6. 数据提供方的业务实现由开发者自定义。例如可以通过数据库、读写文件或访问网络等各方式实现数据提供方的数据存储。
```ts
const DB_NAME = "DB00.db";
......@@ -66,7 +109,7 @@ DataShare即数据共享模块,提供了向其他应用共享以及管理其
// 重写onCreate接口
onCreate(want, callback) {
result = this.context.cacheDir + '/datashare.txt'
result = this.context.cacheDir + '/datashare.txt';
// 业务实现使用RDB
rdb.getRdbStore(this.context, {
name: DB_NAME,
......@@ -76,7 +119,9 @@ DataShare即数据共享模块,提供了向其他应用共享以及管理其
rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) {
console.log('DataShareExtAbility onCreate, executeSql done err:' + JSON.stringify(err));
});
if (callback) {
callback();
}
});
}
......@@ -103,7 +148,7 @@ DataShare即数据共享模块,提供了向其他应用共享以及管理其
};
```
4. 在module.json5中定义DataShareExtensionAbility。
7. 在module.json5中定义DataShareExtensionAbility。
| Json重要字段 | 备注说明 |
| ------------ | ------------------------------------------------------------ |
......@@ -168,7 +213,7 @@ DataShare即数据共享模块,提供了向其他应用共享以及管理其
let valuesBucket = { "name": "ZhangSan", "age": 21, "isStudent": false, "Binary": new Uint8Array([1, 2, 3]) };
let updateBucket = { "name": "LiSi", "age": 18, "isStudent": true, "Binary": new Uint8Array([1, 2, 3]) };
let predicates = new dataSharePredicates.DataSharePredicates();
let valArray = new Array("*");
let valArray = ['*'];
// 插入一条数据
dsHelper.insert(dseUri, valuesBucket, (err, data) => {
console.log("dsHelper insert result: " + data);
......@@ -187,3 +232,8 @@ DataShare即数据共享模块,提供了向其他应用共享以及管理其
});
```
## 相关示例
针对DataShareExtensionAbility开发,有以下相关示例可供参考:
[DataShareExtensionAbility:跨应用数据共享(ArkTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/data/CrossAppDataShare)
......@@ -4,6 +4,8 @@
DataShare即数据共享模块,用于应用管理其自身数据,也提供了向其他应用共享以及管理其数据的方法。目前仅支持同个设备上应用之间的数据共享。
DataShare需要与[DataShareExtensionAbility](../reference/apis/js-apis-application-dataShareExtensionAbility.md)配合使用。
在许多应用场景中都需要用到数据共享,比如将电话簿、短信、媒体库中的数据共享给其他应用等。当然,不是所有的数据都允许其他应用访问,比如帐号、密码等;有些数据也只允许其他应用查询而不允许其删改,比如短信等。所以对于各种数据共享场景,DataShare这样一个安全、便捷的可以跨应用的数据共享机制是十分必需的。
对于数据提供者来说,无需进行繁琐的封装,可直接使用DataShare框架实现向其他应用共享数据;对于数据访问方来说,因DataShare的访问方式不会因数据提供的方式而不同,所以只需要学习和使用一套接口即可,大大减少了学习时间和开发难度。
......@@ -16,11 +18,11 @@ DataShare即数据共享模块,用于应用管理其自身数据,也提供
- **数据提供方**
提供数据及实现相关业务的应用程序,也称为生产者或服务端
DataShareExtensionAbility,基于Stage模型,选择性实现对数据的增、删、改、查以及文件打开等功能,并对外共享这些数据。实现跨应用数据共享的相关业务
- **数据访问方**
访问数据提供方所提供的数据或业务的应用程序,也称为消费者或客户端
DataShareHelper,由[createDataShareHelper()](../reference/apis/js-apis-data-dataShare.md#datasharecreatedatasharehelper)方法所创建的工具类,数据访问方利用工具类,便可访问数据提供方提供的数据
- **数据集**
......
......@@ -111,13 +111,14 @@
这个权限还需要在应用首次启动的时候弹窗获取用户授权。
```js
// FA模型
import featureAbility from '@ohos.ability.featureAbility';
function grantPermission() {
console.info('grantPermission');
let context = featureAbility.getContext();
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
console.info(`result.requestCode=${result.requestCode}`)
console.info(`requestPermissionsFromUser CallBack`);
})
console.info('end grantPermission');
......@@ -126,6 +127,30 @@
grantPermission();
```
```ts
// Stage模型
import UIAbility from '@ohos.app.ability.UIAbility';
let context = null;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
context = this.context;
}
}
function grantPermission() {
let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC'];
context.requestPermissionsFromUser(permissions).then((data) => {
console.log('success: ${data}');
}).catch((error) => {
console.error('failed: ${error}');
});
}
grantPermission();
```
3. 获取分布式数据对象实例。
```js
......
# DFX
- 应用事件打点
- [应用事件打点开发指导](hiappevent-guidelines.md)
- 性能打点跟踪
- [性能打点跟踪开发指导](hitracemeter-guidelines.md)
- 分布式跟踪
- [分布式跟踪开发指导](hitracechain-guidelines.md)
- [应用事件打点开发指导](hiappevent-guidelines.md)
- [性能打点跟踪开发指导](hitracemeter-guidelines.md)
- [分布式跟踪开发指导](hitracechain-guidelines.md)
- 错误管理
- [错误管理开发指导](errormanager-guidelines.md)
- [应用恢复开发指导](apprecovery-guidelines.md)
\ No newline at end of file
......@@ -395,7 +395,11 @@ extensionAbilities示例:
该标签标识应用运行时需向系统申请的权限集合。
**表8** **requestPermissions标签说明**
> **说明:**
>
> 在requestPermissions标签中配置的权限项将在应用级别生效,即该权限适用于整个应用程序。
**表8** **requestPermissions标签说明**
| 属性 | 含义 | 类型 | 取值范围 | 默认值 |
| -------- | -------- | -------- | -------- | -------- |
......
......@@ -16,8 +16,8 @@ IDE支持在一个应用工程中进行多个HAP的开发与构建,如[多HAP
**说明:**
- 该目录由IDE自动生成,名称不可更改。
- AppScope目录下面的文件名与Entry、Feature模块下面的文件名不能重复,否则IDE会报错。
- entry或者featrue目录(名称可由开发者自定义)
- 由IDE引导开发者创建的Module,在该Module中实现应用的业务逻辑;可以创建多个Module,图中entry和featrue即是创建的两个Module。
- entry或者feature目录(名称可由开发者自定义)
- 由IDE引导开发者创建的Module,在该Module中实现应用的业务逻辑;可以创建多个Module,图中entry和feature即是创建的两个Module。
- resources目录:放置该Module中所使用到的资源。
- ets目录:开发者的业务逻辑。
- [module.json5](module-configuration-file.md):配置该Module的描述信息,如:Module的名称、Module的入口代码路径、包含的组件信息等。
......
......@@ -9,29 +9,37 @@
开发者通过[DevEco Studio](https://developer.harmonyos.com/cn/develop/deveco-studio)工具按照业务的需要创建多个Module,在相应的Module中完成自身业务的开发。
## 调试
通过DevEco Studio编译打包,生成单个或者多个HAP,即可基于HAP进行调试。
通过DevEco Studio编译打包,生成单个或者多个HAP,即可基于HAP进行调试。在调试前,需要先安装或更新HAP,以下介绍具体做法。
* 使用DevEco Studio进行调试
使用指导可参考[应用程序包调试方法](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-debugging-and-running-0000001263040487#section10491183521520),其中包括了单HAP与多HAP通过DevEco Studio工具的安装调试方法。
* 使用[hdc_std工具](../../device-dev/subsystems/subsys-toolchain-hdc-guide.md)(可通过OpenHarmony SDK获取,在SDK的toolchains目录下)进行调试
* 使用[hdc工具](../../device-dev/subsystems/subsys-toolchain-hdc-guide.md)(可通过OpenHarmony SDK获取,在SDK的toolchains目录下)进行调试
在调试前,需要先安装或更新HAP,此处有两种方式。
1. 直接使用hdc安装、更新HAP。
HAP的路径为开发平台上的文件路径,以Windows开发平台为例,命令参考如下:
使用hdc_std安装HAP时,HAP的路径为开发平台上的文件路径,以Windows开发平台为例,命令参考如下:
```
// 安装、更新,多HAP可以指定多个文件路径
hdc_std install C:\entry.hap C:\feature.hap
hdc install C:\entry.hap C:\feature.hap
// 执行结果
install bundle successfully.
// 卸载
hdc_std uninstall com.example.myapplication
hdc uninstall com.example.myapplication
// 执行结果
uninstall bundle successfully.
```
* 使用[bm工具](../../application-dev/tools/bm-tool.md)进行调试
2. 先执行hdc shell,再使用bm工具安装、更新HAP。
HAP的文件路径为真机上的文件路径,命令参考如下:
使用bm工具进行安装、更新HAP时,传入的文件路径为真机上 的文件路径,命令参考如下:
```
// 先执行hdc shell才能使用bm工具
hdc shell
// 安装、更新,多HAP可以指定多个文件路径
bm install -p /data/app/entry.hap /data/app/feature.hap
// 执行结果
......@@ -41,6 +49,8 @@
// 执行结果
uninstall bundle successfully.
```
完成HAP安装或更新后,即可参考相关调试命令进行[调试](https://docs.openharmony.cn/pages/v3.2Beta/zh-cn/application-dev/tools/aa-tool.md/)。
## 发布
当开发的程序包满足发布要求时,可以在工具中打包编译生成App包。将该App包上架到应用市场云端,应用市场会对上架的App包校验签名,校验签名通过后会将App包中的HAP拆分出来,同时对拆分出的HAP重新添加签名,然后对HAP进行分发。
......
......@@ -7,7 +7,7 @@
- App Pack包中所有HAP的配置文件中的versionCode标签必须一致。
- App Pack包中同一设备类型的所有HAP中必须有且只有一个entry类型的HAP,featrue类型的HAP可以有一个或者多个,也可以没有。
- App Pack包中同一设备类型的所有HAP中必须有且只有一个entry类型的HAP,feature类型的HAP可以有一个或者多个,也可以没有。
- App Pack包中的每个HAP必须配置moduleName标签,同一设备类型的所有HAP对应的moduleName标签必须唯一。
......
......@@ -10,7 +10,7 @@ Ability模块将二级模块API组织在一起方便开发者进行导出。
## 导入模块
```ts
import ability from '@ohos.ability.ability'
import ability from '@ohos.ability.ability';
```
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
......
......@@ -65,8 +65,8 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
```ts
let want = {
bundleName: "com.example.myapp",
abilityName: "MyAbility"
bundleName: 'com.example.myapp',
abilityName: 'MyAbility'
};
try {
......@@ -120,9 +120,9 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let options = {
windowMode: 0
......@@ -183,8 +183,8 @@ startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
```ts
let want = {
bundleName: "com.example.myapp",
abilityName: "MyAbility"
bundleName: 'com.example.myapp',
abilityName: 'MyAbility'
};
let options = {
windowMode: 0,
......@@ -243,9 +243,9 @@ startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;):
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
try {
......@@ -257,8 +257,8 @@ startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;):
return;
}
// 执行正常业务
console.log("startAbilityForResult succeed, result.resultCode = " +
result.resultCode)
console.log('startAbilityForResult succeed, result.resultCode = ' +
result.resultCode);
});
} catch (paramError) {
// 处理入参错误异常
......@@ -302,9 +302,9 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let options = {
windowMode: 0,
......@@ -319,8 +319,8 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
return;
}
// 执行正常业务
console.log("startAbilityForResult succeed, result.resultCode = " +
result.resultCode)
console.log('startAbilityForResult succeed, result.resultCode = ' +
result.resultCode);
});
} catch (paramError) {
// 处理入参错误异常
......@@ -371,8 +371,8 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityRes
```ts
let want = {
bundleName: "com.example.myapp",
abilityName: "MyAbility"
bundleName: 'com.example.myapp',
abilityName: 'MyAbility'
};
let options = {
windowMode: 0,
......@@ -382,7 +382,7 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityRes
this.context.startAbilityForResult(want, options)
.then((result) => {
// 执行正常业务
console.log("startAbilityForResult succeed, result.resultCode = " + result.resultCode);
console.log('startAbilityForResult succeed, result.resultCode = ' + result.resultCode);
})
.catch((error) => {
// 处理业务逻辑错误
......@@ -432,9 +432,9 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let accountId = 100;
......@@ -447,8 +447,8 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
return;
}
// 执行正常业务
console.log("startAbilityForResultWithAccount succeed, result.resultCode = " +
result.resultCode)
console.log('startAbilityForResultWithAccount succeed, result.resultCode = ' +
result.resultCode);
});
} catch (paramError) {
// 处理入参错误异常
......@@ -495,9 +495,9 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let accountId = 100;
let options = {
......@@ -513,8 +513,8 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
return;
}
// 执行正常业务
console.log("startAbilityForResultWithAccount succeed, result.resultCode = " +
result.resultCode)
console.log('startAbilityForResultWithAccount succeed, result.resultCode = ' +
result.resultCode);
});
} catch (paramError) {
// 处理入参错误异常
......@@ -566,9 +566,9 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let accountId = 100;
let options = {
......@@ -579,8 +579,8 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
this.context.startAbilityForResultWithAccount(want, accountId, options)
.then((result) => {
// 执行正常业务
console.log("startAbilityForResultWithAccount succeed, result.resultCode = " +
result.resultCode)
console.log('startAbilityForResultWithAccount succeed, result.resultCode = ' +
result.resultCode);
})
.catch((error) => {
// 处理业务逻辑错误
......@@ -621,9 +621,9 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
try {
......@@ -671,9 +671,9 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
try {
......@@ -725,9 +725,9 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let accountId = 100;
......@@ -779,9 +779,9 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let accountId = 100;
......@@ -830,9 +830,9 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
try {
......@@ -880,9 +880,9 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
try {
......@@ -934,9 +934,9 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let accountId = 100;
......@@ -988,9 +988,9 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let accountId = 100;
......@@ -1110,15 +1110,15 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;voi
```ts
let want = {
bundleName: "com.extreme.myapplication",
abilityName: "SecondAbility"
}
bundleName: 'com.extreme.myapplication',
abilityName: 'SecondAbility'
};
let resultCode = 100;
// 返回给接口调用方AbilityResult信息
let abilityResult = {
want,
resultCode
}
};
try {
this.context.terminateSelfWithResult(abilityResult, (error) => {
......@@ -1172,15 +1172,15 @@ terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
```ts
let want = {
bundleName: "com.extreme.myapplication",
abilityName: "SecondAbility"
}
bundleName: 'com.extreme.myapplication',
abilityName: 'SecondAbility'
};
let resultCode = 100;
// 返回给接口调用方AbilityResult信息
let abilityResult = {
want,
resultCode
}
};
try {
this.context.terminateSelfWithResult(abilityResult)
......@@ -1234,9 +1234,9 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let options = {
onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
......@@ -1292,9 +1292,9 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let accountId = 100;
let options = {
......@@ -1446,10 +1446,10 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
// 后台启动Ability,不配置parameters
let wantBackground = {
bundleName: "com.example.myservice",
moduleName: "entry",
abilityName: "MainAbility",
deviceId: ""
bundleName: 'com.example.myservice',
moduleName: 'entry',
abilityName: 'MainAbility',
deviceId: ''
};
try {
......@@ -1475,14 +1475,14 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
```ts
let caller = undefined;
// 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true
// 前台启动Ability,将parameters中的'ohos.aafwk.param.callAbilityToForeground'配置为true
let wantForeground = {
bundleName: "com.example.myservice",
moduleName: "entry",
abilityName: "MainAbility",
deviceId: "",
bundleName: 'com.example.myservice',
moduleName: 'entry',
abilityName: 'MainAbility',
deviceId: '',
parameters: {
"ohos.aafwk.param.callAbilityToForeground": true
'ohos.aafwk.param.callAbilityToForeground': true
}
};
......@@ -1540,9 +1540,9 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let accountId = 100;
......@@ -1602,9 +1602,9 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let accountId = 100;
let options = {
......@@ -1666,9 +1666,9 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
```ts
let want = {
deviceId: "",
bundleName: "com.extreme.test",
abilityName: "MainAbility"
deviceId: '',
bundleName: 'com.extreme.test',
abilityName: 'MainAbility'
};
let accountId = 100;
let options = {
......@@ -1711,7 +1711,7 @@ setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void;
**示例:**
```ts
this.context.setMissionLabel("test",(result) => {
this.context.setMissionLabel('test',(result) => {
console.log('setMissionLabel result:' + JSON.stringify(result));
});
```
......@@ -1740,7 +1740,7 @@ setMissionLabel(label: string): Promise&lt;void&gt;;
**示例:**
```ts
this.context.setMissionLabel("test").then(() => {
this.context.setMissionLabel('test').then(() => {
console.log('success');
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
......@@ -1780,7 +1780,7 @@ setMissionIcon(icon: image.PixelMap, callback:AsyncCallback\<void>): void;
imagePixelMap = data;
})
.catch((err) => {
console.log('--------- createPixelMap fail, err: ---------', err)
console.log('--------- createPixelMap fail, err: ---------', err);
});
this.context.setMissionIcon(imagePixelMap, (err) => {
console.log('---------- setMissionIcon fail, err: -----------', err);
......@@ -1827,7 +1827,7 @@ setMissionIcon(icon: image.PixelMap): Promise\<void>;
imagePixelMap = data;
})
.catch((err) => {
console.log('--------- createPixelMap fail, err: ---------', err)
console.log('--------- createPixelMap fail, err: ---------', err);
});
this.context.setMissionIcon(imagePixelMap)
.then(() => {
......
......@@ -35,7 +35,7 @@ getId(uri: string): number
**示例:**
```ts
let id = dataUriUtils.getId("com.example.dataUriUtils/1221");
let id = dataUriUtils.getId('com.example.dataUriUtils/1221');
```
......@@ -66,9 +66,9 @@ attachId(uri: string, id: number): string
```ts
let id = 1122;
let uri = dataUriUtils.attachId(
"com.example.dataUriUtils",
'com.example.dataUriUtils',
id,
)
);
```
......@@ -96,7 +96,7 @@ deleteId(uri: string): string
**示例:**
```ts
let uri = dataUriUtils.deleteId("com.example.dataUriUtils/1221")
let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221');
```
......@@ -127,8 +127,8 @@ updateId(uri: string, id: number): string
```ts
let id = 1122;
let uri = dataUriUtils.updateId(
"com.example.dataUriUtils/1221",
'com.example.dataUriUtils/1221',
id
)
);
```
......@@ -9,7 +9,7 @@ ErrorCode定义启动Ability时返回的错误码,包括无效的参数、权
## 导入模块
```ts
import errorCode from '@ohos.ability.errorCode'
import errorCode from '@ohos.ability.errorCode';
```
## ErrorCode
......
......@@ -46,19 +46,19 @@ featureAbility.startAbility(
{
want:
{
action: "",
entities: [""],
type: "",
action: '',
entities: [''],
type: '',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri: ""
abilityName: 'com.example.myapplication.secondAbility',
uri: ''
},
},
(err, data) => {
console.info("startAbility err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
console.info('startAbility err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
}
);
```
......@@ -99,19 +99,19 @@ featureAbility.startAbility(
{
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri: ""
abilityName: 'com.example.myapplication.secondAbility',
uri: ''
},
}
).then((data) => {
console.info("startAbility data: " + JSON.stringify(data));
console.info('startAbility data: ' + JSON.stringify(data));
});
```
......@@ -140,7 +140,7 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper
```ts
import featureAbility from '@ohos.ability.featureAbility';
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
'dataability:///com.example.DataAbility'
);
```
......@@ -176,19 +176,19 @@ featureAbility.startAbilityForResult(
{
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri:""
abilityName: 'com.example.myapplication.secondAbility',
uri:''
},
},
(err, data) => {
console.info("startAbilityForResult err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
console.info('startAbilityForResult err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
}
);
```
......@@ -230,30 +230,30 @@ featureAbility.startAbilityForResult(
{
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri:"",
abilityName: 'com.example.myapplication.secondAbility',
uri:'',
parameters:
{
mykey0: 1111,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "xxxxxxxxxxxxxxxxxxxxxx",
mykey2: '[1, 2, 3]',
mykey3: 'xxxxxxxxxxxxxxxxxxxxxx',
mykey4: [1, 15],
mykey5: [false, true, false],
mykey6: ["aaaaaa", "bbbbb", "ccccccccccc"],
mykey6: ['aaaaaa', 'bbbbb', 'ccccccccccc'],
mykey7: true,
},
},
},
).then((data) => {
console.info("startAbilityForResult data: " + JSON.stringify(data));
console.info('startAbilityForResult data: ' + JSON.stringify(data));
});
```
......@@ -282,29 +282,29 @@ featureAbility.terminateSelfWithResult(
resultCode: 1,
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri:"",
abilityName: 'com.example.myapplication.secondAbility',
uri:'',
parameters: {
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey2: '[1, 2, 3]',
mykey3: 'ssssssssssssssssssssssssss',
mykey4: [1, 15],
mykey5: [false, true, false],
mykey6: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
mykey7: true,
}
},
},
(err) => {
console.info("err: " + JSON.stringify(err))
console.error('err: ' + JSON.stringify(err));
}
);
```
......@@ -339,29 +339,29 @@ featureAbility.terminateSelfWithResult(
resultCode: 1,
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri:"",
abilityName: 'com.example.myapplication.secondAbility',
uri:'',
parameters: {
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey2: '[1, 2, 3]',
mykey3: 'ssssssssssssssssssssssssss',
mykey4: [1, 15],
mykey5: [false, true, false],
mykey6: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
mykey7: true,
}
},
}
).then((data) => {
console.info("==========================>terminateSelfWithResult=======================>");
console.info('==========================>terminateSelfWithResult=======================>');
});
```
......@@ -384,7 +384,7 @@ hasWindowFocus(callback: AsyncCallback\<boolean>): void
```ts
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus((err, data) => {
console.info("hasWindowFocus err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
console.info('hasWindowFocus err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
});
```
......@@ -407,7 +407,7 @@ hasWindowFocus(): Promise\<boolean>
```ts
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus().then((data) => {
console.info("hasWindowFocus data: " + JSON.stringify(data));
console.info('hasWindowFocus data: ' + JSON.stringify(data));
});
```
......@@ -430,7 +430,7 @@ getWant(callback: AsyncCallback\<Want>): void
```ts
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant((err, data) => {
console.info("getWant err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
console.info('getWant err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
});
```
......@@ -453,7 +453,7 @@ getWant(): Promise\<Want>
```ts
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant().then((data) => {
console.info("getWant data: " + JSON.stringify(data));
console.info('getWant data: ' + JSON.stringify(data));
});
```
......@@ -475,9 +475,9 @@ getContext(): Context
```ts
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext()
let context = featureAbility.getContext();
context.getBundleName((err, data) => {
console.info("getBundleName err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
console.info('getBundleName err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
});
```
......@@ -501,7 +501,7 @@ terminateSelf(callback: AsyncCallback\<void>): void
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf(
(err) => {
console.info("err: " + JSON.stringify(err))
console.error('err: ' + JSON.stringify(err));
}
)
```
......@@ -525,7 +525,7 @@ terminateSelf(): Promise\<void>
```ts
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf().then((data) => {
console.info("==========================>terminateSelf=======================>");
console.info('==========================>terminateSelf=======================>');
});
```
......@@ -566,9 +566,9 @@ function onFailedCallback(code){
}
let connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
abilityName: "com.ix.ServiceAbility.ServiceAbilityA",
deviceId: '',
bundleName: 'com.ix.ServiceAbility',
abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -602,15 +602,15 @@ function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
}
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code);
}
let connectId = featureAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "com.ix.ServiceAbility.ServiceAbilityA",
bundleName: 'com.ix.ServiceAbility',
abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -620,8 +620,8 @@ let connectId = featureAbility.connectAbility(
);
featureAbility.disconnectAbility(connectId, (err) => {
console.log("featureAbilityTest disconnectAbility err====>"
+ ("json err=") + JSON.stringify(err));
console.error('featureAbilityTest disconnectAbility err====>'
+ ('json err=') + JSON.stringify(err));
});
```
......@@ -654,15 +654,15 @@ function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
}
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code);
}
let connectId = featureAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "com.ix.ServiceAbility.ServiceAbilityA",
bundleName: 'com.ix.ServiceAbility',
abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -674,7 +674,7 @@ let connectId = featureAbility.connectAbility(
featureAbility.disconnectAbility(connectId).then((data) => {
console.log('data : ' + data);
}).catch((error)=>{
console.log('featureAbilityTest result errCode : ' + error.code);
console.error('featureAbilityTest result errCode : ' + error.code);
});
```
......@@ -697,7 +697,7 @@ getWindow(callback: AsyncCallback\<window.Window>): void
```ts
featureAbility.getWindow((err, data) => {
console.info("getWindow err: " + JSON.stringify(err) + "data: " + typeof(data));
console.info('getWindow err: ' + JSON.stringify(err) + 'data: ' + typeof(data));
});
```
......@@ -719,7 +719,7 @@ getWindow(): Promise\<window.Window>;
```ts
featureAbility.getWindow().then((data) => {
console.info("getWindow data: " + typeof(data));
console.info('getWindow data: ' + typeof(data));
});
```
......@@ -760,9 +760,9 @@ featureAbility.AbilityStartSetting.BOUNDS_KEY
| 名称 | 值 | 说明 |
| ---------------------------- | --------------- | ---------------------------------------- |
| BOUNDS_KEY<sup>7+</sup> | "abilityBounds" | 窗口显示大小属性的参数名。 |
| WINDOW_MODE_KEY<sup>7+</sup> | "windowMode" | 窗口显示模式属性的参数名。|
| DISPLAY_ID_KEY<sup>7+</sup> | "displayId" | 窗口显示设备ID属性的参数名。 |
| BOUNDS_KEY<sup>7+</sup> | 'abilityBounds' | 窗口显示大小属性的参数名。 |
| WINDOW_MODE_KEY<sup>7+</sup> | 'windowMode' | 窗口显示模式属性的参数名。|
| DISPLAY_ID_KEY<sup>7+</sup> | 'displayId' | 窗口显示设备ID属性的参数名。 |
## ErrorCode
......
......@@ -14,7 +14,7 @@ particleAbility模块用来对Data和Service类型的Ability进行操作。
## 导入模块
```ts
import particleAbility from '@ohos.ability.particleAbility'
import particleAbility from '@ohos.ability.particleAbility';
```
## particleAbility.startAbility
......@@ -40,27 +40,27 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<void>):
**示例:**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from '@ohos.ability.wantConstant'
import particleAbility from '@ohos.ability.particleAbility';
import wantConstant from '@ohos.ability.wantConstant';
particleAbility.startAbility(
{
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.Data",
abilityName: "com.example.Data.MainAbility",
uri: ""
deviceId: '',
bundleName: 'com.example.Data',
abilityName: 'com.example.Data.MainAbility',
uri: ''
},
},
(error, result) => {
console.log('particleAbility startAbility errCode:' + error + 'result:' + result)
console.log('particleAbility startAbility errCode:' + error + 'result:' + result);
},
)
);
```
## particleAbility.startAbility
......@@ -91,25 +91,25 @@ startAbility(parameter: StartAbilityParameter): Promise\<void>;
**示例:**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from '@ohos.ability.wantConstant'
import particleAbility from '@ohos.ability.particleAbility';
import wantConstant from '@ohos.ability.wantConstant';
particleAbility.startAbility(
{
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.Data",
abilityName: "com.example. Data.MainAbility",
uri: ""
deviceId: '',
bundleName: 'com.example.Data',
abilityName: 'com.example. Data.MainAbility',
uri: ''
},
},
).then((data) => {
console.info("particleAbility startAbility");
console.info('particleAbility startAbility');
});
```
......@@ -130,13 +130,13 @@ terminateSelf(callback: AsyncCallback\<void>): void
**示例:**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import particleAbility from '@ohos.ability.particleAbility';
particleAbility.terminateSelf(
(error, result) => {
console.log('particleAbility terminateSelf errCode:' + error + 'result:' + result)
console.log('particleAbility terminateSelf errCode:' + error + 'result:' + result);
}
)
);
```
## particleAbility.terminateSelf
......@@ -156,10 +156,10 @@ terminateSelf(): Promise\<void>
**示例:**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import particleAbility from '@ohos.ability.particleAbility';
particleAbility.terminateSelf().then((data) => {
console.info("particleAbility terminateSelf");
console.info('particleAbility terminateSelf');
});
```
......@@ -188,10 +188,10 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper
**示例:**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import particleAbility from '@ohos.ability.particleAbility';
let uri = "";
particleAbility.acquireDataAbilityHelper(uri)
let uri = '';
particleAbility.acquireDataAbilityHelper(uri);
```
......@@ -222,17 +222,17 @@ import wantAgent from '@ohos.wantAgent';
function callback(err, data) {
if (err) {
console.error("Operation failed cause: " + JSON.stringify(err));
console.error('Operation failed cause: ' + JSON.stringify(err));
} else {
console.info("Operation succeeded");
console.info('Operation succeeded');
}
}
let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility"
bundleName: 'com.example.myapplication',
abilityName: 'com.example.myapplication.MainAbility'
}
],
operationType: wantAgent.OperationType.START_ABILITY,
......@@ -242,8 +242,8 @@ let wantAgentInfo = {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
let basicContent = {
title: "title",
text: "text"
title: 'title',
text: 'text'
};
let notificationContent = {
contentType: notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
......@@ -292,8 +292,8 @@ import wantAgent from '@ohos.wantAgent';
let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility"
bundleName: 'com.example.myapplication',
abilityName: 'com.example.myapplication.MainAbility'
}
],
operationType: wantAgent.OperationType.START_ABILITY,
......@@ -303,8 +303,8 @@ let wantAgentInfo = {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
let basicContent = {
title: "title",
text: "text"
title: 'title',
text: 'text'
};
let notificationContent = {
contentType: notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
......@@ -316,9 +316,9 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
};
let id = 1;
particleAbility.startBackgroundRunning(id, request).then(() => {
console.info("Operation succeeded");
console.info('Operation succeeded');
}).catch((err) => {
console.error("Operation failed cause: " + JSON.stringify(err));
console.error('Operation failed cause: ' + JSON.stringify(err));
});
});
......@@ -345,9 +345,9 @@ import particleAbility from '@ohos.ability.particleAbility';
function callback(err, data) {
if (err) {
console.error("Operation failed cause: " + JSON.stringify(err));
console.error('Operation failed cause: ' + JSON.stringify(err));
} else {
console.info("Operation succeeded");
console.info('Operation succeeded');
}
}
......@@ -375,9 +375,9 @@ cancelBackgroundRunning(): Promise&lt;void&gt;;
import particleAbility from '@ohos.ability.particleAbility';
particleAbility.cancelBackgroundRunning().then(() => {
console.info("Operation succeeded");
console.info('Operation succeeded');
}).catch((err) => {
console.error("Operation failed cause: " + JSON.stringify(err));
console.error('Operation failed cause: ' + JSON.stringify(err));
});
```
......@@ -401,25 +401,25 @@ connectAbility(request: Want, options:ConnectOptions): number
**示例**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import rpc from '@ohos.rpc'
import particleAbility from '@ohos.ability.particleAbility';
import rpc from '@ohos.rpc';
function onConnectCallback(element, remote) {
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element) {
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
}
function onFailedCallback(code) {
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code);
}
let connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
bundleName: 'com.ix.ServiceAbility',
abilityName: 'ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -429,9 +429,9 @@ let connId = particleAbility.connectAbility(
);
particleAbility.disconnectAbility(connId).then((data) => {
console.log(" data: " + data);
console.log(' data: ' + data);
}).catch((error) => {
console.log('particleAbilityTest result errCode : ' + error.code)
console.log('particleAbilityTest result errCode : ' + error.code);
});
```
......@@ -460,17 +460,17 @@ function onConnectCallback(element, remote) {
}
function onDisconnectCallback(element) {
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
}
function onFailedCallback(code) {
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code);
}
let connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
bundleName: 'com.ix.ServiceAbility',
abilityName: 'ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -480,8 +480,8 @@ let connId = particleAbility.connectAbility(
);
particleAbility.disconnectAbility(connId, (err) => {
console.log("particleAbilityTest disconnectAbility err====>"
+ ("json err=") + JSON.stringify(err));
console.log('particleAbilityTest disconnectAbility err====>'
+ ('json err=') + JSON.stringify(err));
});
```
......@@ -511,17 +511,17 @@ function onConnectCallback(element, remote) {
}
function onDisconnectCallback(element) {
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
}
function onFailedCallback(code) {
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code);
}
let connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
bundleName: 'com.ix.ServiceAbility',
abilityName: 'ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -531,9 +531,9 @@ let connId = particleAbility.connectAbility(
);
particleAbility.disconnectAbility(connId).then((data) => {
console.log(" data: " + data);
console.log(' data: ' + data);
}).catch((error) => {
console.log('particleAbilityTest result errCode : ' + error.code)
console.log('particleAbilityTest result errCode : ' + error.code);
});
```
......
......@@ -48,7 +48,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launchParam.launchReason === AbilityConstant.LaunchReason.START_ABILITY) {
console.log("The ability has been started by the way of startAbility.");
console.log('The ability has been started by the way of startAbility.');
}
}
}
......@@ -74,7 +74,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launchParam.lastExitReason === AbilityConstant.LastExitReason.ABILITY_NOT_RESPONDING) {
console.log("The ability has exit last because the ability was not responding.");
console.log('The ability has exit last because the ability was not responding.');
}
}
}
......@@ -122,8 +122,8 @@ class MyAbility extends UIAbility {
```ts
let want = {
bundleName: "com.test.example",
abilityName: "MainAbility"
bundleName: 'com.test.example',
abilityName: 'MainAbility'
};
let option = {
windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FULLSCREEN
......@@ -131,9 +131,9 @@ let option = {
// 确保从上下文获取到context
this.context.startAbility(want, option).then(()={
console.log("Succeed to start ability.");
console.log('Succeed to start ability.');
}).catch((error)=>{
console.log("Failed to start ability with error: " + JSON.stringify(error));
console.log('Failed to start ability with error: ' + JSON.stringify(error));
});
```
......@@ -157,7 +157,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onMemoryLevel(level) {
if (level === AbilityConstant.MemoryLevel.MEMORY_LEVEL_CRITICAL) {
console.log("The memory of device is critical, please release some memory.");
console.log('The memory of device is critical, please release some memory.');
}
}
}
......@@ -209,7 +209,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onSaveState(reason, wantParam) {
if (reason === AbilityConstant.StateType.CONTINUATION) {
console.log("Save the ability data when the ability continuation.");
console.log('Save the ability data when the ability continuation.');
}
return AbilityConstant.OnSaveResult.ALL_AGREE;
}
......
......@@ -49,14 +49,14 @@ import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let want = {
bundleName: "com.ohos.example",
abilityName: "MainAbility"
bundleName: 'com.ohos.example',
abilityName: 'MainAbility'
};
abilityDelegator.startAbility(want, (err) => {
if (err.code !== 0) {
console.log("Success start ability.");
console.log('Success start ability.');
} else {
console.log("Failed start ability, error: " + JSON.stringify(err));
console.log('Failed start ability, error: ' + JSON.stringify(err));
}
})
```
......@@ -81,8 +81,8 @@ getArguments(): AbilityDelegatorArgs
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
let args = AbilityDelegatorRegistry.getArguments();
console.info("getArguments bundleName:" + args.bundleName);
console.info("getArguments parameters:" + JSON.stringify(args.parameters));
console.info("getArguments testCaseNames:" + args.testCaseNames);
console.info("getArguments testRunnerClassName:" + args.testRunnerClassName);
console.info('getArguments bundleName:' + args.bundleName);
console.info('getArguments parameters:' + JSON.stringify(args.parameters));
console.info('getArguments testCaseNames:' + args.testCaseNames);
console.info('getArguments testRunnerClassName:' + args.testRunnerClassName);
```
......@@ -30,7 +30,7 @@ import AbilityStage from '@ohos.app.ability.AbilityStage';
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called");
console.log('MyAbilityStage.onCreate is called');
}
}
```
......@@ -63,8 +63,8 @@ import AbilityStage from '@ohos.app.ability.AbilityStage';
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
return "com.example.test";
console.log('MyAbilityStage.onAcceptWant called');
return 'com.example.test';
}
}
```
......
......@@ -99,15 +99,15 @@ import errorManager from '@ohos.app.ability.errorManager';
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
console.log('onUnhandledException, errorMsg: ', errorMsg);
appRecovery.restartApp();
}
};
try {
errorManager.on("error", observer);
errorManager.on('error', observer);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -133,14 +133,14 @@ import errorManager from '@ohos.app.ability.errorManager';
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
console.log('onUnhandledException, errorMsg: ', errorMsg);
appRecovery.saveAppState();
}
};
try {
errorManager.on("error", observer);
errorManager.on('error', observer);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册