提交 4413ec5e 编写于 作者: S sienna1128

Merge branch 'master' of https://gitee.com/openharmony/docs

...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## 场景介绍 ## 场景介绍
示例服务器解决了升级服务器实际应用场景中,缺乏相应搜包服务器提供查询升级包、获取升级包下载url等问题,支持测试升级服务和二次开发功能验证,为升级服务的应用场景提供尽可能完善的端到端环境搭建。 示例服务器解决了升级服务器实际应用场景中的问题,例如,缺乏相应的搜包服务器来提供查询升级包、获取升级包下载链接等服务。示例服务器支持测试升级服务和二次开发功能验证,为升级服务的应用场景提供尽可能完善的端到端环境搭建。
## 开发步骤 ## 开发步骤
......
...@@ -175,10 +175,15 @@ ...@@ -175,10 +175,15 @@
- [@ohos.telephony.data (蜂窝数据)](js-apis-telephony-data.md) - [@ohos.telephony.data (蜂窝数据)](js-apis-telephony-data.md)
- 网络管理 - 网络管理
- [@ohos.net.connection (网络连接管理)](js-apis-net-connection.md) - [@ohos.net.connection (网络连接管理)](js-apis-net-connection.md)
- [@ohos.net.statistics (网络流量管理)](js-apis-net-statistics.md)
- [@ohos.net.policy (网络策略管理)](js-apis-net-policy.md)
- [@ohos.net.ethernet (以太网连接管理)](js-apis-net-ethernet.md)
- [@ohos.net.sharing (网络共享管理)](js-apis-net-sharing.md)
- [@ohos.net.http (数据请求)](js-apis-http.md) - [@ohos.net.http (数据请求)](js-apis-http.md)
- [@ohos.request (上传下载)](js-apis-request.md) - [@ohos.request (上传下载)](js-apis-request.md)
- [@ohos.net.socket (Socket连接)](js-apis-socket.md) - [@ohos.net.socket (Socket连接)](js-apis-socket.md)
- [@ohos.net.webSocket (WebSocket连接)](js-apis-webSocket.md) - [@ohos.net.webSocket (WebSocket连接)](js-apis-webSocket.md)
- [@ohos.net.tlsSocket (TLSSocket连接)](js-apis-tlsSocket.md)
- 通信与连接 - 通信与连接
- [@ohos.bluetooth (蓝牙)](js-apis-bluetooth.md) - [@ohos.bluetooth (蓝牙)](js-apis-bluetooth.md)
......
...@@ -48,7 +48,11 @@ want操作的常数。 ...@@ -48,7 +48,11 @@ want操作的常数。
| ACTION_APP_ACCOUNT_OAUTH <sup>8+</sup> | ohos.account.appAccount.action.oauth | 指示提供oauth服务的操作。 | | ACTION_APP_ACCOUNT_OAUTH <sup>8+</sup> | ohos.account.appAccount.action.oauth | 指示提供oauth服务的操作。 |
| ACTION_MARKET_DOWNLOAD <sup>9+</sup> | ohos.want.action.marketDownload | 表示从应用程序市场下载应用程序的的操作。<br>**系统API**:该接口为系统接口,三方应用不支持调用。 | | ACTION_MARKET_DOWNLOAD <sup>9+</sup> | ohos.want.action.marketDownload | 表示从应用程序市场下载应用程序的的操作。<br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
| ACTION_MARKET_CROWDTEST <sup>9+</sup> | ohos.want.action.marketCrowdTest | 指示从应用程序市场众测应用程序的操作。<br>**系统API**:该接口为系统接口,三方应用不支持调用。 | | ACTION_MARKET_CROWDTEST <sup>9+</sup> | ohos.want.action.marketCrowdTest | 指示从应用程序市场众测应用程序的操作。<br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
| DLP_PARAMS_SANDBOX<sup>9+</sup> |ohos.dlp.params.sandbox | 指示沙盒标志的参数的操作。<br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
| DLP_PARAMS_BUNDLE_NAME<sup>9+</sup> |ohos.dlp.params.bundleName |指示DLP包名称的参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
| DLP_PARAMS_MODULE_NAME<sup>9+</sup> |ohos.dlp.params.moduleName |指示DLP模块名称的参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
| DLP_PARAMS_ABILITY_NAME<sup>9+</sup> |ohos.dlp.params.abilityName |指示DLP能力名称的参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
| DLP_PARAMS_INDEX<sup>9+</sup> |ohos.dlp.params.index |指示DLP索引参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
## wantConstant.Entity ## wantConstant.Entity
......
...@@ -27,7 +27,7 @@ class MainAbility extends AccessibilityExtensionAbility { ...@@ -27,7 +27,7 @@ class MainAbility extends AccessibilityExtensionAbility {
表示查询下一焦点元素的方向。 表示查询下一焦点元素的方向。
**系统能力**:以下各项对应的系统能力均为 SystemCapability.Barrierfree.Accessibility.Core **系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
| 名称 | 描述 | | 名称 | 描述 |
| -------- | ------- | | -------- | ------- |
...@@ -42,7 +42,7 @@ class MainAbility extends AccessibilityExtensionAbility { ...@@ -42,7 +42,7 @@ class MainAbility extends AccessibilityExtensionAbility {
表示查询焦点元素的类型。 表示查询焦点元素的类型。
**系统能力**:以下各项对应的系统能力均为 SystemCapability.Barrierfree.Accessibility.Core **系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
| 名称 | 描述 | | 名称 | 描述 |
| ------------- | ----------- | | ------------- | ----------- |
...@@ -53,7 +53,7 @@ class MainAbility extends AccessibilityExtensionAbility { ...@@ -53,7 +53,7 @@ class MainAbility extends AccessibilityExtensionAbility {
表示矩形区域。 表示矩形区域。
**系统能力**:以下各项对应的系统能力均为 SystemCapability.Barrierfree.Accessibility.Core **系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ------ | ------ | ---- | ---- | --------- | | ------ | ------ | ---- | ---- | --------- |
...@@ -66,7 +66,7 @@ class MainAbility extends AccessibilityExtensionAbility { ...@@ -66,7 +66,7 @@ class MainAbility extends AccessibilityExtensionAbility {
表示窗口的类型。 表示窗口的类型。
**系统能力**:以下各项对应的系统能力均为 SystemCapability.Barrierfree.Accessibility.Core **系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
| 名称 | 描述 | | 名称 | 描述 |
| ----------- | --------- | | ----------- | --------- |
...@@ -185,7 +185,7 @@ this.context.getWindows().then(windows => { ...@@ -185,7 +185,7 @@ this.context.getWindows().then(windows => {
## AccessibilityExtensionContext.injectGesture ## AccessibilityExtensionContext.injectGesture
injectGesture(gesturePath: GesturePath, listener: Callback\<boolean>): Promise\<void> injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void
注入手势。 注入手势。
...@@ -196,13 +196,7 @@ injectGesture(gesturePath: GesturePath, listener: Callback\<boolean>): Promise\< ...@@ -196,13 +196,7 @@ injectGesture(gesturePath: GesturePath, listener: Callback\<boolean>): Promise\<
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| ----------- | ---------------------------------------- | ---- | -------------- | | ----------- | ---------------------------------------- | ---- | -------------- |
| gesturePath | [GesturePath](js-apis-application-AccessibilityExtensionAbility.md#GesturePath) | 是 | 表示手势的路径信息。 | | gesturePath | [GesturePath](js-apis-application-AccessibilityExtensionAbility.md#GesturePath) | 是 | 表示手势的路径信息。 |
| listener | Callback&lt;boolean&gt; | 是 | 表示注入手势执行结果的回调。 | | callback | AsyncCallback&lt;void&gt; | 是 | 表示注入手势执行结果的回调。 |
**返回值:**
| 类型 | 说明 |
| ---------------------- | ---------------------- |
| Promise&lt;boolean&gt; | Promise对象。返回注入手势的调用结果。 |
**示例:** **示例:**
...@@ -218,7 +212,7 @@ this.context.gestureInject(gesturePath, (result) => { ...@@ -218,7 +212,7 @@ this.context.gestureInject(gesturePath, (result) => {
``` ```
## AccessibilityElement.attributeNames ## AccessibilityElement.attributeNames
attributeNames\<T extends keyof ElementAttributeValues>(): Promise\<Array<T>>; attributeNames\<T extends keyof ElementAttributeValues>(): Promise\<Array\<T>>;
获取节点元素的所有属性名称。 获取节点元素的所有属性名称。
...@@ -283,7 +277,7 @@ try { ...@@ -283,7 +277,7 @@ try {
## AccessibilityElement.actionNames ## AccessibilityElement.actionNames
actionNames(): Promise\<Array<string>>; actionNames(): Promise\<Array\<string>>;
获取节点元素支持的所有操作名称。 获取节点元素支持的所有操作名称。
...@@ -349,7 +343,7 @@ try { ...@@ -349,7 +343,7 @@ try {
## AccessibilityElement.findElement ## AccessibilityElement.findElement
findElement(type: 'content', condition: string): Promise\<Array<AccessibilityElement>>; findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityElement>>;
查询节点元素的指定内容。 查询节点元素的指定内容。
......
...@@ -173,6 +173,7 @@ on(type: 'enableChange', callback: Callback&lt;boolean&gt;): void; ...@@ -173,6 +173,7 @@ on(type: 'enableChange', callback: Callback&lt;boolean&gt;): void;
- **示例:** - **示例:**
```typescript ```typescript
let captionsManager = accessibility.getCaptionsManager();
captionsManager.on('enableChange',(data) => { captionsManager.on('enableChange',(data) => {
console.info('success data:subscribeStateObserver : ' + JSON.stringify(data)) console.info('success data:subscribeStateObserver : ' + JSON.stringify(data))
}) })
...@@ -194,6 +195,7 @@ on(type: 'styleChange', callback: Callback&lt;CaptionsStyle&gt;): void; ...@@ -194,6 +195,7 @@ on(type: 'styleChange', callback: Callback&lt;CaptionsStyle&gt;): void;
- **示例:** - **示例:**
```typescript ```typescript
let captionsManager = accessibility.getCaptionsManager();
captionsManager.on('styleChange',(data) => { captionsManager.on('styleChange',(data) => {
console.info('success data:subscribeStateObserver : ' + JSON.stringify(data)) console.info('success data:subscribeStateObserver : ' + JSON.stringify(data))
}) })
...@@ -215,6 +217,7 @@ off(type: 'enableChange', callback?: Callback&lt;boolean&gt;): void; ...@@ -215,6 +217,7 @@ off(type: 'enableChange', callback?: Callback&lt;boolean&gt;): void;
- **示例:** - **示例:**
```typescript ```typescript
let captionsManager = accessibility.getCaptionsManager();
captionsManager.off('enableChange') captionsManager.off('enableChange')
``` ```
...@@ -234,6 +237,7 @@ off(type: 'styleChange', callback?: Callback&lt;CaptionsStyle&gt;): void; ...@@ -234,6 +237,7 @@ off(type: 'styleChange', callback?: Callback&lt;CaptionsStyle&gt;): void;
- **示例:** - **示例:**
```typescript ```typescript
let captionsManager = accessibility.getCaptionsManager();
captionsManager.off('styleChange') captionsManager.off('styleChange')
``` ```
...@@ -361,11 +365,6 @@ getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise&lt;A ...@@ -361,11 +365,6 @@ getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise&lt;A
console.info(item.id); console.info(item.id);
console.info(item.name); console.info(item.name);
console.info(item.description); console.info(item.description);
console.info(item.abilityTypes);
console.info(item.eventTypes);
console.info(item.capabilities);
console.info(item.packageName);
console.info(item.filterBundleNames);
console.info(item.bundleName); console.info(item.bundleName);
} }
}).catch((error) => { }).catch((error) => {
...@@ -402,11 +401,6 @@ getAbilityLists(abilityType: AbilityType, stateType: AbilityState,callback: Asyn ...@@ -402,11 +401,6 @@ getAbilityLists(abilityType: AbilityType, stateType: AbilityState,callback: Asyn
console.info(item.id); console.info(item.id);
console.info(item.name); console.info(item.name);
console.info(item.description); console.info(item.description);
console.info(item.abilityTypes);
console.info(item.eventTypes);
console.info(item.capabilities);
console.info(item.packageName);
console.info(item.filterBundleNames);
console.info(item.bundleName); console.info(item.bundleName);
} }
}) })
...@@ -429,7 +423,7 @@ getCaptionsManager(): CaptionsManager ...@@ -429,7 +423,7 @@ getCaptionsManager(): CaptionsManager
- **示例:** - **示例:**
```typescript ```typescript
captionsManager = accessibility.getCaptionsManager() let captionsManager = accessibility.getCaptionsManager()
``` ```
## accessibility.on('accessibilityStateChange' | 'touchGuideStateChange') ## accessibility.on('accessibilityStateChange' | 'touchGuideStateChange')
...@@ -603,7 +597,12 @@ sendEvent(event: EventInfo): Promise&lt;void&gt; ...@@ -603,7 +597,12 @@ sendEvent(event: EventInfo): Promise&lt;void&gt;
- **示例:** - **示例:**
```typescript ```typescript
accessibility.sendEvent(this.eventInfo) let eventInfo : accessibility.EventInfo = {
type: 'focus',
bundleName: 'bundle',
triggerAction: 'focus'
}
accessibility.sendEvent(eventInfo)
.then((data) => { .then((data) => {
console.info('success data:sendEvent : ' + JSON.stringify(data)) console.info('success data:sendEvent : ' + JSON.stringify(data))
}).catch((error) => { }).catch((error) => {
...@@ -629,7 +628,12 @@ sendEvent(event: EventInfo, callback: AsyncCallback&lt;void&gt;): void ...@@ -629,7 +628,12 @@ sendEvent(event: EventInfo, callback: AsyncCallback&lt;void&gt;): void
- **示例:** - **示例:**
```typescript ```typescript
accessibility.sendEvent(this.eventInfo,(err, data) => { let eventInfo : accessibility.EventInfo = {
type: 'focus',
bundleName: 'bundle',
triggerAction: 'focus'
}
accessibility.sendEvent(eventInfo,(err, data) => {
if (err) { if (err) {
console.error('failed to sendEvent because ' + JSON.stringify(err)); console.error('failed to sendEvent because ' + JSON.stringify(err));
return; return;
......
# quickFixManager
quickFixManager模块提供快速修复的能力,快速修复是鸿蒙提供给开发者的一种技术手段,支持开发者以远快于(小时级、分钟级)应用升级的方式进行缺陷修复。
> **说明:**
>
> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```
import quickFixManager from '@ohos.application.quickFixManager';
```
## HapModuleQuickFixInfo
hap级别的快速修复信息。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.QuickFix
**系统API**: 此接口为系统接口,三方应用不支持调用。
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| moduleName | 只读 | string | 是 | hap包的名称。 |
| originHapHash | 只读 | string | 是 | 指示hap的哈希值。 |
| quickFixFilePath | 只读 | string | 是 | 指示快速修复文件的安装路径。 |
## ApplicationQuickFixInfo
应用级别的快速修复信息。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.QuickFix
**系统API**: 此接口为系统接口,三方应用不支持调用。
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| bundleName | 只读 | string | 是 | 应用的包名。 |
| bundleVersionCode | 只读 | number | 是 | 应用的版本号。 |
| bundleVersionName | 只读 | string | 是 | 应用版本号的文字描述。 |
| quickFixVersionCode | 只读 | number | 是 | 快速修复补丁包的版本号。 |
| quickFixVersionName | 只读 | string | 是 | 快速修复补丁包版本号的文字描述。 |
| hapModuleQuickFixInfo | 只读 | Array\<[HapModuleQuickFixInfo](#hapmodulequickfixinfo)> | 是 | hap级别的快速修复信息。 |
## quickFixManager.applyQuickFix
applyQuickFix(hapModuleQuickFixFiles: Array\<string>, callback: AsyncCallback\<void>): void;
快速修复的补丁安装接口。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.QuickFix
**系统API**: 此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| hapModuleQuickFixFiles | Array\<string> | 否 | 快速修复补丁文件(补丁文件需包含有效的文件路径)。 |
| callback | AsyncCallback\<void> | 否 | 表示指定的回调方法。 |
**示例:**
```js
import quickFixManager from '@ohos.application.quickFixManager'
let hapModuleQuickFixFiles = ["/data/storage/el2/base/entry.hqf"]
quickFixManager.applyQuickFix(hapModuleQuickFixFiles, (error) => {
if (error) {
console.info( `applyQuickFix failed with error + ${error}`)
} else {
console.info( 'applyQuickFix success')
}
})
```
## quickFixManager.applyQuickFix
applyQuickFix(hapModuleQuickFixFiles: Array\<string>): Promise<void>;
快速修复的补丁安装接口。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.QuickFix
**系统API**: 此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| hapModuleQuickFixFiles | Array\<string> | 否 | 快速修复补丁文件(补丁文件需包含有效的文件路径)。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise\<void> | 返回相应结果。 |
**示例:**
```js
import quickFixManager from '@ohos.application.quickFixManager'
let hapModuleQuickFixFiles = ["/data/storage/el2/base/entry.hqf"]
quickFixManager.applyQuickFix(hapModuleQuickFixFiles).then(() => {
console.info('applyQuickFix success')
}).catch((error) => {
console.info(`applyQuickFix err: + ${error}`)
})
```
## quickFixManager.getApplicationQuickFixInfo
getApplicationQuickFixInfo(bundleName: string, callback: AsyncCallback\<ApplicationQuickFixInfo>): void;
获取应用的快速修复信息。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.QuickFix
**系统API**: 此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| bundleName | string | 否 |应用的包名。 |
| callback | AsyncCallback\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | 否 | 应用的快速修复信息。 |
**示例:**
```js
import quickFixManager from '@ohos.application.quickFixManager'
let bundleName = "bundleName"
quickFixManager.getApplicationQuickFixInfo(bundleName, (error, data) => {
if (error) {
console.info(`getApplicationQuickFixInfo error: + ${error}`)
} else {
console.info(`getApplicationQuickFixInfo success: + ${data}`)
}
})
```
## quickFixManager.getApplicationQuickFixInfo
getApplicationQuickFixInfo(bundleName: string): Promise\<ApplicationQuickFixInfo>;
获取应用的快速修复信息。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.QuickFix
**系统API**: 此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| bundleName | string | 否 | 应用的包名。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | 返回应用的快速修复信息。 |
**示例:**
```js
import quickFixManager from '@ohos.application.quickFixManager'
let bundleName = "bundleName"
quickFixManager.getApplicationQuickFixInfo(bundleName).then((data) => {
console.info(`getApplicationQuickFixInfo success: + ${data}`)
}).catch((error) => {
console.info(`getApplicationQuickFixInfo err: + ${error}`)
})
```
\ No newline at end of file
# ShellCmdResult # ShellCmdResult
ShellCmdResult模块提供Shell命令执行结果的能力。 模块提供Shell命令执行结果的能力。
> **说明:** > **说明:**
> >
......
...@@ -784,7 +784,7 @@ onProcessDied(processData: ProcessData): void; ...@@ -784,7 +784,7 @@ onProcessDied(processData: ProcessData): void;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| processData | ProcessData | 否 | 进程信息。 | | processData | [ProcessData](#processdata) | 否 | 进程信息。 |
**示例:** **示例:**
...@@ -798,6 +798,34 @@ onProcessDied(processData: ProcessData): void; ...@@ -798,6 +798,34 @@ onProcessDied(processData: ProcessData): void;
console.log('-------- observerCode: ---------', observerCode); console.log('-------- observerCode: ---------', observerCode);
``` ```
## ApplicationStateObserver.onProcessStateChanged<sup>9+</sup>
onProcessStateChanged(processData: ProcessData): void;
当进程状态更改时调用。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**:该接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| processData | [ProcessData](#processdata) | 否 | 进程信息。 |
**示例:**
```js
var applicationStateObserver = {
onProcessStateChanged(processData) {
console.log('------------ onProcessStateChanged -----------', processData);
}
}
const observerCode = app.registerApplicationStateObserver(applicationStateObserver);
console.log('-------- observerCode: ---------', observerCode);
```
## AppStateData ## AppStateData
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
...@@ -837,8 +865,8 @@ onProcessDied(processData: ProcessData): void; ...@@ -837,8 +865,8 @@ onProcessDied(processData: ProcessData): void;
| pid<sup>8+</sup> | number | 是 | 否 | 进程ID。 | | pid<sup>8+</sup> | number | 是 | 否 | 进程ID。 |
| bundleName<sup>8+</sup> | string | 是 | 否 | 应用包名。 | | bundleName<sup>8+</sup> | string | 是 | 否 | 应用包名。 |
| uid<sup>8+</sup> | number | 是 | 否 | 用户ID。 | | uid<sup>8+</sup> | number | 是 | 否 | 用户ID。 |
| isContinuousTask<sup>9+</sup> | boolean | 是 | 否 | 判断过程是否为连续任务。 |
| isKeepAlive<sup>8+</sup> | boolean | 是 | 否 | 判断该过程是否保持活跃。 |
## ProcessRunningInfo ## ProcessRunningInfo
...@@ -875,4 +903,32 @@ onProcessDied(processData: ProcessData): void; ...@@ -875,4 +903,32 @@ onProcessDied(processData: ProcessData): void;
| pid<sup>9+</sup> | 只读 | number | 否 | 进程ID。 | | pid<sup>9+</sup> | 只读 | number | 否 | 进程ID。 |
| uid<sup>9+</sup> | 只读 | number | 否 | 用户ID。 | | uid<sup>9+</sup> | 只读 | number | 否 | 用户ID。 |
| processName<sup>9+</sup> | 只读 | string | 否 | 进程的名称。 | | processName<sup>9+</sup> | 只读 | string | 否 | 进程的名称。 |
| bundleNames<sup>9+</sup> | 只读 | Array\<string> | 否 | 进程中运行的bundleName数组。 | | bundleNames<sup>9+</sup> | 只读 | Array\<string> | 否 | 进程中运行的bundleName数组。 |
\ No newline at end of file
## ApplicationState<sup>9+</sup>
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**: 此接口为系统接口,三方应用不支持调用。
| 名称 | 值 | 描述 |
| -------------------- | --- | --------------------------------- |
| STATE_CREATE | 1 | 当应用在创建中的时候处于的状态。 |
| STATE_FOREGROUND | 2 | 当应用切换到前台的时候处于的状态。 |
| STATE_ACTIVE | 3 | 当应用在获焦的时候处于的状态。 |
| STATE_BACKGROUND | 4 | 当应用处于后台不可见时处于的状态。 |
| STATE_DESTROY | 5 | 当应用在销毁的时候处于的状态。 |
## ProcessState<sup>9+</sup>
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**: 此接口为系统接口,三方应用不支持调用。
| 名称 | 值 | 描述 |
| -------------------- | --- | --------------------------------- |
| STATE_CREATE | 1 | 当进程在创建中的时候处于的状态。 |
| STATE_FOREGROUND | 2 | 当进程切换到前台的时候处于的状态。 |
| STATE_ACTIVE | 3 | 当进程在获焦的时候处于的状态。 |
| STATE_BACKGROUND | 4 | 当进程处于后台不可见时处于的状态。 |
| STATE_DESTROY | 5 | 当进程在销毁的时候处于的状态。 |
...@@ -752,7 +752,7 @@ getRoutingManager(callback: AsyncCallback&lt;AudioRoutingManager&gt;): void ...@@ -752,7 +752,7 @@ getRoutingManager(callback: AsyncCallback&lt;AudioRoutingManager&gt;): void
**示例:** **示例:**
```js ```js
await audioManager.getRoutingManager((err, callback) => { audioManager.getRoutingManager((err, callback) => {
if (err) { if (err) {
console.error(`Result ERROR: ${err}`); console.error(`Result ERROR: ${err}`);
} }
...@@ -3360,28 +3360,19 @@ AudioRenderChangeInfo数组,只读。 ...@@ -3360,28 +3360,19 @@ AudioRenderChangeInfo数组,只读。
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
var audioStreamManager; var audioStreamManager;
var audioStreamManagerCB;
var resultFlag = false; var resultFlag = false;
var audioManager = audio.getAudioManager();
async function getStreamManager(){
await audioManager.getStreamManager().then(async function (data) {
audioStreamManager = data;
console.info('Get AudioStream Manager : Success');
}).catch((err) => {
console.error(`Get AudioStream Manager : ERROR : ${err}`);
});
}
audioManager.getStreamManager((err, data) => { audioManager.getStreamManager((err, data) => {
if (err) { if (err) {
console.error(`Get AudioStream Manager : ERROR : ${err}`); console.error(`Get AudioStream Manager : ERROR : ${err}`);
} else { } else {
audioStreamManagerCB = data; audioStreamManager = data;
console.info('Get AudioStream Manager : Success'); console.info('Get AudioStream Manager : Success');
} }
}); });
audioStreamManagerCB.on('audioRendererChange', (AudioRendererChangeInfoArray) => { audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => {
for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) { for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
console.info(`## RendererChange on is called for ${i} ##`); console.info(`## RendererChange on is called for ${i} ##`);
console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`); console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`);
...@@ -3434,6 +3425,16 @@ AudioCapturerChangeInfo数组,只读。 ...@@ -3434,6 +3425,16 @@ AudioCapturerChangeInfo数组,只读。
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
const audioManager = audio.getAudioManager(); const audioManager = audio.getAudioManager();
let audioStreamManager;
audioManager.getStreamManager((err, data) => {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
audioStreamManager = data;
}
});
var resultFlag = false; var resultFlag = false;
audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => { audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => {
for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) { for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
...@@ -3926,34 +3927,6 @@ write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void ...@@ -3926,34 +3927,6 @@ write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
**示例:** **示例:**
```js ```js
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility'
var audioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
channels: audio.AudioChannel.CHANNEL_2,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S32LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 0
}
var audioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
}
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data)=> {
audioRenderer = data;
console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
}).catch((err) => {
console.error(`AudioFrameworkRenderLog: AudioRenderer Created: ERROR: ${err}`);
});
var bufferSize; var bufferSize;
audioRenderer.getBufferSize().then((data)=> { audioRenderer.getBufferSize().then((data)=> {
console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`); console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
...@@ -4034,10 +4007,11 @@ audioRenderer.getBufferSize().then((data) => { ...@@ -4034,10 +4007,11 @@ audioRenderer.getBufferSize().then((data) => {
}); });
console.info(`BufferSize: ${bufferSize}`); console.info(`BufferSize: ${bufferSize}`);
var context = featureAbility.getContext(); var context = featureAbility.getContext();
var path;
async function getCacheDir(){ async function getCacheDir(){
path = await context.getCacheDir(); path = await context.getCacheDir();
} }
var filePath = 'data/StarWars10s-2C-48000-4SW.wav'; var filePath = path + '/StarWars10s-2C-48000-4SW.wav';
let ss = fileio.createStreamSync(filePath, 'r'); let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize); let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf); ss.readSync(buf);
...@@ -4139,33 +4113,6 @@ getBufferSize(): Promise\<number> ...@@ -4139,33 +4113,6 @@ getBufferSize(): Promise\<number>
**示例:** **示例:**
```js ```js
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
var audioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
channels: audio.AudioChannel.CHANNEL_2,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S32LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 0
}
var audioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
}
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
audioRenderer = data;
console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
}).catch((err) => {
console.info(`AudioFrameworkRenderLog: AudioRenderer Created: ERROR: ${err}`);
});
var bufferSize; var bufferSize;
audioRenderer.getBufferSize().then((data) => { audioRenderer.getBufferSize().then((data) => {
console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`); console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
...@@ -4300,26 +4247,6 @@ setInterruptMode(mode: InterruptMode): Promise&lt;void&gt; ...@@ -4300,26 +4247,6 @@ setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var audioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
channels: audio.AudioChannel.CHANNEL_1,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_MUSIC,
usage: audio.StreamUsage.STREAM_USAGE_MEDIA,
rendererFlags: 0
}
var audioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
}
let audioRenderer;
async function createAudioRenderer(){
audioRenderer = await audio.createAudioRenderer(audioRendererOptions);
}
let mode = 0; let mode = 0;
audioRenderer.setInterruptMode(mode).then(data=>{ audioRenderer.setInterruptMode(mode).then(data=>{
console.info('setInterruptMode Success!'); console.info('setInterruptMode Success!');
...@@ -4345,27 +4272,6 @@ setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void ...@@ -4345,27 +4272,6 @@ setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
var audioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
channels: audio.AudioChannel.CHANNEL_1,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_MUSIC,
usage: audio.StreamUsage.STREAM_USAGE_MEDIA,
rendererFlags: 0
}
var audioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
}
let audioRenderer;
async function createAudioRenderer(){
audioRenderer = await audio.createAudioRenderer(audioRendererOptions);
}
let mode = 1; let mode = 1;
audioRenderer.setInterruptMode(mode, (err, data)=>{ audioRenderer.setInterruptMode(mode, (err, data)=>{
if(err){ if(err){
...@@ -4740,33 +4646,6 @@ start(): Promise<void\> ...@@ -4740,33 +4646,6 @@ start(): Promise<void\>
**示例:** **示例:**
```js ```js
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
var audioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
channels: audio.AudioChannel.CHANNEL_2,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioCapturerInfo = {
source: audio.SourceType.SOURCE_TYPE_MIC,
capturerFlags: 0
}
var audioCapturerOptions = {
streamInfo: audioStreamInfo,
capturerInfo: audioCapturerInfo
}
var audioCapturer;
audio.createAudioCapturer(audioCapturerOptions).then((data) => {
audioCapturer = data;
console.info('AudioFrameworkRecLog: AudioCapturer Created: SUCCESS');
}).catch((err) => {
console.info(`AudioFrameworkRecLog: AudioCapturer Created: ERROR: ${err}`);
});
audioCapturer.start().then(() => { audioCapturer.start().then(() => {
console.info('AudioFrameworkRecLog: ---------START---------'); console.info('AudioFrameworkRecLog: ---------START---------');
console.info('AudioFrameworkRecLog: Capturer started: SUCCESS'); console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
......
...@@ -139,8 +139,8 @@ ...@@ -139,8 +139,8 @@
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------- | ------ | ---- | ---- | -------------------- | | ----------- | ------ | ---- | ---- | -------------------- |
| releaseType | string | 是 | 否 | 版本的最小兼容代码。 | | releaseType | string | 是 | 否 | 版本的名称。 |
| compatible | number | 是 | 否 | 版本的名称。 | | compatible | number | 是 | 否 | 版本的最小兼容代码。 |
| target | numbe | 是 | 否 | 目标版本号。 | | target | numbe | 是 | 否 | 目标版本号。 |
## Version ## Version
......
...@@ -66,6 +66,7 @@ connection.getDefaultNet().then(function (netHandle) { ...@@ -66,6 +66,7 @@ connection.getDefaultNet().then(function (netHandle) {
hasDefaultNet(callback: AsyncCallback\<boolean>): void hasDefaultNet(callback: AsyncCallback\<boolean>): void
检查默认数据网络是否被激活,使用callback方式作为异步方法。 检查默认数据网络是否被激活,使用callback方式作为异步方法。
默认数据网络:以太网>wifi>蜂窝,当只有一个网络为连接状态时,当前连接网络为默认数据网络。
**系统能力**:SystemCapability.Communication.NetManager.Core **系统能力**:SystemCapability.Communication.NetManager.Core
...@@ -89,6 +90,7 @@ connection.hasDefaultNet(function (error, has) { ...@@ -89,6 +90,7 @@ connection.hasDefaultNet(function (error, has) {
hasDefaultNet(): Promise\<boolean> hasDefaultNet(): Promise\<boolean>
检查默认数据网络是否被激活,使用Promise方式作为异步方法。 检查默认数据网络是否被激活,使用Promise方式作为异步方法。
默认数据网络:以太网>wifi>蜂窝,当只有一个网络为连接状态时,当前连接网络为默认数据网络。
**系统能力**:SystemCapability.Communication.NetManager.Core **系统能力**:SystemCapability.Communication.NetManager.Core
...@@ -794,6 +796,108 @@ netConnection.unregister(function (error) { ...@@ -794,6 +796,108 @@ netConnection.unregister(function (error) {
| ------ | ------ | ------------------------- | | ------ | ------ | ------------------------- |
| netId | number | 网络ID,必须大于等于100。 | | netId | number | 网络ID,必须大于等于100。 |
### bindSocket
bindSocket(socketParam: TCPSocket \| UDPSocket, callback: AsyncCallback\<void>): void;
将TCPSocket或UDPSocket绑定到当前网络,使用callback方式作为异步方法。
**需要权限**:ohos.permission.GET_NETWORK_INFO
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------------------------ | ---- | -------------------------------|
| socketParam | [TCPSocket](js-apis-socket.md#tcpsocket) \| [UDPSocket](js-apis-socket.md#udpsocket) | 是 | 待绑定的TCPSocket或UDPSocket对象。|
| callback | AsyncCallback\<void> | 是 | 回调函数 |
**示例:**
```js
connection.getDefaultNet().then(function (netHandle) {
var tcp = socket.constructTCPSocketInstance();
var udp = socket.constructUDPSocketInstance();
let socketType = "xxxx";
if (socketType == "TCPSocket") {
tcp.bind({
address: "xxxx", port: xxxx, family: xxxx
}, err => {
netHandle.bindSocket(tcp, function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
} else {
udp.on('message', callback);
udp.bind({
address: "xxxx", port: xxxx, family: xxxx
}, err => {
udp.on('message', (data) => {
console.log(JSON.stringify(data))
});
netHandle.bindSocket(udp, function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
});
})
}
}
```
### bindSocket
bindSocket(socketParam: TCPSocket \| UDPSocket): Promise\<void>;
将TCPSocket或UDPSockett绑定到当前网络,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.GET_NETWORK_INFO
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------------- | --------------------- | ---- | ------------------------------ |
| socketParam | [TCPSocket](js-apis-socket.md#tcpsocket) \| [UDPSocket](js-apis-socket.md#udpsocket) | 是 | 待绑定的TCPSocket或UDPSocket对象。|
**返回值:**
| 类型 | 说明 |
| -------------- | ---------------------- |
| Promise\<void> | 以Promise形式返回结果。 |
**示例:**
```js
connection.getDefaultNet().then(function (netHandle) {
var tcp = socket.constructTCPSocketInstance();
var udp = socket.constructUDPSocketInstance();
let socketType = "xxxx";
if(socketType == "TCPSocket") {
tcp.bind({
address: "xxxx", port: xxxx, family: xxxx
}, err => {
netHandle.bindSocket(tcp).then(err, data) {
console.log(JSON.stringify(data))
})
} else {
udp.on('message', callback);
udp.bind({
address: "xxxx", port: xxxx, family: xxxx
}, err => {
udp.on('message', (data) => {
console.log(JSON.stringify(data))
});
netHandle.bindSocket(tcp).then(err, data) {
console.log(JSON.stringify(data))
});
})
}
}
```
### getAddressesByName ### getAddressesByName
getAddressesByName(host: string, callback: AsyncCallback\<Array\<NetAddress>>): void getAddressesByName(host: string, callback: AsyncCallback\<Array\<NetAddress>>): void
...@@ -1018,4 +1122,4 @@ connection.getDefaultNet().then(function (netHandle) { ...@@ -1018,4 +1122,4 @@ connection.getDefaultNet().then(function (netHandle) {
| ------- | ------ | ------------------------------ | | ------- | ------ | ------------------------------ |
| address | string | 地址。 | | address | string | 地址。 |
| family | number | IPv4 = 1,IPv6 = 2,默认IPv4。 | | family | number | IPv4 = 1,IPv6 = 2,默认IPv4。 |
| port | number | 端口,取值范围\[0, 65535]。 | | port | number | 端口,取值范围\[0, 65535]。 |
\ No newline at end of file
# 以太网连接管理
以太网连接管理主要提供有线网络能力,提供设置有线网络的IP地址,子网掩码,网关,DNS等信息
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```js
import ethernet from '@ohos.net.ethernet'
```
## ethernet.setIfaceConfig
setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback\<void>): void;
设置网络接口配置信息,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | ------------------------------------------ |
| iface | string | 是 | 网络接口名 |
| ic | [InterfaceConfiguration](#interfaceconfiguration) | 是 | 要设置的网络接口配置信息 |
| callback | AsyncCallback\<void> | 是 | 回调函数,成功无返回,失败返回对应错误码。 |
**示例:**
```js
ethernet.setIfaceConfig("eth0", {mode:ethernet.STATIC,ipAddr:"192.168.1.123", routeAddr:"192.168.1.1",
gateAddr:"192.168.1.1", maskAddr:"255.255.255.0", dnsAddr0:"1.1.1.1", dnsAddr1:"2.2.2.2"},
(error) => {
if (error) {
console.log("setIfaceConfig callback error = " + error);
} else {
console.log("setIfaceConfig callback ok ");
}
});
```
## ethernet.setIfaceConfig
setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\<void>;
设置网络接口配置信息,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------------- | ---- | ------------------------ |
| iface | string | 是 | 接口名 |
| ic | [InterfaceConfiguration](#interfaceconfiguration) | 是 | 要设置的网络接口配置信息 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------------------- |
| Promise\<void> | 以Promise形式返回执行结果。成功无返回,失败返回对应错误码。 |
**示例:**
```js
ethernet.setIfaceConfig("eth0", {mode:ethernet.STATIC,ipAddr:"192.168.1.123", routeAddr:"192.168.1.1",
gateAddr:"192.168.1.1", maskAddr:"255.255.255.0", dnsAddr0:"1.1.1.1", dnsAddr1:"2.2.2.2"}).then(() => {
console.log("setIfaceConfig promiss ok ");
}).catch((error) => {
console.log("setIfaceConfig promiss error = " + error);
});
```
## ethernet.getIfaceConfig
getIfaceConfig(iface: string, callback: AsyncCallback\<InterfaceConfiguration>): void;
获取指定网络接口信息,使用callback方式作为异步方法。
**需要权限**:ohos.permission.GET_NETWORK_INFO
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ----- | ------------ |
| iface | string | 是 | 指定网络接口 |
| callback | AsyncCallback\<[InterfaceConfiguration](#interfaceconfiguration)> | 是 | 回调函数,返回指定网络接口信息 |
**示例:**
```js
ethernet.getIfaceConfig("eth0", (error, value) => {
if (error) {
console.log("getIfaceConfig callback error = " + error);
} else {
console.log("getIfaceConfig callback mode = " + value.mode);
console.log("getIfaceConfig callback ipAddr = " + value.ipAddr);
console.log("getIfaceConfig callback routeAddr = " + value.routeAddr);
console.log("getIfaceConfig callback gateAddr = " + value.gateAddr);
console.log("getIfaceConfig callback maskAddr = " + value.maskAddr);
console.log("getIfaceConfig callback dns0Addr = " + value.dns0Addr);
console.log("getIfaceConfig callback dns1Addr = " + value.dns1Addr);
}
});
```
## ethernet.getIfaceConfig
getIfaceConfig(iface: string): Promise\<InterfaceConfiguration>;
获取指定网络接口信息,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.GET_NETWORK_INFO
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ------------ |
| iface | string | 是 | 指定网络接口 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ---------------------------------- |
| Promise\<[InterfaceConfiguration](#interfaceconfiguration)> | 以Promise形式返回接口信息。 |
**示例:**
```js
ethernet.getIfaceConfig("eth0").then((data) => {
console.log("getIfaceConfig promiss mode = " + data.mode);
console.log("getIfaceConfig promiss ipAddr = " + data.ipAddr);
console.log("getIfaceConfig promiss routeAddr = " + data.routeAddr);
console.log("getIfaceConfig promiss gateAddr = " + data.gateAddr);
console.log("getIfaceConfig promiss maskAddr = " + data.maskAddr);
console.log("getIfaceConfig promiss dns0Addr = " + data.dns0Addr);
console.log("getIfaceConfig promiss dns1Addr = " + data.dns1Addr);
}).catch((error) => {
console.log("getIfaceConfig promiss error = " + error);
});
```
## ethernet.isIfaceActive
isIfaceActive(iface?: string, callback: AsyncCallback\<number>): void;
判断接口是否已激活,使用callback方式作为异步方法。
**需要权限**:ohos.permission.GET_NETWORK_INFO
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | -------------------------------------------------- |
| iface | string | 否 | 接口名。为空时代表查询是否存在激活接口 |
| callback | AsyncCallback\<number> | 是 | 回调函数,已激活:1,未激活:0,其他为获取失败错误码。 |
**示例:**
```js
ethernet.isIfaceActive("eth0", (error, value) => {
if (error) {
console.log("whether2Activate callback error = " + error);
} else {
console.log("whether2Activate callback = " + value);
}
});
```
## ethernet.isIfaceActive
isIfaceActive(iface?: string): Promise\<number>;
判断接口是否已激活,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.GET_NETWORK_INFO
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------------------- |
| iface | string | 否 | 接口名。为空时代表查询是否存在激活接口 |
**返回值:**
| 类型 | 说明 |
| ----------------| ------------------------------------------------------------------ |
| Promise\<number> | 以Promise形式返回获取结果。已激活:1,未激活:0,其他为获取失败错误码。|
**示例:**
```js
ethernet.isIfaceActive("eth0").then((data) => {
console.log("isIfaceActive promiss = " + data);
}).catch((error) => {
console.log("isIfaceActive promiss error = " + error);
});
```
## ethernet.getAllActiveIfaces
getAllActiveIfaces(callback: AsyncCallback\<Array\<string>>): void;
获取活动的网络接口,使用callback方式作为异步方法。
**需要权限**:ohos.permission.GET_NETWORK_INFO
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------ | ---- | ------------------------------ |
| callback | AsyncCallback\<Array\<string>> | 是 | 回调函数,返回值为对应接口名。 |
**示例:**
```js
ethernet.getAllActiveIfaces((error, value) => {
if (error) {
console.log("getAllActiveIfaces callback error = " + error);
} else {
console.log("getAllActiveIfaces callback value.length = " + value.length);
for (let i = 0; i < value.length; i++) {
console.log("getAllActiveIfaces callback = " + value[i]);
}
}
});
```
## ethernet.getAllActiveIfaces
getAllActiveIfaces(): Promise\<Array\<string>>;
获取活动的网络接口,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.GET_NETWORK_INFO
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
**返回值:**
| 类型 | 说明 |
| ------------------------------ | ----------------------------------------------- |
| Promise\<Array\<string>> | 以Promise形式返回获取结果。返回值为对应接口名。 |
**示例:**
```js
ethernet.getAllActiveIfaces().then((data) => {
console.log("getAllActiveIfaces promiss data.length = " + data.length);
for (let i = 0; i < data.length; i++) {
console.log("getAllActiveIfaces promiss = " + data[i]);
}
}).catch((error) => {
console.log("getAllActiveIfaces promiss error = " + error);
});
```
## InterfaceConfiguration
以太网连接配置网络信息。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Communication.NetManager.Core。
| 参数名 | 类型 | 说明 |
| ----------------------- | ----------------------------------- | ------------------------------------------------------------ |
| mode | [IPSetMode](#ipsetmode) | 以太网连接配置模式。 |
| ipAddr | string | 以太网连接静态配置ip信息,地址值范围0-255.0-255.0-255.0-255(DHCP模式无需配置)。 |
| route | string | 以太网连接静态配置路由信息,地址值范围0-255.0-255.0-255.0-255(DHCP模式无需配置)。 |
| gateway | string | 以太网连接配置网关信息,地址值范围0-255.0-255.0-255.0-255(DHCP模式无需配置)。 |
| netMask | string | 以太网连接配置子网掩码,地址值范围0-255.0-255.0-255.0-255(DHCP模式无需配置)。 |
| dnsServers | string | 以太网连接配置dns服务地址,地址值范围0-255.0-255.0-255.0-255(DHCP模式无需配置)多地址间用“,”隔开。 |
## IPSetMode
以太网连接模式。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Communication.NetManager.Core。
| 参数名 | 值 | 说明 |
| ------------------------ | ---- | ---------------------- |
| STATIC | 0 | 以太网连接静态配置网络信息。 |
| DHCP | 1 | 以太网连接动态配置网络信息。 |
# 网络策略管理
网络策略管理通过对用户使用数据流量进行控制管理,采用防火墙技术实现网络策略的管理。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```js
import policy from '@ohos.net.policy'
```
## policy.setBackgroundPolicy
setBackgroundPolicy(isAllowed: boolean, callback: AsyncCallback\<void>): void
设置后台网络策略,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| isAllowed | boolean | 是 | 是否允许应用后台使用数据 |
| callback | AsyncCallback\<void> | 是 | 回调函数,返回设定结果。 |
**示例:**
```js
policy.setBackgroundPolicy(Boolean(Number.parseInt(this.isBoolean))), (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
});
```
## policy.setBackgroundPolicy
setBackgroundPolicy(isAllowed: boolean): Promise\<void>
设置后台网络策略,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| isAllowed | boolean | 是 | 是否允许应用后台使用数据 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | 以Promise形式返回设定结果。 |
**示例:**
```js
policy.setBackgroundPolicy(Boolean(Number.parseInt(this.isBoolean))).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getBackgroundPolicy
getBackgroundPolicy(callback: AsyncCallback\<boolean>): void;
获取后台网络策略,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true代表后台策略为允许。 |
**示例:**
```js
policy.getBackgroundPolicy((err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
});
```
## policy.getBackgroundPolicy
getBackgroundPolicy(): Promise\<boolean>;
获取后台网络策略,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<boolean> | 以Promise形式返回设定结果。 |
**示例:**
```js
policy.getBackgroundPolicy().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.setPolicyByUid
setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback\<void>): void;
设置对应uid应用的访问计量网络的策略,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | 应用的唯一标识符 |
| policy | [NetUidPolicy](#netuidpolicy) | 是 | 应用对应的策略 |
| callback | AsyncCallback\<void> | 是 | 回调函数,返回设定结果。 |
**示例:**
```js
let param = {
uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy)
}
policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy), (err, data) => {
this.callBack(err, data);
});
```
## policy.setPolicyByUid
setPolicyByUid(uid: number, policy: NetUidPolicy): Promise\<void>;
设置对应uid应用的访问计量网络的策略,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | 应用的唯一标识符 |
| policy | [NetUidPolicy](#netuidpolicy) | 是 | 应用对应的策略 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | 以Promise形式返回设定结果。 |
**示例:**
```js
let param = {
uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy)
}
policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy)).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getPolicyByUid
getPolicyByUid(uid: number, callback: AsyncCallback\<NetUidPolicy>): void;
通过应用uid获取策略,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | app唯一标识符 |
| callback | AsyncCallback\<[NetUidPolicy](#netuidpolicy)> | 是 | 回调函数,返回获取结果。 |
**示例:**
```js
policy.getPolicyByUid(Number.parseInt(this.firstParam), (err, data) => {
this.callBack(err, data);
});
```
## policy.getPolicyByUid
getPolicyByUid(uid: number): Promise\<NetUidPolicy>;
通过应用uid获取策略,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | app唯一标识符 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<[NetUidPolicy](#netuidpolicy)> | 以Promise形式返回设定结果。 |
**示例:**
```js
policy.getPolicyByUid(Number.parseInt(this.firstParam)).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getUidsByPolicy
getUidsByPolicy(policy: NetUidPolicy, callback: AsyncCallback\<Array\<number>>): void;
通过策略获取设置这一策略的应用uid数组,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| policy | [NetUidPolicy](#netuidpolicy) | 是 | 应用对应的计量网络下的策略 |
| callback | AsyncCallback\<Array\<number>> | 是 | 回调函数,返回获取结果。 |
**示例:**
```js
policy.getUidsByPolicy(Number.parseInt(this.currentNetUidPolicy), (err, data) => {
this.callBack(err, data);
});
```
## policy.getUidsByPolicy
function getUidsByPolicy(policy: NetUidPolicy): Promise\<Array\<number>>;
通过策略获取设置这一策略的应用uid数组,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| policy | [NetUidPolicy](#netuidpolicy) | 是 | app对应的计量网络下的策略 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<Array\<number>> | 以Promise形式返回设定结果。 |
**示例:**
```js
policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getNetQuotaPolicies
getNetQuotaPolicies(callback: AsyncCallback\<Array\<NetQuotaPolicy>>): void;
获取计量网络策略,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<Array\<[NetQuotaPolicy](#netquotapolicy)>> | 是 | 回调函数,返回获取结果。 |
**示例:**
```js
policy.getNetQuotaPolicies((err, data) => {
this.callBack(err, data);
});
```
## policy.getNetQuotaPolicies
getNetQuotaPolicies(): Promise\<Array\<NetQuotaPolicy>>;
获取计量网络策略,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<Array\<[NetQuotaPolicy](#netquotapolicy)>> | 以Promise形式返回设定结果。 |
**示例:**
```js
policy.getNetQuotaPolicies().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.setNetQuotaPolicies
setNetQuotaPolicies(quotaPolicies: Array\<NetQuotaPolicy>, callback: AsyncCallback\<void>): void;
设置计量网络策略,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| quotaPolicies | Array\<[NetQuotaPolicy](#netquotapolicy)> | 是 | 计量网络策略 |
| callback | AsyncCallback\<void> | 是 | 回调函数,返回设定结果。 |
**示例:**
```js
let param = {netType:Number.parseInt(this.netType), iccid:this.iccid, ident:this.ident, periodDuration:this.periodDuration, warningBytes:Number.parseInt(this.warningBytes),
limitBytes:Number.parseInt(this.limitBytes), lastWarningRemind:this.lastWarningRemind, lastLimitRemind:this.lastLimitRemind, metered:Boolean(Number.parseInt(this.metered)), limitAction:this.limitAction};
this.netQuotaPolicyList.push(param);
policy.setNetQuotaPolicies(this.netQuotaPolicyList, (err, data) => {
this.callBack(err, data);
});
```
## policy.setNetQuotaPolicies
setNetQuotaPolicies(quotaPolicies: Array\<NetQuotaPolicy>): Promise\<void>;
设置计量网络策略,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| quotaPolicies | Array\<[NetQuotaPolicy](#netquotapolicy)> | 是 | 计量网络策略 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | 以Promise形式返回设定结果。 |
**示例:**
```js
let param = {netType:Number.parseInt(this.netType), iccid:this.iccid, ident:this.ident, periodDuration:this.periodDuration, warningBytes:Number.parseInt(this.warningBytes),
limitBytes:Number.parseInt(this.limitBytes), lastWarningRemind:this.lastWarningRemind, lastLimitRemind:this.lastLimitRemind, metered:Boolean(Number.parseInt(this.metered)), limitAction:this.limitAction};
this.netQuotaPolicyList.push(param);
policy.setNetQuotaPolicies(this.netQuotaPolicyList).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.restoreAllPolicies
restoreAllPolicies(iccid: string, callback: AsyncCallback\<void>): void;
重置对应sim卡id的蜂窝网络、后台网络策略、防火墙策略、应用对应的策略,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| iccid | string | 是 | SIM卡ID|
| callback | AsyncCallback\<void> | 是 | 回调函数,返回重置结果。 |
**示例:**
```js
this.firstParam = iccid;
policy.restoreAllPolicies(this.firstParam, (err, data) => {
this.callBack(err, data);
});
```
## policy.restoreAllPolicies
restoreAllPolicies(iccid: string): Promise\<void>;
重置对应sim卡id的蜂窝网络、后台网络策略、防火墙策略、应用对应的策略,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| iccid | string | 是 | SIM卡ID|
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | 以Promise形式返回设定结果。 |
**示例:**
```js
this.firstParam = iccid;
policy.restoreAllPolicies(this.firstParam).then((err, data){
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.isUidNetAllowed
isUidNetAllowed(uid: number, isMetered: boolean, callback: AsyncCallback\<boolean>): void;
获取对应uid能否访问计量或非计量网络,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | app唯一标识符 |
| isMetered | boolean | 是 | 是否为计量网络 |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示这个uid可以访问对应的计量网络。 |
**示例:**
```js
let param = {
uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean))
}
policy.isUidNetAllowed(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (err, data) => {
this.callBack(err, data);
});
```
## policy.isUidNetAllowed
isUidNetAllowed(uid: number, isMetered: boolean): Promise\<boolean>;
获取对应uid能否访问计量或非计量网络,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | app唯一标识符 |
| isMetered | boolean | 是 | 是否为计量网络 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<boolean> | 以Promise形式返回设定结果。 |
**示例:**
```js
let param = {
uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean))
}
policy.isUidNetAllowed(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.isUidNetAllowed
isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback\<boolean>): void;
获取对应uid能否访问指定的iface的网络,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | app唯一标识符 |
| iface | string | 是 | 网络对应的名称 |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示这个uid可以访问对应iface的网络。 |
**示例:**
```js
let param = {
uid: Number.parseInt(this.firstParam), iface: this.secondParam
}
policy.isUidNetAllowed(Number.parseInt(this.firstParam), this.secondParam, (err, data) => {
this.callBack(err, data);
});
```
## policy.isUidNetAllowed
isUidNetAllowed(uid: number, iface: string): Promise\<boolean>;
获取对应uid能否访问指定的iface的网络,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | app唯一标识符 |
| iface | string | 是 | 网络对应的名称 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<boolean> | 以Promise形式返回设定结果。 |
**示例:**
```js
let param = {
uid: Number.parseInt(this.firstParam), iface: this.secondParam
}
policy.isUidNetAllowed(Number.parseInt(this.firstParam), this.secondParam).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.setDeviceIdleAllowlist
setDeviceIdleAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\<void>): void;
设置指定uid能应用是否在休眠防火墙的白名单,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | app唯一标识符 |
| isAllowed | boolean | 是 | 是否加入白名单 |
| callback | callback: AsyncCallback\<void> | 是 | 回调函数,返回设定结果。 |
**示例:**
```js
let param = {
uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
}
policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (err, data) => {
this.callBack(err, data);
});
```
## policy.setDeviceIdleAllowlist
setDeviceIdleAllowList(uid: number, isAllowed: boolean): Promise\<void>;
设置指定uid能应用是否在休眠防火墙的白名单,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | app唯一标识符 |
| isAllowed | boolean | 是 | 是否加入白名单 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | 以Promise形式返回设定结果。 |
**示例:**
```js
let param = {
uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
}
policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getDeviceIdleAllowlist
getDeviceIdleAllowList(callback: AsyncCallback\<Array\<number>>): void;
获取休眠模式白名单所包含的uid数组,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<Array\<number>> | 是 | 回调函数,返回获取结果。 |
**示例:**
```js
policy.getDeviceIdleAllowList((err, data) => {
this.callBack(err, data);
});
```
## policy.getDeviceIdleAllowlist
getDeviceIdleAllowList(): Promise\<Array\<number>>;
获取休眠模式白名单所包含的uid数组,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<Array\<number>> | 以Promise形式返回设定结果。 |
**示例:**
```js
policy.getDeviceIdleAllowList().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getBackgroundPolicyByUid
getBackgroundPolicyByUid(uid: number, callback: AsyncCallback\<NetBackgroundPolicy>): void;
获取指定uid能否访问后台网络,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | app唯一标识符 |
| callback | AsyncCallback\<[NetBackgroundPolicy](#netbackgroundpolicy)> | 是 | 回调函数,返回获取结果。 |
**示例:**
```js
this.firstParam = uid
policy.getBackgroundPolicyByUid(Number.parseInt(this.firstParam), (err, data) => {
this.callBack(err, data);
});
```
## policy.getBackgroundPolicyByUid
getBackgroundPolicyByUid(uid: number): Promise\<NetBackgroundPolicy>;
获取指定uid能否访问后台网络,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | app唯一标识符 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<[NetBackgroundPolicy](#netbackgroundpolicy)> | 以Promise形式返回设定结果。 |
**示例:**
```js
this.firstParam = uid
policy.getBackgroundPolicyByUid(Number.parseInt(this.firstParam)).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.resetPolicies
resetPolicies(iccid: string, callback: AsyncCallback\<void>): void;
重置对应sim卡id的蜂窝网络、后台网络策略、防火墙策略、应用对应的策略,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| iccid | string | 是 | SIM卡ID|
| callback | AsyncCallback\<void> | 是 | 回调函数,返回重置结果。 |
**示例:**
```js
this.firstParam = iccid
policy.resetPolicies(this.firstParam, (err, data) => {
this.callBack(err, data);
});
```
## policy.resetPolicies
resetPolicies(iccid: string): Promise\<void>;
重置对应sim卡id的蜂窝网络、后台网络策略、防火墙策略、应用对应的策略,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| iccid | string | 是 | SIM卡ID|
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | 以Promise形式返回设定结果。 |
**示例:**
```js
policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then((err, data) {
})
this.firstParam = iccid
policy.resetPolicies(this.firstParam).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.updateRemindPolicy
updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType, callback: AsyncCallback\<void>): void;
更新提醒策略,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| netType | [NetBearType](js-apis-net-connection.md#netbeartype) | 是 | 网络类型 |
| iccid | string | 是 | SIM卡ID|
| remindType | [RemindType](#remindtype) | 是 | 提醒类型 |
| callback | AsyncCallback\<void> | 是 | 回调函数,返回更新结果。 |
**示例:**
```js
let param = {
netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType
}
policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType), (err, data) => {
this.callBack(err, data);
});
```
## policy.updateRemindPolicy
updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType): Promise\<void>;
更新提醒策略,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| netType | [NetBearType](js-apis-net-connection.md#netbeartype) | 是 | 网络类型 |
| iccid | string | 是 | SIM卡ID|
| remindType | [RemindType](#remindtype) | 是 | 提醒类型 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | 以Promise形式返回设定结果。 |
**示例:**
```js
let param = {
netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType
}
policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType)).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.on
网络策略的句柄。
### on('netUidPolicyChange')
on(type: "netUidPolicyChange", callback: Callback\<{ uid: number, policy: NetUidPolicy }>): void;
注册policy发生改变时的回调,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| type | netUidPolicyChange | 是 | policy发生改变的类型 |
| callback | Callback\<{ uid: number, policy: [NetUidPolicy](#netuidpolicy) }> | 是 | 回调函数。 |
**示例:**
```js
policy.on('netUidPolicyChange', (data) => {
this.log('on netUidPolicyChange:' + JSON.stringify(data));
})
```
### on('netUidRuleChange')
on(type: "netUidRuleChange", callback: Callback\<{ uid: number, rule: NetUidRule }>): void;
注册rule发生改变时的回调,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| type | netUidRuleChange | 是 | rule发生改变的类型 |
| callback | Callback\<{ uid: number, rule: [NetUidRule](#netuidrule) }> | 是 | 回调函数。 |
**示例:**
```js
policy.on('netUidRuleChange', (data) => {
this.log('on netUidRuleChange:' + JSON.stringify(data));
})
```
### on('netMeteredIfacesChange')
on(type: "netMeteredIfacesChange", callback: Callback\<Array\<string>>): void;
注册计量iface发生改变时的回调,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| type | netMeteredIfacesChange | 是 | 计量iface发生改变的类型 |
| callback | Callback\<Array\<string>> | 是 | 回调函数。 |
**示例:**
```js
policy.on('netMeteredIfacesChange', (data) => {
this.log('on netMeteredIfacesChange:' + JSON.stringify(data));
})
```
### on('netQuotaPolicyChange')
on(type: "netQuotaPolicyChange", callback: Callback\<Array\<NetQuotaPolicy>>): void;
注册计量网络策略发生改变时的回调,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| type | netQuotaPolicyChange | 是 | 计量网络策略发生改变的类型 |
| callback | Callback\<Array\<[NetQuotaPolicy](#netquotapolicy)>> | 是 | 回调函数。 |
**示例:**
```js
policy.on('netQuotaPolicyChange', (data) => {
this.log('on netQuotaPolicyChange:' + JSON.stringify(data));
})
```
### on('netBackgroundPolicyChange')
on(type: "netBackgroundPolicyChange", callback: Callback\<boolean>): void;
注册后台网络策略发生改变时的回调,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| type | netBackgroundPolicyChange | 是 | 后台网络策略发生改变的类型 |
| callback | Callback\<boolean> | 是 | 回调函数。 |
**示例:**
```js
policy.on('netBackgroundPolicyChange', (data) => {
this.log('on netBackgroundPolicyChange:' + JSON.stringify(data));
})
```
## NetBackgroundPolicy
后台网络策略。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Communication.NetManager.Core。
| 参数名 | 值 | 说明 |
| ------------------------ | ---- | ---------------------- |
| NET_BACKGROUND_POLICY_NONE | 0 | 默认值。 |
| NET_BACKGROUND_POLICY_ENABLE | 1 | 应用在后台可以使用计量网路。 |
| NET_BACKGROUND_POLICY_DISABLE | 2 | 应用在后台不可以使用计量网路。 |
| NET_BACKGROUND_POLICY_ALLOW_LIST | 3 | 只有应用指定的列表在后台可以使用计量网络。 |
## NetQuotaPolicy
计量网络策略。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Communication.NetManager.Core。
| 参数名 | 类型 | 说明 |
| ----------------------- | ----------------------------------- | ------------------------------------------------------------ |
| netType | [NetBearType](js-apis-net-connection.md#netbeartype) | 网络类型。 |
| iccid | string | 计量蜂窝网络的SIM卡的标识值。以太网,wify网络不会用到 |
| ident | string | 计量蜂窝网络中配合iccid联合使用。以太网,wify网络单独使用。用于标记类型。 |
| periodDuration | string | 计量开始时间。 |
| warningBytes | number | 发出警告的流量阈值。 |
| limitBytes | number | 流量设置的配额。 |
| lastWarningRemind | string | 最新一次发出警告的时间。 |
| lastLimitRemind | string | 最新一次配额耗尽的时间。 |
| metered | string | 是否为计量网络。 |
| limitAction | [LimitAction](#limitaction) | 到达流量限制后的动作。 |
## LimitAction
限制动作。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Communication.NetManager.Core。
| 参数名 | 值 | 说明 |
| ---------------------- | ----- | ------------ |
| LIMIT_ACTION_NONE | -1 | 默认值。 |
| LIMIT_ACTION_DISABLE | 0 | 当配额策略达到限制时,访问被禁用。 |
| LIMIT_ACTION_AUTO_BILL| 1 | 当配额策略达到限制时,用户将自动计费。 |
## NetUidRule
计量网络规则。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Communication.NetManager.Core。
| 参数名 | 值 | 说明 |
| ---------------------- | ----- | ------------ |
| NET_RULE_NONE | 0 | 默认规则 |
| NET_RULE_ALLOW_METERED_FOREGROUND | 1 | 允许前台访问计量网络 |
| NET_RULE_ALLOW_METERED | 2 | 允许访问计量网络 |
| NET_RULE_REJECT_METERED | 4 | 拒绝访问计量网络 |
| NET_RULE_ALLOW_ALL | 32 | 允许访问所有网络 |
| NET_RULE_REJECT_ALL | 64 | 拒绝访问所有网络 |
## RemindType
提醒类型。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Communication.NetManager.Core。
| 参数名 | 值 | 说明 |
| ---------------------- | - | ------- |
| REMIND_TYPE_WARNING | 1 | 警告提醒 |
| REMIND_TYPE_LIMIT | 2 | 限制提醒 |
## NetUidPolicy
应用对应的网络策略。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Communication.NetManager.Core。
| 参数名 | 值 | 说明 |
| ---------------------- | ----- | ------------ |
| NET_POLICY_NONE | 0 | 默认网络策略 |
| NET_POLICY_ALLOW_METERED_BACKGROUND | 1 | 允许应用在后台访问计量网络 |
| NET_POLICY_REJECT_METERED_BACKGROUND | 2 | 拒绝应用在后台访问计量网络 |
# 网络共享管理
网络共享管理分享设备已有网络给其他连接设备,支持Wi-Fi热点共享、蓝牙共享和USB共享,同时提供网络共享状态、共享流量查询功能。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```js
import sharing from '@ohos.net.sharing'
```
## sharing.isSharingSupported
isSharingSupported(callback: AsyncCallback\<boolean>): void
判断是否支持网络共享,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回ture代表支持网络共享。 |
**示例:**
```js
sharing.isSharingSupported((error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## sharing.isSharingSupported
isSharingSupported(): Promise\<boolean>
判断是否支持网络共享,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<boolean> | 以Promise形式返回是否支持共享结果。 |
**示例:**
```js
sharing.isSharingSupported().then(data => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## sharing.isSharing
isSharing(callback: AsyncCallback\<boolean>): void
获取当前网络共享状态,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回ture代表网络共享中。 |
**示例:**
```js
sharing.isSharing((error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## sharing.isSharing
isSharing(): Promise\<boolean>
获取当前网络共享状态,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<boolean> | 以Promise形式返回网络共享状态结果,返回ture代表网络共享中。 |
**示例:**
```js
sharing.isSharing().then(data => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## sharing.startSharing
startSharing(type: SharingIfaceType, callback: AsyncCallback\<void>): void
开启指定类型共享,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | [SharingIfaceType](#sharingifacetype) | 是 | 共享类型,0:Wi-Fi 1:USB 2:BLUETOOTH。 |
| callback | AsyncCallback\<void> | 是 | 回调函数,返回开启网络共享结果。 |
**示例:**
```js
import SharingIfaceType from '@ohos.net.sharing'
sharing.startSharing(SharingIfaceType.SHARING_WIFI, (error) => {
console.log(JSON.stringify(error));
});
```
## sharing.startSharing
startSharing(type: SharingIfaceType): Promise\<void>
开启指定类型共享,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | [SharingIfaceType](#sharingifacetype) | 是 | 共享类型,0:Wi-Fi 1:USB 2:BLUETOOTH。 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | 以Promise形式返回开启共享执行结果。 |
**示例:**
```js
import SharingIfaceType from '@ohos.net.sharing'
sharing.startSharing(SharingIfaceType.SHARING_WIFI).then(() => {
console.log("start wifi sharing successful");
}).catch(error => {
console.log("start wifi sharing failed");
});
```
## sharing.stopSharing
stopSharing(type: SharingIfaceType, callback: AsyncCallback\<void>): void
关闭指定类型共享,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | [SharingIfaceType](#sharingifacetype) | 是 | 共享类型,0:Wi-Fi 1:USB 2:BLUETOOTH。 |
| callback | AsyncCallback\<void> | 是 | 回调函数,返回停止网络共享结果。 |
**示例:**
```js
import SharingIfaceType from '@ohos.net.sharing'
sharing.stopSharing(SharingIfaceType.SHARING_WIFI, (error) => {
console.log(JSON.stringify(error));
});
```
## sharing.stopSharing
stopSharing(type: SharingIfaceType): Promise\<void>
关闭指定类型共享,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | [SharingIfaceType](#sharingifacetype) | 是 | 共享类型,0:Wi-Fi 1:USB 2:BLUETOOTH。 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | 以Promise形式返回关闭共享执行结果。 |
**示例:**
```js
import SharingIfaceType from '@ohos.net.sharing'
sharing.stopSharing(SharingIfaceType.SHARING_WIFI).then(() => {
console.log("stop wifi sharing successful");
}).catch(error => {
console.log("stop wifi sharing failed");
});
```
## sharing.getStatsRxBytes
getStatsRxBytes(callback: AsyncCallback\<number>): void
获取共享网络接收数据量,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | 是 | 回调函数,number代表数据量,单位:KB。 |
**示例:**
```js
sharing.getStatsRxBytes((error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## sharing.getStatsRxBytes
getStatsRxBytes(): Promise\<number>
获取共享网络接收数据量,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | 以Promise形式返回共享网络接收数据量,单位:KB。 |
**示例:**
```js
sharing.getStatsRxBytes().then(data => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## sharing.getStatsTxBytes
getStatsTxBytes(callback: AsyncCallback\<number>): void
获取共享网络发送数据量,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | 是 | 回调函数,number代表数据量,单位:KB。 |
**示例:**
```js
sharing.getStatsTxBytes((error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## sharing.getStatsTxBytes
getStatsTxBytes(): Promise\<number>
获取共享网络发送数据量,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | 以Promise形式返回共享网络发送数据量,单位:KB。 |
**示例:**
```js
sharing.getStatsTxBytes().then(data => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## sharing.getStatsTotalBytes
getStatsTotalBytes(callback: AsyncCallback\<number>): void
获取共享网络总数据量,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | 是 | 回调函数,number代表数据量,单位:KB。 |
**示例:**
```js
sharing.getStatsTotalBytes((error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## sharing.getStatsTotalBytes
getStatsTotalBytes(): Promise\<number>
获取共享网络总数据量,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | 以Promise形式返回共享网络总数据量,单位:KB。 |
**示例:**
```js
sharing.getStatsTotalBytes().then(data => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## sharing.getSharingIfaces
getSharingIfaces(state: SharingIfaceState, callback: AsyncCallback\<Array\<string>>): void
获取指定状态的网卡名称列表,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| state | state: [SharingIfaceState](#sharingifacestate) | 是 | 网络共享状态。 |
| callback | AsyncCallback\<Array\<string>> | 是 | 回调函数,返回指定状态的网卡名称列表。 |
**示例:**
```js
import SharingIfaceState from '@ohos.net.sharing'
sharing.getSharingIfaces(SharingIfaceState.SHARING_NIC_CAN_SERVER, (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## sharing.getSharingIfaces
getSharingIfaces(state: SharingIfaceState): Promise\<Array\<string>>
获取指定状态的网卡名称列表,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| state | state: [SharingIfaceState](#sharingifacestate) | 是 | 网络共享状态。 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<Array\<string>> | 以Promise形式返回指定状态网卡名称列表。 |
**示例:**
```js
import SharingIfaceState from '@ohos.net.sharing'
sharing.getSharingIfaces(SharingIfaceState.SHARING_NIC_CAN_SERVER).then(data => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## sharing.getSharingState
getSharingState(type: SharingIfaceType, callback: AsyncCallback\<SharingIfaceState>): void
获取指定类型网络共享状态,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | [SharingIfaceType](#sharingifacetype) | 是 | 共享类型,0:Wi-Fi 1:USB 2:BLUETOOTH。 |
| callback | AsyncCallback\<[SharingIfaceState](#sharingifacestate)> | 是 | 回调函数,返回指定类型网络共享状态。 |
**示例:**
```js
import SharingIfaceState from '@ohos.net.sharing'
sharing.getSharingState(SharingIfaceType.SHARING_WIFI, (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## sharing.getSharingState
getSharingState(type: SharingIfaceType): Promise\<SharingIfaceState>
获取指定类型网络共享状态,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | [SharingIfaceType](#sharingifacetype) | 是 | 共享类型,0:Wi-Fi 1:USB 2:BLUETOOTH。 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<[SharingIfaceState](#sharingifacestate)> | 以Promise形式返回定类型网络共共享状态。 |
**示例:**
```js
import SharingIfaceType from '@ohos.net.sharing'
sharing.getSharingIfaces(SharingIfaceType.SHARING_WIFI).then(data => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## sharing.getSharableRegexes
getSharableRegexes(type: SharingIfaceType, callback: AsyncCallback\<Array\<string>>): void
获取指定类型网卡名称正则表达式列表,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | [SharingIfaceType](#sharingifacetype) | 是 | 共享类型,0:Wi-Fi 1:USB 2:BLUETOOTH。 |
| callback | AsyncCallback\<Array\<string>> | 是 | 回调函数,返回指定类型网卡名称正则表达式列表。 |
**示例:**
```js
import SharingIfaceState from '@ohos.net.sharing'
sharing.getSharingState(SharingIfaceType.SHARING_WIFI, (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## sharing.getSharableRegexes
getSharableRegexes(type: SharingIfaceType): Promise\<Array\<string>>
获取指定类型网卡名称正则表达式列表,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | [SharingIfaceType](#sharingifacetype) | 是 | 共享类型,0:Wi-Fi 1:USB 2:BLUETOOTH。 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<Array\<string>> | 以Promise形式返回正则表达式列表。 |
**示例:**
```js
import SharingIfaceType from '@ohos.net.sharing'
sharing.getSharableRegexes(SharingIfaceType.SHARING_WIFI).then(data => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## on('sharingStateChange')
on(type: 'sharingStateChange', callback: Callback\<boolean>): void
注册网络共享状态变化事件,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | 是 | 事件名称。 |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回网络共享状态。 |
**示例:**
```js
sharing.on('sharingStateChange', (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## off('sharingStateChange')
off(type: 'sharingStateChange', callback?: Callback\<boolean>): void
注销网络共享状态变化事件,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | 是 | 事件名称。 |
| callback | AsyncCallback\<boolean> | 否 | 回调函数,返回网络共享状态。 |
**示例:**
```js
sharing.off('sharingStateChange', (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## on('interfaceSharingStateChange')
on(type: 'interfaceSharingStateChange', callback: Callback\<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void
注册网卡网络共享状态变化事件,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | 是 | 事件名称。 |
| callback | AsyncCallback\<{ type: [SharingIfaceType](#sharingifacetype), iface: string, state: SharingIfaceState(#sharingifacestate) }> | 是 | 回调函数,指定网卡共享状态变化时调用。 |
**示例:**
```js
sharing.on('interfaceSharingStateChange', (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## off('interfaceSharingStateChange')
off(type: 'interfaceSharingStateChange', callback?: Callback\<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void
注销网卡网络共享状态变化事件,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | 否 | 事件名称。 |
| callback | AsyncCallback\<{ type: [SharingIfaceType](#sharingifacetype), iface: string, state: SharingIfaceState(#sharingifacestate) }> | 否 | 回调函数,注销指定网卡共享状态变化通知。 |
**示例:**
```js
sharing.off('interfaceSharingStateChange', (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## on('sharingUpstreamChange')
on(type: 'sharingUpstreamChange', callback: Callback\<NetHandle>): void
注册上行网络变化事件,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | 是 | 事件名称。 |
| callback | AsyncCallback\<NetHandle> | 是 | 回调函数,上行网络变化时调用。 |
**示例:**
```js
sharing.on('sharingUpstreamChange', (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## off('sharingUpstreamChange')
off(type: 'sharingUpstreamChange', callback?: Callback\<NetHandle>): void
注销上行网络变化事件,使用callback方式作为异步方法。
**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | 是 | 事件名称。 |
| callback | AsyncCallback\<NetHandle> | 否 | 回调函数,注销上行网络变化事件。 |
**示例:**
```js
sharing.off('sharingUpstreamChange', (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
```
## SharingIfaceState
网络共享状态。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Communication.NetManager.Core。
| 参数名 | 值 | 说明 |
| ------------------------ | ---- | ---------------------- |
| SHARING_NIC_SERVING | 1 | 正在网络共享。 |
| SHARING_NIC_CAN_SERVER | 2 | 可提供网络共享。 |
| SHARING_NIC_ERROR | 3 | 网络共享错误。 |
## SharingIfaceType
网络共享类型。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Communication.NetManager.Core。
| 参数名 | 值 | 说明 |
| ------------------------ | ---- | ---------------------- |
| SHARING_WIFI | 0 | 网络共享类型Wi-Fi。 |
| SHARING_USB | 1 | 网络共享类型USB。 |
| SHARING_BLUETOOTH | 2 | 网络共享类型蓝牙。 |
# 网络流量管理
网络流量管理提供对用户上网过程中产生的流量进行统计,支持用户按网络接口(蜂窝、Wi-Fi)和按应用查询网络流量使用情况的功能
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```js
import statistics from '@ohos.net.statistics'
```
## statistics.getIfaceRxBytes
getIfaceRxBytes(nic: string, callback: AsyncCallback\<number>): void
获取指定网卡的接收数据量,使用callback方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | 是 | 网卡名 |
| callback | AsyncCallback\<number> | 是 | 回调函数,number代表数据量,单位:bytes。 |
**示例:**
```js
statistics.getIfaceRxBytes(this.nic, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getIfaceRxBytes
getIfaceRxBytes(nic: string): Promise\<number>;
获取指定网卡的接收数据量,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | 是 | 网卡名 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | 以Promise形式返回指定网卡的接收数据量,单位:bytes。 |
**示例:**
```js
statistics.getIfaceRxBytes(this.nic).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getIfaceTxBytes
getIfaceTxBytes(nic: string, callback: AsyncCallback\<number>): void
获取指定网卡的发送数据量,使用callback方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | 是 | 网卡名 |
| callback | AsyncCallback\<number> | 是 | 回调函数,number代表数据量,单位:bytes。 |
**示例:**
```js
statistics.getIfaceTxBytes(this.nic, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getIfaceTxBytes
getIfaceTxBytes(nic: string): Promise\<number>;
获取指定网卡的发送数据量,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | 是 | 网卡名 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | 以Promise形式返回指定网卡的发送数据量,单位:bytes。 |
**示例:**
```js
statistics.getIfaceTxBytes(this.nic).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularRxBytes
getCellularRxBytes(callback: AsyncCallback\<number>): void;
获取蜂窝网的接收数据量,使用callback方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | 是 | 回调函数,number代表数据量,单位:bytes。 |
**示例:**
```js
statistics.getCellularRxBytes((err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularRxBytes
getCellularRxBytes(): Promise\<number>;
获取蜂窝网的接收数据量,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | 以Promise形式返回蜂窝网的接收数据量,单位:bytes。 |
**示例:**
```js
statistics.getCellularRxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularTxBytes
getCellularTxBytes(callback: AsyncCallback\<number>): void;
获取蜂窝网的发送数据量,使用callback方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | 是 | 回调函数,number代表数据量,单位:bytes。 |
**示例:**
```js
statistics.getCellularTxBytes((err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularTxBytes
getCellularTxBytes(): Promise\<number>;
获取蜂窝网的发送数据量,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | 以Promise形式返回蜂窝网的发送数据量,单位:bytes。 |
**示例:**
```js
statistics.getCellularTxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getAllRxBytes
getAllRxBytes(callback: AsyncCallback\<number>): void;
获取所有网卡的接收数据量,使用callback方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | 是 | 回调函数,number代表数据量,单位:bytes。 |
**示例:**
```js
statistics.getAllRxBytes(err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getAllRxBytes
getAllRxBytes(): Promise\<number>;
获取所有网卡的接收数据量,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | 以Promise形式返回所有网卡的接收数据量,单位:bytes。 |
**示例:**
```js
statistics.getAllRxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getAllTxBytes
getAllTxBytes(callback: AsyncCallback\<number>): void;
获取所有网卡的发送数据,使用callback方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | 是 | 回调函数,number代表数据量,单位:bytes。 |
**示例:**
```js
statistics.getAllTxBytes((err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getAllTxBytes
getAllTxBytes(): Promise\<number>;
获取所有网卡的发送数据量,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | 以Promise形式返回所有网卡的发送数据量,单位:bytes。 |
**示例:**
```js
statistics.getAllTxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getUidRxBytes
getUidRxBytes(uid: number, callback: AsyncCallback\<number>): void;
获取指定应用的接收数据量,使用callback方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | 应用ID |
| callback | AsyncCallback\<number> | 是 | 回调函数,number代表数据量,单位:bytes。 |
**示例:**
```js
statistics.getUidRxBytes(this.uid, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getUidRxBytes
getUidRxBytes(uid: number): Promise\<number>;
获取指定应用的接收数据量,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | 应用ID |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | 以Promise形式返回指定网卡的接收数据量,单位:bytes。 |
**示例:**
```js
statistics.getUidRxBytes(this.uid).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getUidTxBytes
getUidTxBytes(uid: number, callback: AsyncCallback\<number>): void;
获取指定应用的发送数据量,使用callback方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | 应用ID |
| callback | AsyncCallback\<number> | 是 | 回调函数,number代表数据量,单位:bytes。 |
**示例:**
```js
statistics.getUidTxBytes(this.uid, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getUidTxBytes
getUidTxBytes(uid: number): Promise\<number>;
获取指定应用的发送数据量,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetManager.Core
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | 是 | 应用ID |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | 以Promise形式返回指定网卡的发送数据量,单位:bytes。 |
**示例:**
```js
statistics.getUidTxBytes(this.uid).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
...@@ -422,7 +422,7 @@ enableAirplaneMode(enable: boolean): Promise\<void> ...@@ -422,7 +422,7 @@ enableAirplaneMode(enable: boolean): Promise\<void>
```js ```js
let isEnabled = true; let isEnabled = true;
settingsenableAirplaneMode(isEnabled).then((err) => { settings.enableAirplaneMode(isEnabled).then((err) => {
if (err) { if (err) {
console.log('Failed to enable AirplaneMode.'); console.log('Failed to enable AirplaneMode.');
return; return;
......
...@@ -357,7 +357,7 @@ setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void ...@@ -357,7 +357,7 @@ setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
var data = new Date("October 13, 2020 11:13:00"); var data = new Date();
systemTime.setDate(data,(error, data) => { systemTime.setDate(data,(error, data) => {
if (error) { if (error) {
console.error('failed to systemTime.setDate because ' + JSON.stringify(error)); console.error('failed to systemTime.setDate because ' + JSON.stringify(error));
...@@ -393,7 +393,7 @@ setDate(date: Date): Promise&lt;void&gt; ...@@ -393,7 +393,7 @@ setDate(date: Date): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var data = new Date("October 13, 2020 11:13:00"); var data = new Date();
systemTime.setDate(data).then((value) => { systemTime.setDate(data).then((value) => {
console.log(`systemTime.setDate success data : ` + JSON.stringify(value)); console.log(`systemTime.setDate success data : ` + JSON.stringify(value));
}).catch((error) => { }).catch((error) => {
......
# TLSSocket
TLS Socket通信是对Socket通信的拓展。在Socket通信的基础上添加了一层安全性保护,提供了更高的安全性,分为三个子模块,包括密钥,证书,通信。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```js
import socket from '@ohos.net.tlssocket'
```
## socket.constructTLSSocketInstance
constructTLSSocketInstance(): TLSSocket
创建并返回一个TLSSocket对象。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**示例:**
```js
let tlssocket = socket.constructTLSSocketInstance();
```
## tlssocket.connect
connect(options: TLSConnectOptions, callback: AsyncCallback\<void>): void
在TLSSocket上进行通信连接,并创建和初始化TLS会话,实现建立连接过程,启动与服务器的TLS/SSL握手,实现数据传输功能,使用callback方式作为异步方法。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------| ----| --------------- |
| options | [TLSConnectOptions](#tlsconnectoptions) | 是 | 连接所需要的参数。|
| callback | AsyncCallback\<void> | 是 | 回调函数,成功无返回,失败返回对应错误码。 |
**示例:**
```js
let options = {
ALPNProtocols: ["spdy/1", "http/1.1"],
address: {
address: "xxx",
port: "xxxx",
family: 1,
},
secureOptions: {
key: "xxxx",
cert: "xxxx",
ca: ["xxxx"],
passwd: "xxxx",
protocols: "TlsV1_2",
useRemoteCipherPrefer: true,
signatureAlgorithms: SHA256,
cipherSuites: AES256-SHA256,
},
};
tlssocket.connect(options, (err, data) => {
console.info(err);
console.info(data);
});
```
## tlssocket.connect
connect(options: TLSConnectOptions): Promise\<void>;
在TLSSocket上进行通信连接,并创建和初始化TLS会话,实现建立连接过程,启动与服务器的TLS/SSL握手,实现数据传输功能,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------| ----| --------------- |
| options | [TLSConnectOptions](#tlsconnectoptions) | 是 | 连接所需要的参数。|
**返回值:**
| 类型 | 说明 |
| ------------------------------------------- | ----------------------------- |
| Promise\<void> | 以Promise形式返回,成功无返回,失败返回对应错误码。 |
**示例:**
```js
let options = {
ALPNProtocols: ["spdy/1", "http/1.1"],
address: {
address: "xxxx",
port: "xxxx",
family: 1,
},
secureOptions: {
key: "xxxx",
cert: "xxxx",
ca: ["xxxx"],
passwd: "xxxx",
protocols: "TlsV1_2",
useRemoteCipherPrefer: true,
signatureAlgorithms: SHA256,
cipherSuites: AES256-SHA256,
},
};
tlssocket.connect(options).then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getCertificate
getCertificate(callback: AsyncCallback\<string>): void;
在TLSSocket通信连接之后,获取本地的数字证书,使用callback方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<string> | 是 | 回调函数,返回本地的证书。|
**示例:**
```js
tlssocket.getCertificate((err, data) => {
if (err) {
console.log("getCertificate callback error = " + err);
} else {
console.log("getCertificate callback = " + data);
}
});
```
## tlssocket.getCertificate
getCertificate():Promise\<string>;
在TLSSocket通信连接之后,获取本地的数字证书,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**返回值:**
| 类型 | 说明 |
| -------------- | -------------------- |
| Promise\<string> | 以Promise形式返回本地的数字证书。 |
**示例:**
```js
tlssocket.getCertificate().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getRemoteCertificate
getRemoteCertificate(callback: AsyncCallback\<string>): void;
在TLSSocket通信连接之后,获取对等方的数字证书,使用callback方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<string> | 是 | 回调函数,返回对等方的证书。 |
**示例:**
```js
tlssocket.getRemoteCertificate((err, data) => {
if (err) {
console.log("getRemoteCertificate callback error = " + err);
} else {
console.log("getRemoteCertificate callback = " + data);
}
});
```
## tlssocket.getRemoteCertificate
getRemoteCertificate():Promise\<string>;
在TLSSocket通信连接之后,获取对等方的数字证书,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**返回值:**
| 类型 | 说明 |
| -------------- | -------------------- |
| Promise\<string> | 以Promise形式返回对等方的数字证书。 |
**示例:**
```js
tlssocket.getRemoteCertificate().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getProtocol
getProtocol(callback: AsyncCallback\<string>): void;
在TLSSocket通信连接之后,获取通信的协议,使用callback方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<string> | 是 | 回调函数,返回通信的协议。 |
**示例:**
```js
tlssocket.getProtocol((err, data) => {
if (err) {
console.log("getProtocol callback error = " + err);
} else {
console.log("getProtocol callback = " + data);
}
});
```
## tlssocket.getProtocol
getProtocol():Promise\<string>;
在TLSSocket通信连接之后,获取通信的协议,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**返回值:**
| 类型 | 说明 |
| -------------- | -------------------- |
| Promise\<string> | 以Promise形式返回通信的协议。 |
**示例:**
```js
tlssocket.getProtocol().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getCipherSuites
getCipherSuites(callback: AsyncCallback\<Array\<string>>): void;
在TLSSocket通信连接之后,获取通信双方支持的加密套件,使用callback方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<Array\<string>> | 是 | 回调函数,返回通信双方支持的加密套件。 |
**示例:**
```js
tlssocket.getCipherSuites((err, data) => {
if (err) {
console.log("getCipherSuites callback error = " + err);
} else {
console.log("getCipherSuites callback = " + data);
}
});
```
## tlssocket.getCipherSuites
getCipherSuites(): Promise\<Array\<string>>;
在TLSSocket通信连接之后,获取通信双方支持的加密套件,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**返回值:**
| 类型 | 说明 |
| ---------------------- | --------------------- |
| Promise\<Array\<string>> | 以Promise形式返回通信双方支持的加密套件。 |
**示例:**
```js
tlssocket.getCipherSuites().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getSignatureAlgorithms
getSignatureAlgorithms(callback: AsyncCallback\<Array\<string>>): void;
在TLSSocket通信连接之后,获取通信双方支持的签名算法,使用callback方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<Array\<string>> | 是 | 回调函数,返回双方支持的签名算法。 |
**示例:**
```js
tlssocket.getSignatureAlgorithms((err, data) => {
if (err) {
console.log("getSignatureAlgorithms callback error = " + err);
} else {
console.log("getSignatureAlgorithms callback = " + data);
}
});
```
## tlssocket.getSignatureAlgorithms
getSignatureAlgorithms(): Promise\<Array\<string>>;
在TLSSocket通信连接之后,获取通信双方支持的签名算法,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**返回值:**
| 类型 | 说明 |
| ---------------------- | -------------------- |
| Promise\<Array\<string>> | 以Promise形式返回获取到的双方支持的签名算法。 |
**示例:**
```js
tlssocket.getSignatureAlgorithms().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.close
close(callback: AsyncCallback\<void>): void;
在TLSSocket通信连接之后,断开连接,使用callback方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -----------------------------| ---- | ---------------|
| callback | AsyncCallback\<void> | 是 | 回调函数,返回TLSSocket关闭连接的结果。 |
**示例:**
```js
tlssocket.close((err) => {
if (err) {
console.log("close callback error = " + err);
} else {
console.log("close success");
}
});
```
## tlssocket.close
close(): Promise\<void>;
在TLSSocket通信连接之后,断开连接,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
**返回值:**
| 类型 | 说明 |
| -------------- | -------------------- |
| Promise\<void> | 以Promise形式返回,返回TLSSocket关闭连接的结果。 |
**示例:**
```js
tlssocket.close().then(() =>
console.log("close success");
}).catch(err => {
console.error(err);
});
```
## TLSConnectOptions
TLS连接的操作。
**系统能力**:SystemCapability.Communication.NetStack
| 参数名 | 类型 | 说明 |
| -------------- | ------------------------------------- | -------------- |
| address | [NetAddress](#netaddress) | 网关地址。 |
| secureOptions | [TLSSecureOptions](#tlssecureoptions) | TLS安全相关操作。|
| ALPNProtocols | Array\<string> | ALPN协议。 |
## NetAddress
网络地址。
**系统能力**:SystemCapability.Communication.NetStack
| 参数名 | 类型 | 说明 |
| ------- | ------ | ---------------------------- |
| address | string | 地址。 |
| family | number | IPv4 = 1,IPv6 = 2,默认IPv4。 |
| port | number | 端口,取值范围\[0, 65535]。 |
## TLSSecureOptions
TLS安全相关操作。
**系统能力**:SystemCapability.Communication.NetStack
| 参数名 | 类型 | 说明 |
| --------------------- | ---------------------- | ---------------------- |
| ca | string \| Array\<string> | ca证书。 |
| cert | string | 本地数字证书。 |
| key | string | 本地数字证书私钥。 |
| passwd | string | 密码。 |
| protocols | string | 协议名。 |
| useRemoteCipherPrefer | boolean | 优先使用对等方的密码套件。 |
| signatureAlgorithms | string | 设置签名算法。 |
| cipherSuites | string | 加密套件。 |
\ No newline at end of file
...@@ -303,8 +303,8 @@ create(id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): voi ...@@ -303,8 +303,8 @@ create(id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): voi
**示例:** **示例:**
```js ```js
var windowClass = null; let windowClass = null;
window.create("first", window.WindowType.TYPE_APP,(err,data) => { window.create('first', window.WindowType.TYPE_APP,(err,data) => {
if(err.code){ if(err.code){
console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));
return; return;
...@@ -340,8 +340,8 @@ create(id: string, type: WindowType): Promise&lt;Window&gt; ...@@ -340,8 +340,8 @@ create(id: string, type: WindowType): Promise&lt;Window&gt;
**示例:** **示例:**
```js ```js
var windowClass = null; let windowClass = null;
let promise = window.create("first", window.WindowType.TYPE_APP); let promise = window.create('first', window.WindowType.TYPE_APP);
promise.then((data)=> { promise.then((data)=> {
windowClass = data; windowClass = data;
console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data));
...@@ -372,8 +372,8 @@ create(ctx: Context, id: string, type: WindowType, callback: AsyncCallback&lt;Wi ...@@ -372,8 +372,8 @@ create(ctx: Context, id: string, type: WindowType, callback: AsyncCallback&lt;Wi
**示例:** **示例:**
```js ```js
var windowClass = null; let windowClass = null;
window.create(this.context, "alertWindow", window.WindowType.TYPE_SYSTEM_ALERT, (err, data) => { window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); console.error('Failed to create the window. Cause: ' + JSON.stringify(err));
return; return;
...@@ -411,8 +411,8 @@ create(ctx: Context, id: string, type: WindowType): Promise&lt;Window&gt; ...@@ -411,8 +411,8 @@ create(ctx: Context, id: string, type: WindowType): Promise&lt;Window&gt;
**示例:** **示例:**
```js ```js
var windowClass = null; let windowClass = null;
let promise = window.create(this.context, "alertWindow", window.WindowType.TYPE_SYSTEM_ALERT); let promise = window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT);
promise.then((data)=> { promise.then((data)=> {
windowClass = data; windowClass = data;
console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); console.info('Succeeded in creating the window. Data:' + JSON.stringify(data));
...@@ -439,8 +439,8 @@ find(id: string, callback: AsyncCallback&lt;Window&gt;): void ...@@ -439,8 +439,8 @@ find(id: string, callback: AsyncCallback&lt;Window&gt;): void
**示例:** **示例:**
```js ```js
var windowClass = null; let windowClass = null;
window.find("alertWindow", (err, data) => { window.find('alertWindow', (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); console.error('Failed to find the Window. Cause: ' + JSON.stringify(err));
return; return;
...@@ -473,8 +473,8 @@ find(id: string): Promise&lt;Window&gt; ...@@ -473,8 +473,8 @@ find(id: string): Promise&lt;Window&gt;
**示例:** **示例:**
```js ```js
var windowClass = null; let windowClass = null;
let promise = window.find("alertWindow"); let promise = window.find('alertWindow');
promise.then((data)=> { promise.then((data)=> {
windowClass = data; windowClass = data;
console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
...@@ -502,7 +502,7 @@ getTopWindow(callback: AsyncCallback&lt;Window&gt;): void ...@@ -502,7 +502,7 @@ getTopWindow(callback: AsyncCallback&lt;Window&gt;): void
**示例:** **示例:**
```js ```js
var windowClass = null; let windowClass = null;
window.getTopWindow((err, data) => { window.getTopWindow((err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
...@@ -532,7 +532,7 @@ getTopWindow(): Promise&lt;Window&gt; ...@@ -532,7 +532,7 @@ getTopWindow(): Promise&lt;Window&gt;
**示例:** **示例:**
```js ```js
var windowClass = null; let windowClass = null;
let promise = window.getTopWindow(); let promise = window.getTopWindow();
promise.then((data)=> { promise.then((data)=> {
windowClass = data; windowClass = data;
...@@ -560,7 +560,7 @@ getTopWindow(ctx: Context, callback: AsyncCallback&lt;Window&gt;): void ...@@ -560,7 +560,7 @@ getTopWindow(ctx: Context, callback: AsyncCallback&lt;Window&gt;): void
**示例:** **示例:**
```js ```js
var windowClass = null; let windowClass = null;
window.getTopWindow(this.context, (err, data) => { window.getTopWindow(this.context, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
...@@ -594,7 +594,7 @@ getTopWindow(ctx: Context): Promise&lt;Window&gt; ...@@ -594,7 +594,7 @@ getTopWindow(ctx: Context): Promise&lt;Window&gt;
**示例:** **示例:**
```js ```js
var windowClass = null; let windowClass = null;
let promise = window.getTopWindow(this.context); let promise = window.getTopWindow(this.context);
promise.then((data)=> { promise.then((data)=> {
windowClass = data; windowClass = data;
...@@ -626,7 +626,7 @@ minimizeAll(id: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -626,7 +626,7 @@ minimizeAll(id: number, callback: AsyncCallback&lt;void&gt;): void
import display from '@ohos.display' import display from '@ohos.display'
import window from '@ohos.window' import window from '@ohos.window'
var displayClass = null; let displayClass = null;
display.getDefaultDisplay((err, data) => { display.getDefaultDisplay((err, data) => {
if(err.code) { if(err.code) {
return; return;
...@@ -669,7 +669,7 @@ minimizeAll(id: number): Promise&lt;void&gt; ...@@ -669,7 +669,7 @@ minimizeAll(id: number): Promise&lt;void&gt;
import display from '@ohos.display' import display from '@ohos.display'
import window from '@ohos.window' import window from '@ohos.window'
var displayClass = null; let displayClass = null;
display.getDefaultDisplay((err, data) => { display.getDefaultDisplay((err, data) => {
if(err.code) { if(err.code) {
return; return;
...@@ -1259,7 +1259,7 @@ setWindowType(type: WindowType, callback: AsyncCallback&lt;void&gt;): void ...@@ -1259,7 +1259,7 @@ setWindowType(type: WindowType, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
var type = window.WindowType.TYPE_APP; let type = window.WindowType.TYPE_APP;
windowClass.setWindowType(type, (err, data) => { windowClass.setWindowType(type, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to set the window type. Cause: ' + JSON.stringify(err)); console.error('Failed to set the window type. Cause: ' + JSON.stringify(err));
...@@ -1298,7 +1298,7 @@ setWindowType(type: WindowType): Promise&lt;void&gt; ...@@ -1298,7 +1298,7 @@ setWindowType(type: WindowType): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var type = window.WindowType.TYPE_APP; let type = window.WindowType.TYPE_APP;
let promise = windowClass.setWindowType(type); let promise = windowClass.setWindowType(type);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in setting the window type. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the window type. Data: ' + JSON.stringify(data));
...@@ -1376,7 +1376,7 @@ getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback&lt; ...@@ -1376,7 +1376,7 @@ getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback&lt;
**示例:** **示例:**
```js ```js
var type = window.AvoidAreaType.TYPE_SYSTEM; let type = window.AvoidAreaType.TYPE_SYSTEM;
windowClass.getAvoidArea(type, (err, data) => { windowClass.getAvoidArea(type, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); console.error('Failed to obtain the area. Cause:' + JSON.stringify(err));
...@@ -1409,7 +1409,7 @@ getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise&lt;[AvoidArea](#av ...@@ -1409,7 +1409,7 @@ getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise&lt;[AvoidArea](#av
**示例:** **示例:**
```js ```js
var type = window.AvoidAreaType.TYPE_SYSTEM; let type = window.AvoidAreaType.TYPE_SYSTEM;
let promise = windowClass.getAvoidArea(type); let promise = windowClass.getAvoidArea(type);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
...@@ -1436,7 +1436,7 @@ setFullScreen(isFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void ...@@ -1436,7 +1436,7 @@ setFullScreen(isFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
var isFullScreen = true; let isFullScreen = true;
windowClass.setFullScreen(isFullScreen, (err, data) => { windowClass.setFullScreen(isFullScreen, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
...@@ -1469,7 +1469,7 @@ setFullScreen(isFullScreen: boolean): Promise&lt;void&gt; ...@@ -1469,7 +1469,7 @@ setFullScreen(isFullScreen: boolean): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var isFullScreen = true; let isFullScreen = true;
let promise = windowClass.setFullScreen(isFullScreen); let promise = windowClass.setFullScreen(isFullScreen);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data)); console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data));
...@@ -1496,7 +1496,7 @@ setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void ...@@ -1496,7 +1496,7 @@ setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void
**示例:** **示例:**
```js ```js
var isLayoutFullScreen= true; let isLayoutFullScreen= true;
windowClass.setLayoutFullScreen(isLayoutFullScreen, (err, data) => { windowClass.setLayoutFullScreen(isLayoutFullScreen, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
...@@ -1529,7 +1529,7 @@ setLayoutFullScreen(isLayoutFullScreen: boolean): Promise&lt;void&gt; ...@@ -1529,7 +1529,7 @@ setLayoutFullScreen(isLayoutFullScreen: boolean): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var isLayoutFullScreen = true; let isLayoutFullScreen = true;
let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen); let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data));
...@@ -1550,14 +1550,14 @@ setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallbac ...@@ -1550,14 +1550,14 @@ setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallbac
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| names | Array | 是 | 设置状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为["status",&nbsp;"navigation"];不设置,则默认不显示。 | | names | Array | 是 | 设置状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];不设置,则默认不显示。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
// 此处以不显示导航栏、状态栏为例 // 此处以不显示导航栏、状态栏为例
var names = []; let names = [];
windowClass.setSystemBarEnable(names, (err, data) => { windowClass.setSystemBarEnable(names, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err));
...@@ -1579,7 +1579,7 @@ setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise&lt;void&gt; ...@@ -1579,7 +1579,7 @@ setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise&lt;void&gt;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ----- | ---- | ------------------------------------------------------------ | | ------ | ----- | ---- | ------------------------------------------------------------ |
| names | Array | 是 | 设置状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为["status",&nbsp;"navigation"];不设置,则默认不显示。 | | names | Array | 是 | 设置状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];不设置,则默认不显示。 |
**返回值:** **返回值:**
...@@ -1591,7 +1591,7 @@ setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise&lt;void&gt; ...@@ -1591,7 +1591,7 @@ setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise&lt;void&gt;
```js ```js
// 此处以不显示导航栏、状态栏为例 // 此处以不显示导航栏、状态栏为例
var names = []; let names = [];
let promise = windowClass.setSystemBarEnable(names); let promise = windowClass.setSystemBarEnable(names);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in setting the system bar to be invisible. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the system bar to be invisible. Data: ' + JSON.stringify(data));
...@@ -1618,7 +1618,7 @@ setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: Async ...@@ -1618,7 +1618,7 @@ setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: Async
**示例:** **示例:**
```js ```js
var SystemBarProperties={ let SystemBarProperties={
statusBarColor: '#ff00ff', statusBarColor: '#ff00ff',
navigationBarColor: '#00ff00', navigationBarColor: '#00ff00',
//以下两个属性从API Version7开始支持 //以下两个属性从API Version7开始支持
...@@ -1660,7 +1660,7 @@ setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;voi ...@@ -1660,7 +1660,7 @@ setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;voi
**示例:** **示例:**
```js ```js
var SystemBarProperties={ let SystemBarProperties={
statusBarColor: '#ff00ff', statusBarColor: '#ff00ff',
navigationBarColor: '#00ff00', navigationBarColor: '#00ff00',
//以下两个属性从API Version7开始支持 //以下两个属性从API Version7开始支持
...@@ -1696,7 +1696,7 @@ setPreferredOrientation(orientation: Orientation, callback: AsyncCallback&lt;voi ...@@ -1696,7 +1696,7 @@ setPreferredOrientation(orientation: Orientation, callback: AsyncCallback&lt;voi
**示例:** **示例:**
```js ```js
var orientation = window.Orientation.AUTO_ROTATION; let orientation = window.Orientation.AUTO_ROTATION;
windowClass.setPreferredOrientation(orientation, (err, data) => { windowClass.setPreferredOrientation(orientation, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to set window orientation. Cause: ' + JSON.stringify(err)); console.error('Failed to set window orientation. Cause: ' + JSON.stringify(err));
...@@ -1729,7 +1729,7 @@ setPreferredOrientation(orientation: Orientation): Promise&lt;void&gt; ...@@ -1729,7 +1729,7 @@ setPreferredOrientation(orientation: Orientation): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var orientation = window.Orientation.AUTO_ROTATION; let orientation = window.Orientation.AUTO_ROTATION;
let promise = windowClass.setPreferredOrientation(orientation); let promise = windowClass.setPreferredOrientation(orientation);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in setting the window orientation. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the window orientation. Data: ' + JSON.stringify(data));
...@@ -1756,7 +1756,7 @@ loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -1756,7 +1756,7 @@ loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
windowClass.loadContent("pages/page2/page2", (err, data) => { windowClass.loadContent('pages/page2/page2', (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
...@@ -1788,7 +1788,7 @@ loadContent(path: string): Promise&lt;void&gt; ...@@ -1788,7 +1788,7 @@ loadContent(path: string): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let promise = windowClass.loadContent("pages/page2/page2"); let promise = windowClass.loadContent('pages/page2/page2');
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
}).catch((err)=>{ }).catch((err)=>{
...@@ -1820,9 +1820,9 @@ class myAbility extends Ability { ...@@ -1820,9 +1820,9 @@ class myAbility extends Ability {
storage : LocalStorage storage : LocalStorage
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.storage = new LocalStorage(); this.storage = new LocalStorage();
this.storage.setOrCreate("storageSimpleProp",121); this.storage.setOrCreate('storageSimpleProp',121);
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
windowStage.loadContent("pages/page2",this.storage,(err, data) => { windowStage.loadContent('pages/page2',this.storage,(err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
...@@ -1863,10 +1863,10 @@ class myAbility extends Ability { ...@@ -1863,10 +1863,10 @@ class myAbility extends Ability {
storage : LocalStorage storage : LocalStorage
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.storage = new LocalStorage(); this.storage = new LocalStorage();
this.storage.setOrCreate("storageSimpleProp",121); this.storage.setOrCreate('storageSimpleProp',121);
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
var windowClass = null; let windowClass = null;
let promise = windowStage.loadContent("pages/page2",this.storage); let promise = windowStage.loadContent('pages/page2',this.storage);
promise.then((data)=> { promise.then((data)=> {
windowClass = data; windowClass = data;
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
...@@ -2199,7 +2199,7 @@ off(type: 'screenshot', callback?: Callback&lt;void&gt;): void ...@@ -2199,7 +2199,7 @@ off(type: 'screenshot', callback?: Callback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
var callback = ()=>{ let callback = ()=>{
console.info('screenshot happened'); console.info('screenshot happened');
} }
windowClass.on('screenshot', callback) windowClass.on('screenshot', callback)
...@@ -2276,7 +2276,7 @@ bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback&lt;void&gt;, c ...@@ -2276,7 +2276,7 @@ bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback&lt;void&gt;, c
```js ```js
class MyDeathRecipient { class MyDeathRecipient {
onRemoteDied() { onRemoteDied() {
console.log("server died"); console.log('server died');
} }
} }
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
...@@ -2293,7 +2293,7 @@ class TestRemoteObject extends rpc.RemoteObject { ...@@ -2293,7 +2293,7 @@ class TestRemoteObject extends rpc.RemoteObject {
return false; return false;
} }
} }
let token = new TestRemoteObject("testObject"); let token = new TestRemoteObject('testObject');
windowClass.bindDialogTarget(token, () => { windowClass.bindDialogTarget(token, () => {
console.info('Dialog Window Need Destroy.'); console.info('Dialog Window Need Destroy.');
}, (err, data) => { }, (err, data) => {
...@@ -2333,7 +2333,7 @@ bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback&lt;void&gt;): ...@@ -2333,7 +2333,7 @@ bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback&lt;void&gt;):
```js ```js
class MyDeathRecipient { class MyDeathRecipient {
onRemoteDied() { onRemoteDied() {
console.log("server died"); console.log('server died');
} }
} }
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
...@@ -2350,7 +2350,7 @@ class TestRemoteObject extends rpc.RemoteObject { ...@@ -2350,7 +2350,7 @@ class TestRemoteObject extends rpc.RemoteObject {
return false; return false;
} }
} }
let token = new TestRemoteObject("testObject"); let token = new TestRemoteObject('testObject');
let promise = windowClass.bindDialogTarget(token, () => { let promise = windowClass.bindDialogTarget(token, () => {
console.info('Dialog Window Need Destroy.'); console.info('Dialog Window Need Destroy.');
}); });
...@@ -2539,7 +2539,7 @@ setBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -2539,7 +2539,7 @@ setBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
var color = '#00ff33'; let color = '#00ff33';
windowClass.setBackgroundColor(color, (err, data) => { windowClass.setBackgroundColor(color, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); console.error('Failed to set the background color. Cause: ' + JSON.stringify(err));
...@@ -2561,7 +2561,7 @@ setBackgroundColor(color: string): Promise&lt;void&gt; ...@@ -2561,7 +2561,7 @@ setBackgroundColor(color: string): Promise&lt;void&gt;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| color | string | 是 | 需要设置的背景色,为十六进制颜色,不区分大小写,例如"#00FF00"或"#FF00FF00"。 | | color | string | 是 | 需要设置的背景色,为十六进制颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 |
**返回值:** **返回值:**
...@@ -2572,7 +2572,7 @@ setBackgroundColor(color: string): Promise&lt;void&gt; ...@@ -2572,7 +2572,7 @@ setBackgroundColor(color: string): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var color = '#00ff33'; let color = '#00ff33';
let promise = windowClass.setBackgroundColor(color); let promise = windowClass.setBackgroundColor(color);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in setting the background color. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the background color. Data: ' + JSON.stringify(data));
...@@ -2600,7 +2600,7 @@ setWakeUpScreen(wakeUp: boolean): void; ...@@ -2600,7 +2600,7 @@ setWakeUpScreen(wakeUp: boolean): void;
**示例:** **示例:**
```js ```js
var wakeUp = true; let wakeUp = true;
windowClass.setWakeUpScreen(wakeUp); windowClass.setWakeUpScreen(wakeUp);
``` ```
...@@ -2622,7 +2622,7 @@ setBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -2622,7 +2622,7 @@ setBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
var brightness = 1; let brightness = 1;
windowClass.setBrightness(brightness, (err, data) => { windowClass.setBrightness(brightness, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
...@@ -2655,7 +2655,7 @@ setBrightness(brightness: number): Promise&lt;void&gt; ...@@ -2655,7 +2655,7 @@ setBrightness(brightness: number): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var brightness = 1; let brightness = 1;
let promise = windowClass.setBrightness(brightness); let promise = windowClass.setBrightness(brightness);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in setting the brightness. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the brightness. Data: ' + JSON.stringify(data));
...@@ -2748,7 +2748,7 @@ setFocusable(isFocusable: boolean, callback: AsyncCallback&lt;void&gt;): void ...@@ -2748,7 +2748,7 @@ setFocusable(isFocusable: boolean, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
var isFocusable= true; let isFocusable= true;
windowClass.setFocusable(isFocusable, (err, data) => { windowClass.setFocusable(isFocusable, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err)); console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err));
...@@ -2781,7 +2781,7 @@ setFocusable(isFocusable: boolean): Promise&lt;void&gt; ...@@ -2781,7 +2781,7 @@ setFocusable(isFocusable: boolean): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var isFocusable= true; let isFocusable= true;
let promise = windowClass.setFocusable(isFocusable); let promise = windowClass.setFocusable(isFocusable);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in setting the window to be focusable. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the window to be focusable. Data: ' + JSON.stringify(data));
...@@ -2808,7 +2808,7 @@ setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback&lt;void&gt;): v ...@@ -2808,7 +2808,7 @@ setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback&lt;void&gt;): v
**示例:** **示例:**
```js ```js
var isKeepScreenOn = true; let isKeepScreenOn = true;
windowClass.setKeepScreenOn(isKeepScreenOn, (err, data) => { windowClass.setKeepScreenOn(isKeepScreenOn, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err));
...@@ -2841,7 +2841,7 @@ setKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt; ...@@ -2841,7 +2841,7 @@ setKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var isKeepScreenOn = true; let isKeepScreenOn = true;
let promise = windowClass.setKeepScreenOn(isKeepScreenOn); let promise = windowClass.setKeepScreenOn(isKeepScreenOn);
promise.then((data) => { promise.then((data) => {
console.info('Succeeded in setting the screen to be always on. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the screen to be always on. Data: ' + JSON.stringify(data));
...@@ -2934,7 +2934,7 @@ setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): voi ...@@ -2934,7 +2934,7 @@ setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): voi
**示例:** **示例:**
```js ```js
var isPrivacyMode = true; let isPrivacyMode = true;
windowClass.setPrivacyMode(isPrivacyMode, (err, data) => { windowClass.setPrivacyMode(isPrivacyMode, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
...@@ -2968,7 +2968,7 @@ setPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt; ...@@ -2968,7 +2968,7 @@ setPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var isPrivacyMode = true; let isPrivacyMode = true;
let promise = windowClass.setPrivacyMode(isPrivacyMode); let promise = windowClass.setPrivacyMode(isPrivacyMode);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in setting the window to privacy mode. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the window to privacy mode. Data: ' + JSON.stringify(data));
...@@ -2992,7 +2992,7 @@ setSnapshotSkip(isSkip: boolean): void ...@@ -2992,7 +2992,7 @@ setSnapshotSkip(isSkip: boolean): void
| ------------- | ------- | ---- | -------------------- | | ------------- | ------- | ---- | -------------------- |
| isSkip | boolean | 是 | 截屏录屏是否忽略当前窗口,默认为false。<br>true表示忽略当前窗口,false表示不忽略当前窗口。</br> | | isSkip | boolean | 是 | 截屏录屏是否忽略当前窗口,默认为false。<br>true表示忽略当前窗口,false表示不忽略当前窗口。</br> |
```js ```js
var isSkip = true; let isSkip = true;
windowClass.setSnapshotSkip(isSkip); windowClass.setSnapshotSkip(isSkip);
``` ```
...@@ -3014,7 +3014,7 @@ setTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void ...@@ -3014,7 +3014,7 @@ setTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
var isTouchable = true; let isTouchable = true;
windowClass.setTouchable(isTouchable, (err, data) => { windowClass.setTouchable(isTouchable, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err));
...@@ -3048,7 +3048,7 @@ setTouchable(isTouchable: boolean): Promise&lt;void&gt; ...@@ -3048,7 +3048,7 @@ setTouchable(isTouchable: boolean): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var isTouchable = true; let isTouchable = true;
let promise = windowClass.setTouchable(isTouchable); let promise = windowClass.setTouchable(isTouchable);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in setting the window to be touchable. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the window to be touchable. Data: ' + JSON.stringify(data));
...@@ -3077,7 +3077,7 @@ setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback&lt;void&g ...@@ -3077,7 +3077,7 @@ setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback&lt;void&g
**示例:** **示例:**
```js ```js
var isForbidSplitMove = true; let isForbidSplitMove = true;
windowClass.setForbidSplitMove(isForbidSplitMove, (err, data) => { windowClass.setForbidSplitMove(isForbidSplitMove, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(err)); console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(err));
...@@ -3113,7 +3113,7 @@ setForbidSplitMove(isForbidSplitMove: boolean): Promise&lt;void&gt; ...@@ -3113,7 +3113,7 @@ setForbidSplitMove(isForbidSplitMove: boolean): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
var isForbidSplitMove = true; let isForbidSplitMove = true;
let promise = windowClass.setForbidSplitMove(isForbidSplitMove); let promise = windowClass.setForbidSplitMove(isForbidSplitMove);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in forbidding window moving in split screen mode. Data: ' + JSON.stringify(data)); console.info('Succeeded in forbidding window moving in split screen mode. Data: ' + JSON.stringify(data));
...@@ -3329,7 +3329,7 @@ scale(scaleOptions: ScaleOptions): void ...@@ -3329,7 +3329,7 @@ scale(scaleOptions: ScaleOptions): void
**示例:** **示例:**
```js ```js
var obj : window.ScaleOptions = { let obj : window.ScaleOptions = {
x : 2.0, x : 2.0,
y : 1.0, y : 1.0,
pivotX = 0.5; pivotX = 0.5;
...@@ -3357,7 +3357,7 @@ rotate(rotateOptions: RotateOptions): void ...@@ -3357,7 +3357,7 @@ rotate(rotateOptions: RotateOptions): void
**示例:** **示例:**
```js ```js
var obj : window.RotateOptions = { let obj : window.RotateOptions = {
x : 1.0, x : 1.0,
y : 1.0, y : 1.0,
z : 45.0, z : 45.0,
...@@ -3386,7 +3386,7 @@ translate(translateOptions: TranslateOptions): void ...@@ -3386,7 +3386,7 @@ translate(translateOptions: TranslateOptions): void
**示例:** **示例:**
```js ```js
var obj : window.TranslateOptions = { let obj : window.TranslateOptions = {
x : 100.0, x : 100.0,
y : 0.0, y : 0.0,
z : 0.0 z : 0.0
...@@ -3427,7 +3427,7 @@ controller.animationForHidden = (context : window.TransitionContext) => { ...@@ -3427,7 +3427,7 @@ controller.animationForHidden = (context : window.TransitionContext) => {
context.completeTransition(true) context.completeTransition(true)
} }
}, () => { }, () => {
var obj : window.TranslateOptions = { let obj : window.TranslateOptions = {
x : 100.0, x : 100.0,
y : 0.0, y : 0.0,
z : 0.0 z : 0.0
...@@ -3491,7 +3491,7 @@ import Ability from '@ohos.application.Ability'; ...@@ -3491,7 +3491,7 @@ import Ability from '@ohos.application.Ability';
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
var windowClass = null; let windowClass = null;
windowStage.getMainWindow((err, data) => { windowStage.getMainWindow((err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
...@@ -3526,7 +3526,7 @@ import Ability from '@ohos.application.Ability'; ...@@ -3526,7 +3526,7 @@ import Ability from '@ohos.application.Ability';
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
var windowClass = null; let windowClass = null;
let promise = windowStage.getMainWindow(); let promise = windowStage.getMainWindow();
promise.then((data)=> { promise.then((data)=> {
windowClass = data; windowClass = data;
...@@ -3561,8 +3561,8 @@ import Ability from '@ohos.application.Ability'; ...@@ -3561,8 +3561,8 @@ import Ability from '@ohos.application.Ability';
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
var windowClass = null; let windowClass = null;
windowStage.createSubWindow("mySubWindow", (err, data) => { windowStage.createSubWindow('mySubWindow', (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
return; return;
...@@ -3603,8 +3603,8 @@ import Ability from '@ohos.application.Ability'; ...@@ -3603,8 +3603,8 @@ import Ability from '@ohos.application.Ability';
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
var windowClass = null; let windowClass = null;
let promise = windowStage.createSubWindow("mySubWindow"); let promise = windowStage.createSubWindow('mySubWindow');
promise.then((data)=> { promise.then((data)=> {
windowClass = data; windowClass = data;
console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
...@@ -3637,7 +3637,7 @@ import Ability from '@ohos.application.Ability'; ...@@ -3637,7 +3637,7 @@ import Ability from '@ohos.application.Ability';
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
var windowClass = null; let windowClass = null;
windowStage.getSubWindow((err, data) => { windowStage.getSubWindow((err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err)); console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err));
...@@ -3672,7 +3672,7 @@ import Ability from '@ohos.application.Ability'; ...@@ -3672,7 +3672,7 @@ import Ability from '@ohos.application.Ability';
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
var windowClass = null; let windowClass = null;
let promise = windowStage.getSubWindow(); let promise = windowStage.getSubWindow();
promise.then((data)=> { promise.then((data)=> {
windowClass = data; windowClass = data;
...@@ -3709,9 +3709,9 @@ class myAbility extends Ability { ...@@ -3709,9 +3709,9 @@ class myAbility extends Ability {
storage : LocalStorage storage : LocalStorage
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.storage = new LocalStorage(); this.storage = new LocalStorage();
this.storage.setOrCreate("storageSimpleProp",121); this.storage.setOrCreate('storageSimpleProp',121);
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
windowStage.loadContent("pages/page2",this.storage,(err, data) => { windowStage.loadContent('pages/page2',this.storage,(err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
...@@ -3753,10 +3753,10 @@ class myAbility extends Ability { ...@@ -3753,10 +3753,10 @@ class myAbility extends Ability {
storage : LocalStorage storage : LocalStorage
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.storage = new LocalStorage(); this.storage = new LocalStorage();
this.storage.setOrCreate("storageSimpleProp",121); this.storage.setOrCreate('storageSimpleProp',121);
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
var windowClass = null; let windowClass = null;
let promise = windowStage.loadContent("pages/page2",this.storage); let promise = windowStage.loadContent('pages/page2',this.storage);
promise.then((data)=> { promise.then((data)=> {
windowClass = data; windowClass = data;
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
...@@ -3791,7 +3791,7 @@ import Ability from '@ohos.application.Ability'; ...@@ -3791,7 +3791,7 @@ import Ability from '@ohos.application.Ability';
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
windowStage.loadContent("pages/page2", (err, data) => { windowStage.loadContent('pages/page2', (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
...@@ -3959,7 +3959,7 @@ controller.animationForShown = (context : window.TransitionContext) => { ...@@ -3959,7 +3959,7 @@ controller.animationForShown = (context : window.TransitionContext) => {
iterations: 1, // 播放次数 iterations: 1, // 播放次数
playMode: PlayMode.Normal, // 动画模式 playMode: PlayMode.Normal, // 动画模式
}, () => { }, () => {
var obj : window.TranslateOptions = { let obj : window.TranslateOptions = {
x : 100.0, x : 100.0,
y : 0.0, y : 0.0,
z : 0.0 z : 0.0
...@@ -4010,7 +4010,7 @@ controller.animationForShown = (context : window.TransitionContext) => { ...@@ -4010,7 +4010,7 @@ controller.animationForShown = (context : window.TransitionContext) => {
context.completeTransition(true) context.completeTransition(true)
} }
}, () => { }, () => {
var obj : window.TranslateOptions = { let obj : window.TranslateOptions = {
x : 100.0, x : 100.0,
y : 0.0, y : 0.0,
z : 0.0 z : 0.0
...@@ -4056,7 +4056,7 @@ controller.animationForHidden = (context : window.TransitionContext) => { ...@@ -4056,7 +4056,7 @@ controller.animationForHidden = (context : window.TransitionContext) => {
context.completeTransition(true) context.completeTransition(true)
} }
}, () => { }, () => {
var obj : window.TranslateOptions = { let obj : window.TranslateOptions = {
x : 100.0, x : 100.0,
y : 0.0, y : 0.0,
z : 0.0 z : 0.0
......
...@@ -31,7 +31,7 @@ setController(controller: WindowAnimationController): void ...@@ -31,7 +31,7 @@ setController(controller: WindowAnimationController): void
**示例:** **示例:**
```js ```js
var controller = { let controller = {
onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget); console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget);
finishCallback.onAnimationFinish(); finishCallback.onAnimationFinish();
...@@ -88,8 +88,8 @@ minimizeWindowWithAnimation(windowTarget: WindowAnimationTarget, callback: Async ...@@ -88,8 +88,8 @@ minimizeWindowWithAnimation(windowTarget: WindowAnimationTarget, callback: Async
**示例:** **示例:**
```js ```js
var target: WindowAnimationTarget = undefined; let target: WindowAnimationTarget = undefined;
var controller = { let controller = {
onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget); console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget);
finishCallback.onAnimationFinish(); finishCallback.onAnimationFinish();
...@@ -127,7 +127,7 @@ var controller = { ...@@ -127,7 +127,7 @@ var controller = {
windowAnimationManager.setController(controller) windowAnimationManager.setController(controller)
var finishedCallback = null; let finishedCallback = null;
windowAnimationManager.minimizeWindowWithAnimation(target, (err, data) => { windowAnimationManager.minimizeWindowWithAnimation(target, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to minimize the window target. Cause: ' + JSON.stringify(err)); console.error('Failed to minimize the window target. Cause: ' + JSON.stringify(err));
...@@ -164,8 +164,8 @@ minimizeWindowWithAnimation(windowTarget: WindowAnimationTarget): Promise&lt;Win ...@@ -164,8 +164,8 @@ minimizeWindowWithAnimation(windowTarget: WindowAnimationTarget): Promise&lt;Win
**示例:** **示例:**
```js ```js
var target: WindowAnimationTarget = undefined; let target: WindowAnimationTarget = undefined;
var controller = { let controller = {
onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget); console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget);
finishCallback.onAnimationFinish(); finishCallback.onAnimationFinish();
......
...@@ -140,9 +140,9 @@ ...@@ -140,9 +140,9 @@
| Center<sup>(deprecated) </sup> | 竖直方向居中位置<br/> 从API version 9开始废弃 | | Center<sup>(deprecated) </sup> | 竖直方向居中位置<br/> 从API version 9开始废弃 |
| Bottom | 竖直方向下边缘 | | Bottom | 竖直方向下边缘 |
| Baseline<sup>(deprecated) </sup> | 交叉轴方向文本基线位置<br/> 从API version 9开始废弃 | | Baseline<sup>(deprecated) </sup> | 交叉轴方向文本基线位置<br/> 从API version 9开始废弃 |
| Start<sup>(deprecated) </sup> | 水平方向起始位置<br/> 从API version 9开始废弃 | | Start | 水平方向起始位置 |
| Middle<sup>(deprecated) </sup> | 水平方向居中位置<br/> 从API version 9开始废弃 | | Middle<sup>(deprecated) </sup> | 水平方向居中位置<br/> 从API version 9开始废弃 |
| End<sup>(deprecated) </sup> | 水平方向末尾位置<br/> 从API version 9开始废弃 | | End | 水平方向末尾位置 |
## Week ## Week
......
...@@ -53,7 +53,7 @@ Scroll(scroller?: Scroller) ...@@ -53,7 +53,7 @@ Scroll(scroller?: Scroller)
## Scroller ## Scroller
可滚动容器组件的控制器,可以将此组件绑定至容器组件,然后通过它控制容器组件的滚动,目前支持绑定到List、Scroll、ScrollBar上。 可滚动容器组件的控制器,可以将此组件绑定至容器组件,然后通过它控制容器组件的滚动,同一个控制器不可以控制多个容器组件,目前支持绑定到List、Scroll、ScrollBar上。
### 导入对象 ### 导入对象
......
...@@ -192,4 +192,10 @@ onWorkStop(work: WorkInfo): void | 延迟调度任务结束回调 ...@@ -192,4 +192,10 @@ onWorkStop(work: WorkInfo): void | 延迟调度任务结束回调
.catch(err => { .catch(err => {
console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.code); console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.code);
}); });
}) })
\ No newline at end of file
## 相关实例
基于延迟任务调度,有以下相关实例可供参考:
- [`WorkScheduler`:延迟任务调度(eTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/ResourcesSchedule/WorkScheduler)
\ No newline at end of file
# CSS语法参考 # CSS语法参考
CSS是描述HML页面结构的样式语言。所有组件均存在系统默认样式,也可在页面CSS样式文件中对组件、页面自定义不同的样式。请参考[通用样式](../reference/arkui-js/js-components-common-styles.md)了解基于JS扩展的类Web开发范式支持的组件样式。 CSS是描述HML页面结构的样式语言。所有组件均存在系统默认样式,也可在页面CSS样式文件中对组件、页面自定义不同的样式。请参考[通用样式](../reference/arkui-js/js-components-common-styles.md)了解兼容JS的类Web开发范式支持的组件样式。
## 尺寸单位 ## 尺寸单位
......
# 基本概念 # 基本概念
基于TS扩展的声明式开发范式提供了一系列基础组件,这些组件以声明方式进行组合和扩展来描述应用程序的UI界面,并且还提供了基本的数据绑定和事件处理机制,帮助开发者实现应用交互逻辑。 基于eTS的声明式开发范式提供了一系列基础组件,这些组件以声明方式进行组合和扩展来描述应用程序的UI界面,并且还提供了基本的数据绑定和事件处理机制,帮助开发者实现应用交互逻辑。
## HelloWorld基本示例 ## HelloWorld基本示例
......
# 自定义组件 # 自定义组件
使用基于JS扩展的类Web开发范式的方舟开发框架支持自定义组件,用户可根据业务需求将已有的组件进行扩展,增加自定义的私有属性和事件,封装成新的组件,方便在工程中多次调用,提高页面布局代码的可读性。具体的封装方法示例如下: 使用兼容JS的类Web开发范式的方舟开发框架支持自定义组件,用户可根据业务需求将已有的组件进行扩展,增加自定义的私有属性和事件,封装成新的组件,方便在工程中多次调用,提高页面布局代码的可读性。具体的封装方法示例如下:
- 构建自定义组件 - 构建自定义组件
......
# 概述 # 概述
基于TS扩展的声明式开发范式的方舟开发框架是一套开发极简、高性能、跨设备应用的UI开发框架,支持开发者高效的构建跨设备应用UI界面。 基于eTS的声明式开发范式的方舟开发框架是一套开发极简、高性能、跨设备应用的UI开发框架,支持开发者高效的构建跨设备应用UI界面。
## 基础能力 ## 基础能力
使用基于TS扩展的声明式开发范式的方舟开发框架,采用更接近自然语义的编程方式,让开发者可以直观地描述UI界面,不必关心框架如何实现UI绘制和渲染,实现极简高效开发。开发框架不仅从组件、动效和状态管理三个维度来提供UI能力,还提供了系统能力接口,实现系统能力的极简调用。 使用基于eTS的声明式开发范式的方舟开发框架,采用更接近自然语义的编程方式,让开发者可以直观地描述UI界面,不必关心框架如何实现UI绘制和渲染,实现极简高效开发。开发框架不仅从组件、动效和状态管理三个维度来提供UI能力,还提供了系统能力接口,实现系统能力的极简调用。
请参考[基于TS扩展的声明式开发范式API](../reference/arkui-ts/ts-universal-events-click.md)文档,全面地了解组件,更好地开发应用。 请参考[基于eTS的声明式开发范式API](../reference/arkui-ts/ts-universal-events-click.md)文档,全面地了解组件,更好地开发应用。
- **开箱即用的组件** - **开箱即用的组件**
...@@ -22,12 +22,12 @@ ...@@ -22,12 +22,12 @@
- **状态与数据管理** - **状态与数据管理**
状态数据管理作为基于TS扩展的声明式开发范式的特色,通过功能不同的装饰器给开发者提供了清晰的页面更新渲染流程和管道。状态管理包括UI组件状态和应用程序状态,两者协作可以使开发者完整地构建整个应用的数据更新和UI渲染。 状态数据管理作为基于eTS的声明式开发范式的特色,通过功能不同的装饰器给开发者提供了清晰的页面更新渲染流程和管道。状态管理包括UI组件状态和应用程序状态,两者协作可以使开发者完整地构建整个应用的数据更新和UI渲染。
- **系统能力接口** - **系统能力接口**
使用基于TS扩展的声明式开发范式的方舟开发框架,还封装了丰富的系统能力接口,开发者可以通过简单的接口调用,实现从UI设计到系统能力调用的极简开发。 使用基于eTS的声明式开发范式的方舟开发框架,还封装了丰富的系统能力接口,开发者可以通过简单的接口调用,实现从UI设计到系统能力调用的极简开发。
## 整体架构 ## 整体架构
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
## 相关实例 ## 相关实例
基于TS扩展的声明式开发范式的方舟开发框架,有以下相关实例可供参考: 基于eTS的声明式开发范式的方舟开发框架,有以下相关实例可供参考:
- [`Canvas`:画布组件(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/Canvas) - [`Canvas`:画布组件(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/Canvas)
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
- [`Gallery`:组件集合(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/Gallery) - [`Gallery`:组件集合(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/Gallery)
- [`BringApp`:拉起系统应用(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/BringApp) - [`BringApp`:拉起系统应用(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/BringApp)
- [`Chat`:聊天示例应用(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/AppSample/Chat) - [`Chat`:聊天示例应用(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/AppSample/Chat)
...@@ -95,7 +95,7 @@ ...@@ -95,7 +95,7 @@
- [`Search`:Search组件(eTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/Search) - [`Search`:Search组件(eTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/Search)
- [`QRCode`:二维码(eTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/QRCode) - [`QRCode`:二维码(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/QRCode)
- [极简声明式UI范式(eTS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/ETSUI/SimpleGalleryEts) - [极简声明式UI范式(eTS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/ETSUI/SimpleGalleryEts)
......
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
步骤写作要求: 步骤写作要求:
- 步骤里涉及的接口在前面开放能力介绍里有说明。 - 步骤里涉及的接口在前面开放能力介绍里有说明。
- 如果操作可选,要明确可选条件 - 如果操作可选,要明确可选条件
- 每一个开发步骤,如果涉及接口调用,需要清晰给出使用的接口及其使用说明,或给出示例代码 - 每一个开发步骤,如果涉及接口调用,需要清晰给出使用的接口及其使用说明,或给出示例代码
**介绍性文档**以开发指南某一功能为例,文档结构可以参考如下: **介绍性文档**以开发指南某一功能为例,文档结构可以参考如下:
...@@ -109,38 +109,12 @@ Output ...@@ -109,38 +109,12 @@ Output
**表 1** 参数表 **表 1** 参数表
<a name="table163931041183019"></a> | Tables | Type | Note |
<table><thead align="left"><tr id="row1393134183014"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p1539314418307"><a name="p1539314418307"></a><a name="p1539314418307"></a>Tables</p> | ----------- |:-------------:| -----:|
</th> | first | standard | None |
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p1339324120303"><a name="p1339324120303"></a><a name="p1339324120303"></a>Type</p> | second | outstanding | 5 |
</th> | third | inside | with |
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p13932041133012"><a name="p13932041133012"></a><a name="p13932041133012"></a>Note</p>
</th>
</tr>
</thead>
<tbody><tr id="row1839304110309"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p4393174143014"><a name="p4393174143014"></a><a name="p4393174143014"></a>first</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p6393141133013"><a name="p6393141133013"></a><a name="p6393141133013"></a>standard</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p17393184112307"><a name="p17393184112307"></a><a name="p17393184112307"></a>None</p>
</td>
</tr>
<tr id="row1039318412306"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p113941541103012"><a name="p113941541103012"></a><a name="p113941541103012"></a>second</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p83941841153016"><a name="p83941841153016"></a><a name="p83941841153016"></a>outstanding</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p1539404114305"><a name="p1539404114305"></a><a name="p1539404114305"></a>5</p>
</td>
</tr>
<tr id="row6547101813118"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p35483184313"><a name="p35483184313"></a><a name="p35483184313"></a>third</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p1554821817318"><a name="p1554821817318"></a><a name="p1554821817318"></a>inside</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p15548201819310"><a name="p15548201819310"></a><a name="p15548201819310"></a>with</p>
</td>
</tr>
</tbody>
</table>
**代码** **代码**
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
## 简介<a name="section104mcpsimp"></a> ## 简介<a name="section104mcpsimp"></a>
网络管理子系统,作为设备联网的必备组件,提供了对不同类型网络连接的统一管理,并提供了网络协议栈能力。应用可以通过调用API来获取数据网络的连接信息,查询和订阅数据网络的连接状态等,并可通过网络协议栈进行数据传输。 网络管理子系统,作为设备联网的必备组件,提供了对不同类型网络连接的统一管理、流量管理、策略管理、网络共享,并提供了网络协议栈能力。应用可以通过调用API来获取数据网络的连接信息,查询和订阅数据网络的连接状态,网络流量数据,网路策略以及网络共享等,并可通过网络协议栈进行数据传输。
下图所示为网络管理子系统架构图。各个部件主要作用如下: 下图所示为网络管理子系统架构图。各个部件主要作用如下:
...@@ -67,6 +67,26 @@ foundation/communication/ ...@@ -67,6 +67,26 @@ foundation/communication/
conn.unregister((err, data) => {}); conn.unregister((err, data) => {});
``` ```
### 网路共享<a name="section2458213210369"></a>
1. 从@ohos.net.sharing中导入sharing命名空间。
2. 设定共享类型
3. 开始共享
4. 止共享
```
// 引入包名
import sharing from '@ohos.net.sharing';
// 设定共享类型
this.sharingType = 0; // 0: WIFI 1: USB 2: BLUETOOTH
// 开始共享
sharing.startSharing(this.sharingType,(err)=>{
this.callBack(err);
})
// 停止共享
sharing.stopSharing(this.sharingType,(err)=>{
this.callBack(err);
})
```
### 发起网络请求<a name="section750135512369"></a> ### 发起网络请求<a name="section750135512369"></a>
...@@ -119,13 +139,10 @@ httpRequest.request( ...@@ -119,13 +139,10 @@ httpRequest.request(
); );
``` ```
## 相关仓<a name="section152mcpsimp"></a> ## 相关仓<a name="section152mcpsimp"></a>
**网络管理子系统** **网络管理子系统**
[communication_netmanager_base](https://gitee.com/openharmony/communication_netmanager_base/blob/master/README_zh.md) [communication_netmanager_base](https://gitee.com/openharmony/communication_netmanager_base/blob/master/README_zh.md)
[communication_netmanager_ext](https://gitee.com/openharmony/communication_netmanager_ext/blob/master/README_zh.md) [communication_netmanager_ext](https://gitee.com/openharmony/communication_netmanager_ext/blob/master/README_zh.md)
[communication_netstack](https://gitee.com/openharmony/communication_netstack/blob/master/README_zh.md) [communication_netstack](https://gitee.com/openharmony/communication_netstack/blob/master/README_zh.md)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册