diff --git a/zh-cn/application-dev/reference/apis/js-apis-wifi.md b/zh-cn/application-dev/reference/apis/js-apis-wifi.md index 0179b5999b9038ad70693af0971ae22f06a666c2..6fceb9cc33fedadf690bf98388308890e4ce04bf 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-wifi.md +++ b/zh-cn/application-dev/reference/apis/js-apis-wifi.md @@ -1706,6 +1706,24 @@ createGroup(config: WifiP2PConfig): boolean | -------- | -------- | | boolean | true:创建群组操作执行成功, false:创建群组操作执行失败。 | +**示例:** +``` + import wifi from '@ohos.wifi'; + + try { + let config = { + deviceAddress: "****", + netId: 0, + passphrase: "*****", + groupName: "****", + goBand: 0 + } + wifi.createGroup(config); + + }catch(error){ + console.error("failed:" + JSON.stringify(error)); + } +``` ## WifiP2PConfig8+ @@ -1751,6 +1769,16 @@ removeGroup(): boolean | -------- | -------- | | boolean | true:操作执行成功, false:操作执行失败。 | +**示例:** +``` + import wifi from '@ohos.wifi'; + + try { + wifi.removeGroup(); + }catch(error){ + console.error("failed:" + JSON.stringify(error)); + } +``` ## wifi.p2pConnect8+ @@ -1859,6 +1887,16 @@ p2pCancelConnect(): boolean | -------- | -------- | | boolean | true:操作执行成功, false:操作执行失败。 | +**示例:** +``` + import wifi from '@ohos.wifi'; + + try { + wifi.p2pCancelConnect(); + }catch(error){ + console.error("failed:" + JSON.stringify(error)); + } +``` ## wifi.startDiscoverDevices8+ @@ -1876,6 +1914,16 @@ startDiscoverDevices(): boolean | -------- | -------- | | boolean | true:操作执行成功, false:操作执行失败。 | +**示例:** +``` + import wifi from '@ohos.wifi'; + + try { + wifi.startDiscoverDevices(); + }catch(error){ + console.error("failed:" + JSON.stringify(error)); + } +``` ## wifi.stopDiscoverDevices8+ @@ -1893,6 +1941,16 @@ stopDiscoverDevices(): boolean | -------- | -------- | | boolean | true:操作执行成功,操作执行失败。 | +**示例:** +``` + import wifi from '@ohos.wifi'; + + try { + wifi.stopDiscoverDevices(); + }catch(error){ + console.error("failed:" + JSON.stringify(error)); + } +``` ## wifi.deletePersistentGroup8+ @@ -1919,6 +1977,17 @@ deletePersistentGroup(netId: number): boolean | -------- | -------- | | boolean | true:操作执行成功,操作执行失败。 | +**示例:** +``` + import wifi from '@ohos.wifi'; + + try { + let netId = 0; + wifi.deletePersistentGroup(netId); + }catch(error){ + console.error("failed:" + JSON.stringify(error)); + } +``` ## WifiP2pGroupInfo8+ @@ -1963,6 +2032,17 @@ setDeviceName(devName: string): boolean | -------- | -------- | | boolean | true:操作成功, false:操作失败。 | +**示例:** +``` + import wifi from '@ohos.wifi'; + + try { + let name = "****"; + wifi.setDeviceName(netId); + }catch(error){ + console.error("failed:" + JSON.stringify(error)); + } +``` ## wifi.on('wifiStateChange')7+ @@ -2006,7 +2086,7 @@ off(type: "wifiStateChange", callback?: Callback<number>): void | **参数名** | **类型** | **必填** | **说明** | | -------- | -------- | -------- | -------- | | type | string | 是 | 固定填"wifiStateChange"字符串。 | - | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | + | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 | **示例:** ```js @@ -2064,9 +2144,23 @@ off(type: "wifiConnectionChange", callback?: Callback<number>): void | **参数名** | **类型** | **必填** | **说明** | | -------- | -------- | -------- | -------- | | type | string | 是 | 固定填"wifiConnectionChange"字符串。 | - | callback | Callback<number> | 否 | 连接状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | - + | callback | Callback<number> | 否 | 连接状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 | +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvWifiConnectionChangeFunc = result => { + console.info("Receive wifi connection change event: " + result); + } + + // Register event + wifi.on("wifiConnectionChange", recvWifiConnectionChangeFunc); + + // Unregister event + wifi.off("wifiConnectionChange", recvWifiConnectionChangeFunc); + ``` + ## wifi.on('wifiScanStateChange')7+ on(type: "wifiScanStateChange", callback: Callback<number>): void @@ -2107,9 +2201,23 @@ off(type: "wifiScanStateChange", callback?: Callback<number>): void | **参数名** | **类型** | **必填** | **说明** | | -------- | -------- | -------- | -------- | | type | string | 是 | 固定填"wifiScanStateChange"字符串。 | -| callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | - +| callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 | +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvWifiScanStateChangeFunc = result => { + console.info("Receive Wifi scan state change event: " + result); + } + + // Register event + wifi.on("wifiScanStateChange", recvWifiScanStateChangeFunc); + + // Unregister event + wifi.off("wifiScanStateChange", recvWifiScanStateChangeFunc); + ``` + ## wifi.on('wifiRssiChange')7+ on(type: "wifiRssiChange", callback: Callback<number>): void @@ -2143,9 +2251,23 @@ off(type: "wifiRssiChange", callback?: Callback<number>): void | **参数名** | **类型** | **必填** | **说明** | | -------- | -------- | -------- | -------- | | type | string | 是 | 固定填"wifiRssiChange"字符串。 | - | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | - + | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 | +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvWifiRssiChangeFunc = result => { + console.info("Receive wifi rssi change event: " + result); + } + + // Register event + wifi.on("wifiRssiChange", recvWifiRssiChangeFunc); + + // Unregister event + wifi.off("wifiRssiChange", recvWifiRssiChangeFunc); + ``` + ## wifi.on('hotspotStateChange')7+ on(type: "hotspotStateChange", callback: Callback<number>): void @@ -2172,6 +2294,21 @@ on(type: "hotspotStateChange", callback: Callback<number>): void | 2 | 激活中。 | | 3 | 去激活中。 | +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvHotspotStateChangeFunc = result => { + console.info("Receive hotspot state change event: " + result); + } + + // Register event + wifi.on("hotspotStateChange", recvHotspotStateChangeFunc); + + // Unregister event + wifi.off("hotspotStateChange", recvHotspotStateChangeFunc); + ``` + ## wifi.off('hotspotStateChange')7+ @@ -2188,7 +2325,7 @@ off(type: "hotspotStateChange", callback?: Callback<number>): void | **参数名** | **类型** | **必填** | **说明** | | -------- | -------- | -------- | -------- | | type | string | 是 | 固定填"hotspotStateChange"字符串。 | - | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | + | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 | ## wifi.on('p2pStateChange')8+ @@ -2233,8 +2370,22 @@ off(type: "p2pStateChange", callback?: Callback<number>): void | **参数名** | **类型** | **必填** | **说明** | | -------- | -------- | -------- | -------- | | type | string | 是 | 固定填"p2pStateChange"字符串。 | - | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | - + | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 | + +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvP2pStateChangeFunc = result => { + console.info("Receive p2p state change event: " + result); + } + + // Register event + wifi.on("p2pStateChange", recvP2pStateChangeFunc); + + // Unregister event + wifi.off("p2pStateChange", recvP2pStateChangeFunc); + ``` ## wifi.on('p2pConnectionChange')8+ @@ -2269,9 +2420,23 @@ off(type: "p2pConnectionChange", callback?: Callback<WifiP2pLinkedInfo>): | **参数名** | **类型** | **必填** | **说明** | | -------- | -------- | -------- | -------- | | type | string | 是 | 固定填"p2pConnectionChange"字符串。 | - | callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo8)> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | - + | callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo8)> | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 | +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvP2pConnectionChangeFunc = result => { + console.info("Receive p2p connection change event: " + result); + } + + // Register event + wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc); + + // Unregister event + wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc); + ``` + ## wifi.on('p2pDeviceChange')8+ on(type: "p2pDeviceChange", callback: Callback<WifiP2pDevice>): void @@ -2305,9 +2470,23 @@ off(type: "p2pDeviceChange", callback?: Callback<WifiP2pDevice>): void | **参数名** | **类型** | **必填** | **说明** | | -------- | -------- | -------- | -------- | | type | string | 是 | 固定填"p2pDeviceChange"字符串。 | - | callback | Callback<[WifiP2pDevice](#wifip2pdevice8)> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | - + | callback | Callback<[WifiP2pDevice](#wifip2pdevice8)> | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 | +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvP2pDeviceChangeFunc = result => { + console.info("Receive recv p2p device change event: " + result); + } + + // Register event + wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc); + + // Unregister event + wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc); + ``` + ## wifi.on('p2pPeerDeviceChange')8+ on(type: "p2pPeerDeviceChange", callback: Callback<WifiP2pDevice[]>): void @@ -2341,8 +2520,22 @@ off(type: "p2pPeerDeviceChange", callback?: Callback<WifiP2pDevice[]>): vo | **参数名** | **类型** | **必填** | **说明** | | -------- | -------- | -------- | -------- | | type | string | 是 | 固定填"p2pPeerDeviceChange"字符串。 | - | callback | Callback<[WifiP2pDevice[]](#wifip2pdevice8)> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | + | callback | Callback<[WifiP2pDevice[]](#wifip2pdevice8)> | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 | +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvP2pPeerDeviceChangeFunc = result => { + console.info("Receive recv p2p peer device change event: " + result); + } + + // Register event + wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); + + // Unregister event + wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); + ``` ## wifi.on('p2pPersistentGroupChange')8+ @@ -2377,8 +2570,23 @@ off(type: "p2pPersistentGroupChange", callback?: Callback<void>): void | **参数名** | **类型** | **必填** | **说明** | | -------- | -------- | -------- | -------- | | type | string | 是 | 固定填"p2pPersistentGroupChange"字符串。 | - | callback | Callback<void> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | - + | callback | Callback<void> | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 | + +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvP2pPersistentGroupChangeFunc = result => { + console.info("Receive recv p2p persistent group change event: " + result); + } + + // Register event + wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); + + // Unregister event + wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); + + ``` ## wifi.on('p2pDiscoveryChange')8+ @@ -2420,5 +2628,19 @@ off(type: "p2pDiscoveryChange", callback?: Callback<number>): void | **参数名** | **类型** | **必填** | **说明** | | -------- | -------- | -------- | -------- | | type | string | 是 | 固定填"p2pDiscoveryChange"字符串。 | - | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | + | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 | +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvP2pDiscoveryChangeFunc = result => { + console.info("Receive recv p2p discovery change event: " + result); + } + + // Register event + wifi.on("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc); + + // Unregister event + wifi.off("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc); + ``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-wifiManager.md b/zh-cn/application-dev/reference/apis/js-apis-wifiManager.md index 86122d531b405815dbf54614e69800c70c21d1f0..9b57c27a403c359da5943a43effabe0341042f1c 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-wifiManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-wifiManager.md @@ -2901,6 +2901,21 @@ off(type: "wifiConnectionChange", callback?: Callback<number>): void | -------- | -------- | | 2501000 | Operation failed.| +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvWifiConnectionChangeFunc = result => { + console.info("Receive wifi connection change event: " + result); + } + + // Register event + wifi.on("wifiConnectionChange", recvWifiConnectionChangeFunc); + + // Unregister event + wifi.off("wifiConnectionChange", recvWifiConnectionChangeFunc); + ``` + ## wifi.on('wifiScanStateChange')9+ on(type: "wifiScanStateChange", callback: Callback<number>): void @@ -2958,6 +2973,21 @@ off(type: "wifiScanStateChange", callback?: Callback<number>): void | -------- | -------- | | 2501000 | Operation failed.| +**示例:** + ```js + import wifi from '@ohos.wifi'; + + var recvWifiScanStateChangeFunc = result => { + console.info("Receive Wifi scan state change event: " + result); + } + + // Register event + wifi.on("wifiScanStateChange", recvWifiScanStateChangeFunc); + + // Unregister event + wifi.off("wifiScanStateChange", recvWifiScanStateChangeFunc); + ``` + ## wifi.on('wifiRssiChange')9+ on(type: "wifiRssiChange", callback: Callback<number>): void @@ -3008,6 +3038,21 @@ off(type: "wifiRssiChange", callback?: Callback<number>): void | -------- | -------- | | 2501000 | Operation failed.| +**示例:** + ```js + import wifi from '@ohos.wifiManager'; + + var recvWifiRssiChangeFunc = result => { + console.info("Receive wifi rssi change event: " + result); + } + + // Register event + wifiManager.on("wifiRssiChange", recvWifiRssiChangeFunc); + + // Unregister event + wifiManager.off("wifiRssiChange", recvWifiRssiChangeFunc); + ``` + ## wifi.on('hotspotStateChange')9+ on(type: "hotspotStateChange", callback: Callback<number>): void @@ -3067,6 +3112,21 @@ off(type: "hotspotStateChange", callback?: Callback<number>): void | -------- | -------- | | 2601000 | Operation failed.| +**示例:** + ```js + import wifi from '@ohos.wifiManager'; + + var recvHotspotStateChangeFunc = result => { + console.info("Receive hotspot state change event: " + result); + } + + // Register event + wifiManager.on("hotspotStateChange", recvHotspotStateChangeFunc); + + // Unregister event + wifiManager.off("hotspotStateChange", recvHotspotStateChangeFunc); + ``` + ## wifi.on('p2pStateChange')9+ on(type: "p2pStateChange", callback: Callback<number>): void @@ -3127,6 +3187,21 @@ off(type: "p2pStateChange", callback?: Callback<number>): void | -------- | -------- | | 2801000 | Operation failed.| +**示例:** + ```js + import wifi from '@ohos.wifiManager'; + + var recvP2pStateChangeFunc = result => { + console.info("Receive p2p state change event: " + result); + } + + // Register event + wifiManager.on("p2pStateChange", recvP2pStateChangeFunc); + + // Unregister event + wifiManager.off("p2pStateChange", recvP2pStateChangeFunc); + ``` + ## wifi.on('p2pConnectionChange')9+ on(type: "p2pConnectionChange", callback: Callback<WifiP2pLinkedInfo>): void @@ -3177,6 +3252,21 @@ off(type: "p2pConnectionChange", callback?: Callback<WifiP2pLinkedInfo>): | -------- | -------- | | 2801000 | Operation failed.| +**示例:** + ```js + import wifi from '@ohos.wifiManager'; + + var recvP2pConnectionChangeFunc = result => { + console.info("Receive p2p connection change event: " + result); + } + + // Register event + wifiManager.on("p2pConnectionChange", recvP2pConnectionChangeFunc); + + // Unregister event + wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc); + ``` + ## wifi.on('p2pDeviceChange')9+ on(type: "p2pDeviceChange", callback: Callback<WifiP2pDevice>): void @@ -3227,6 +3317,21 @@ off(type: "p2pDeviceChange", callback?: Callback<WifiP2pDevice>): void | -------- | -------- | | 2801000 | Operation failed.| +**示例:** + ```js + import wifi from '@ohos.wifiManager'; + + var recvP2pDeviceChangeFunc = result => { + console.info("Receive recv p2p device change event: " + result); + } + + // Register event + wifiManager.on("p2pDeviceChange", recvP2pDeviceChangeFunc); + + // Unregister event + wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc); + ``` + ## wifi.on('p2pPeerDeviceChange')9+ on(type: "p2pPeerDeviceChange", callback: Callback<WifiP2pDevice[]>): void @@ -3277,6 +3382,21 @@ off(type: "p2pPeerDeviceChange", callback?: Callback<WifiP2pDevice[]>): vo | -------- | -------- | | 2801000 | Operation failed.| +**示例:** + ```js + import wifi from '@ohos.wifiManager'; + + var recvP2pPeerDeviceChangeFunc = result => { + console.info("Receive recv p2p peer device change event: " + result); + } + + // Register event + wifiManager.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); + + // Unregister event + wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); + ``` + ## wifi.on('p2pPersistentGroupChange')9+ on(type: "p2pPersistentGroupChange", callback: Callback<void>): void @@ -3327,6 +3447,21 @@ off(type: "p2pPersistentGroupChange", callback?: Callback<void>): void | -------- | -------- | | 2801000 | Operation failed.| +**示例:** + ```js + import wifi from '@ohos.wifiManager'; + + var recvP2pPersistentGroupChangeFunc = result => { + console.info("Receive recv p2p persistent group change event: " + result); + } + + // Register event + wifiManager.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); + + // Unregister event + wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); + ``` + ## wifi.on('p2pDiscoveryChange')9+ on(type: "p2pDiscoveryChange", callback: Callback<number>): void @@ -3383,3 +3518,18 @@ off(type: "p2pDiscoveryChange", callback?: Callback<number>): void | **错误码ID** | **错误信息** | | -------- | -------- | | 2801000 | Operation failed.| + +**示例:** + ```js + import wifi from '@ohos.wifiManager'; + + var recvP2pDiscoveryChangeFunc = result => { + console.info("Receive recv p2p discovery change event: " + result); + } + + // Register event + wifiManager.on("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc); + + // Unregister event + wifiManager.off("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc); + ``` \ No newline at end of file