From ff778fd8e4a775028aa88f53ae00a58c6ca7c6dd Mon Sep 17 00:00:00 2001 From: liyufan Date: Tue, 22 Aug 2023 10:37:09 +0800 Subject: [PATCH] add conn sync interface Signed-off-by: liyufan --- .../reference/apis/js-apis-net-connection.md | 199 ++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/zh-cn/application-dev/reference/apis/js-apis-net-connection.md b/zh-cn/application-dev/reference/apis/js-apis-net-connection.md index 2bd615b3b0..27fad275b4 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-net-connection.md +++ b/zh-cn/application-dev/reference/apis/js-apis-net-connection.md @@ -438,6 +438,34 @@ connection.getAppNet().then((data) => { }) ``` +## connection.getAppNetSync10+ + +getAppNetSync(): NetHandle + +使用同步方法获取App绑定的网络信息。 + +**系统能力**:SystemCapability.Communication.NetManager.Core + +**返回值:** + +| 类型 | 说明 | +| --------- | ---------------------------------- | +| NetHandle | 返回APP绑定的数据网络。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | ----------------------------- | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service.| +| 2100003 | System internal error. | + +**示例:** + +```js +let netHandle = connection.getAppNetSync(); +``` + ## connection.SetAppNet9+ setAppNet(netHandle: NetHandle, callback: AsyncCallback\): void @@ -587,6 +615,37 @@ connection.getAllNets().then(function (data) { }); ``` +## connection.getAllNetsSync10+ + +getAllNetsSync(): Array<NetHandle> + +使用同步方法获取App绑定的网络信息。 + +**需要权限**:ohos.permission.GET_NETWORK_INFO + +**系统能力**:SystemCapability.Communication.NetManager.Core + +**返回值:** + +| 类型 | 说明 | +| --------- | ---------------------------------- | +| Array<[NetHandle](#nethandle)> | 返回激活的数据网络列表。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | ----------------------------- | +| 201 | Permission denied. | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service.| +| 2100003 | System internal error. | + +**示例:** + +```js +let netHandle = connection.getAllNetsSync(); +``` + ## connection.getConnectionProperties8+ getConnectionProperties(netHandle: NetHandle, callback: AsyncCallback\): void @@ -667,6 +726,45 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` +## connection.getConnectionPropertiesSync10+ + +getConnectionPropertiesSync(netHandle: NetHandle): ConnectionProperties + +获取netHandle对应的网络的连接信息,使用同步方法返回。 + +**需要权限**:ohos.permission.GET_NETWORK_INFO + +**系统能力**:SystemCapability.Communication.NetManager.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ----------------------- | ---- | ---------------- | +| netHandle | [NetHandle](#nethandle) | 是 | 数据网络的句柄。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------------------------------------------- | --------------------------------- | +| [ConnectionProperties](#connectionproperties) | 返回网络的连接信息。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | ----------------------------- | +| 201 | Permission denied. | +| 401 | Parameter error. | +| 2100001 | Invalid parameter value. | +| 2100002 | Operation failed. Cannot connect to service.| +| 2100003 | System internal error. | + +**示例:** + +```js +let netHandle = connection.getDefaultNetsSync(); +let connectionproperties = connection.getConnectionPropertiesSync(netHandle); +``` + ## connection.getNetCapabilities8+ getNetCapabilities(netHandle: NetHandle, callback: AsyncCallback\): void @@ -747,6 +845,45 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` +## connection.getNetCapabilitiesSync10+ + +getNetCapabilities(netHandle: NetHandle): NetCapabilities + +获取netHandle对应的网络的能力信息,使用同步方式返回。 + +**需要权限**:ohos.permission.GET_NETWORK_INFO + +**系统能力**:SystemCapability.Communication.NetManager.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ----------------------- | ---- | ---------------- | +| netHandle | [NetHandle](#nethandle) | 是 | 数据网络的句柄。 | + +**返回值:** + +| 类型 | 说明 | +| --------------------------------------------- | --------------------------------- | +| [NetCapabilities](#netcapabilities) | 返回网络的能力信息。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | ----------------------------- | +| 201 | Permission denied. | +| 401 | Parameter error. | +| 2100001 | Invalid parameter value. | +| 2100002 | Operation failed. Cannot connect to service.| +| 2100003 | System internal error. | + +**示例:** + +```js +let netHandle = connection.getDefaultNetsSync(); +let getNetCapabilitiesSync = connection.getNetCapabilitiesSync(netHandle); +``` + ## connection.isDefaultNetMetered9+ isDefaultNetMetered(callback: AsyncCallback\): void @@ -814,6 +951,37 @@ connection.isDefaultNetMetered().then(function (data) { }) ``` +## connection.isDefaultNetMeteredSync10+ + +isDefaultNetMeteredSync(): boolean + +检查当前网络上的数据流量使用是否被计量,使用同步方式返回。 + +**需要权限**:ohos.permission.GET_NETWORK_INFO + +**系统能力**:SystemCapability.Communication.NetManager.Core + +**返回值:** + +| 类型 | 说明 | +| ----------------- | ----------------------------------------------- | +| boolean | 当前网络上的数据流量使用被计量true。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | ----------------------------- | +| 201 | Permission denied. | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service.| +| 2100003 | System internal error. | + +**示例:** + +```js +let isMetered = connection.isDefaultNetMeteredSync(); +``` + ## connection.hasDefaultNet8+ hasDefaultNet(callback: AsyncCallback\): void @@ -881,6 +1049,37 @@ connection.hasDefaultNet().then(function (data) { }) ``` +## connection.hasDefaultNetSync10+ + +hasDefaultNetSync(): boolean + +检查默认数据网络是否被激活,使用同步方式返回接口,如果被激活则返回true。 + +**需要权限**:ohos.permission.GET_NETWORK_INFO + +**系统能力**:SystemCapability.Communication.NetManager.Core + +**返回值:** + +| 类型 | 说明 | +| ----------------- | ----------------------------------------------- | +| boolean | 默认数据网络被激活返回true。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | ----------------------------- | +| 201 | Permission denied. | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service.| +| 2100003 | System internal error. | + +**示例:** + +```js +let isDefaultNet = connection.hasDefaultNetSync(); +``` + ## connection.enableAirplaneMode8+ enableAirplaneMode(callback: AsyncCallback\): void -- GitLab