Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
8c28c325
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
8c28c325
编写于
5月 26, 2023
作者:
O
openharmony_ci
提交者:
Gitee
5月 26, 2023
浏览文件
操作
浏览文件
下载
差异文件
!18747 修改md文档格式
Merge pull request !18747 from 刘姣姣/master
上级
8152eade
e79cfb61
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
675 addition
and
672 deletion
+675
-672
zh-cn/application-dev/reference/apis/js-apis-wifi.md
zh-cn/application-dev/reference/apis/js-apis-wifi.md
+675
-672
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-wifi.md
浏览文件 @
8c28c325
...
...
@@ -33,14 +33,14 @@ enableWifi(): boolean
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
enableWifi
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.disableWifi
...
...
@@ -63,14 +63,15 @@ disableWifi(): boolean
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
disableWifi
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.isWifiActive
...
...
@@ -91,15 +92,15 @@ isWifiActive(): boolean
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
isActivate
=
wifi
.
isActivate
();
console
.
info
(
"
isActivate:
"
+
isActivate
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.scan
...
...
@@ -120,14 +121,14 @@ scan(): boolean
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
scan
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.getScanInfos
...
...
@@ -164,10 +165,11 @@ getScanInfos(callback: AsyncCallback<Array<WifiScanInfo>>): void
| callback | AsyncCallback
<
Array
<
[WifiScanInfo](#wifiscaninfo)
>>
| 是 | 回调函数。当成功时,err为0,data为扫描到的热点;否则err为非0值,data为空。 |
**示例:**
```
js
import
wifi
from
'
@ohos.wifi
'
;
wifi
.
getScanInfos
((
err
,
result
)
=>
{
```
js
import
wifi
from
'
@ohos.wifi
'
;
wifi
.
getScanInfos
((
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
"
get scan info error
"
);
return
;
...
...
@@ -186,9 +188,9 @@ getScanInfos(callback: AsyncCallback<Array<WifiScanInfo>>): void
console
.
info
(
"
channelWidth:
"
+
result
[
i
].
channelWidth
);
console
.
info
(
"
timestamp:
"
+
result
[
i
].
timestamp
);
}
});
});
wifi
.
getScanInfos
().
then
(
result
=>
{
wifi
.
getScanInfos
().
then
(
result
=>
{
var
len
=
Object
.
keys
(
result
).
length
;
console
.
log
(
"
wifi received scan info:
"
+
len
);
for
(
var
i
=
0
;
i
<
len
;
++
i
)
{
...
...
@@ -202,8 +204,8 @@ getScanInfos(callback: AsyncCallback<Array<WifiScanInfo>>): void
console
.
info
(
"
channelWidth:
"
+
result
[
i
].
channelWidth
);
console
.
info
(
"
timestamp:
"
+
result
[
i
].
timestamp
);
}
});
```
});
```
## WifiScanInfo
...
...
@@ -285,10 +287,10 @@ addDeviceConfig(config: WifiDeviceConfig): Promise<number>
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
config
=
{
ssid
:
"
****
"
,
preSharedKey
:
"
****
"
,
...
...
@@ -297,9 +299,9 @@ addDeviceConfig(config: WifiDeviceConfig): Promise<number>
wifi
.
addDeviceConfig
(
config
).
then
(
result
=>
{
console
.
info
(
"
result:
"
+
JSON
.
stringify
(
result
));
});
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## WifiDeviceConfig
...
...
@@ -378,10 +380,10 @@ addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>)
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
config
=
{
ssid
:
"
****
"
,
preSharedKey
:
"
****
"
,
...
...
@@ -390,9 +392,9 @@ addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>)
wifi
.
addDeviceConfig
(
config
,(
error
,
result
)
=>
{
console
.
info
(
"
result:
"
+
JSON
.
stringify
(
result
));
});
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.addUntrustedConfig<sup>7+</sup>
...
...
@@ -415,11 +417,12 @@ addUntrustedConfig(config: WifiDeviceConfig): Promise<boolean>
|
**类型**
|
**说明**
|
| -------- | -------- |
| Promise
<
boolean
>
| Promise对象。表示操作结果,true: 成功, false: 失败。 |
**示例:**
```
``
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
config
=
{
ssid
:
"
****
"
,
preSharedKey
:
"
****
"
,
...
...
@@ -428,10 +431,10 @@ addUntrustedConfig(config: WifiDeviceConfig): Promise<boolean>
wifi
.
addUntrustedConfig
(
config
).
then
(
result
=>
{
console
.
info
(
"
result:
"
+
JSON
.
stringify
(
result
));
});
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
```
``
}
```
## wifi.addUntrustedConfig<sup>7+</sup>
...
...
@@ -451,10 +454,10 @@ addUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback<boolean&
| callback | AsyncCallback
<
boolean
>
| 是 | 回调函数。当操作成功时,err为0,data表示操作结果,true: 成功, false: 失败。如果error为非0,表示处理出现错误。 |
**示例:**
```
``
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
config
=
{
ssid
:
"
****
"
,
preSharedKey
:
"
****
"
,
...
...
@@ -463,10 +466,10 @@ addUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback<boolean&
wifi
.
addUntrustedConfig
(
config
,(
error
,
result
)
=>
{
console
.
info
(
"
result:
"
+
JSON
.
stringify
(
result
));
});
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
```
``
}
```
## wifi.removeUntrustedConfig<sup>7+</sup>
...
...
@@ -490,17 +493,19 @@ removeUntrustedConfig(config: WifiDeviceConfig): Promise<boolean>
| -------- | -------- |
| Promise
<
boolean
>
| Promise对象。表示操作结果,true: 成功, false: 失败。 |
```
import wifi from '@ohos.wifi';
**示例:**
try {
```
js
import
wifi
from
'
@ohos.wifi
'
;
try
{
let
networkId
=
0
;
wifi
.
removeUntrustedConfig
(
networkId
).
then
(
result
=>
{
console
.
info
(
"
result:
"
+
JSON
.
stringify
(
result
));
});
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
...
...
@@ -522,17 +527,17 @@ removeUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback<boole
| callback | AsyncCallback
<
boolean
>
| 是 | 回调函数。当操作成功时,err为0,data表示操作结果,true: 成功, false: 失败。如果error为非0,表示处理出现错误。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
networkId
=
0
;
wifi
.
removeUntrustedConfig
(
networkId
,(
error
,
result
)
=>
{
console
.
info
(
"
result:
"
+
JSON
.
stringify
(
result
));
});
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.connectToNetwork
...
...
@@ -561,15 +566,15 @@ connectToNetwork(networkId: number): boolean
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
networkId
=
0
;
wifi
.
connectToNetwork
(
networkId
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.connectToDevice
...
...
@@ -598,10 +603,10 @@ connectToDevice(config: WifiDeviceConfig): boolean
| boolean | true:操作成功,
false:操作失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
config
=
{
ssid
:
"
****
"
,
preSharedKey
:
"
****
"
,
...
...
@@ -609,9 +614,9 @@ connectToDevice(config: WifiDeviceConfig): boolean
}
wifi
.
connectToDevice
(
config
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.disconnect
...
...
@@ -634,14 +639,14 @@ disconnect(): boolean
| boolean | true:操作成功,
false:操作失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
disconnect
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.getSignalLevel
...
...
@@ -668,17 +673,17 @@ getSignalLevel(rssi: number, band: number): number
| number | 信号强度,取值范围为[0,
4]。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
rssi
=
0
;
let
band
=
0
;
let
level
=
wifi
.
getSignalLevel
(
rssi
,
band
);
console
.
info
(
"
lelvel:
"
+
JSON
.
stringify
(
lelvel
));
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
...
...
@@ -716,23 +721,23 @@ getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void
| callback | AsyncCallback
<
[WifiLinkedInfo](#wifilinkedinfo)
>
| 是 | 回调函数。当获取成功时,err为0,data表示WLAN连接信息。如果error为非0,表示处理出现错误。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
wifi.getLinkedInfo((err, data) => {
wifi
.
getLinkedInfo
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
"
get linked info error
"
);
return
;
}
console
.
info
(
"
get wifi linked info:
"
+
JSON
.
stringify
(
data
));
});
});
wifi.getLinkedInfo().then(data => {
wifi
.
getLinkedInfo
().
then
(
data
=>
{
console
.
info
(
"
get wifi linked info:
"
+
JSON
.
stringify
(
data
));
}).catch(error => {
}).
catch
(
error
=>
{
console
.
info
(
"
get linked info error
"
);
});
```
});
```
## WifiLinkedInfo
...
...
@@ -877,16 +882,16 @@ isFeatureSupported(featureId: number): boolean
| boolean | true:支持,
false:不支持。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
featureId
=
0
;
let
ret
=
wifi
.
isFeatureSupported
(
featureId
);
console
.
info
(
"
isFeatureSupported:
"
+
ret
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
...
...
@@ -909,15 +914,15 @@ getDeviceMacAddress(): string[]
| string[] | MAC地址。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
ret
=
wifi
.
getDeviceMacAddress
();
console
.
info
(
"
deviceMacAddress:
"
+
JSON
.
stringify
(
ret
));
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
...
...
@@ -938,15 +943,15 @@ getIpInfo(): IpInfo
|
[
IpInfo
](
#ipinfo7
)
| IP信息。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
info
=
wifi
.
getIpInfo
();
console
.
info
(
"
info:
"
+
JSON
.
stringify
(
info
));
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## IpInfo<sup>7+</sup>
...
...
@@ -983,15 +988,15 @@ getCountryCode(): string
| string | 国家码。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
code
=
wifi
.
getCountryCode
();
console
.
info
(
"
code:
"
+
code
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.reassociate<sup>7+</sup>
...
...
@@ -1013,14 +1018,14 @@ reassociate(): boolean
| boolean | true:操作成功,
false:操作失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
reassociate
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.reconnect<sup>7+</sup>
...
...
@@ -1042,14 +1047,14 @@ reconnect(): boolean
| boolean | true:操作成功,
false:操作失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
reconnect
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.getDeviceConfigs<sup>7+</sup>
...
...
@@ -1071,15 +1076,15 @@ getDeviceConfigs(): Array<[WifiDeviceConfig](#wifideviceconfig)>
|
Array
<
[WifiDeviceConfig](#wifideviceconfig)
>
| 网络配置信息的数组。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
configs
=
wifi
.
getDeviceConfigs
();
console
.
info
(
"
configs:
"
+
JSON
.
stringify
(
configs
));
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.updateNetwork<sup>7+</sup>
...
...
@@ -1107,10 +1112,10 @@ updateNetwork(config: WifiDeviceConfig): number
| number | 返回更新的网络配置ID,如果值为-1表示更新失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
config
=
{
ssid
:
"
****
"
,
preSharedKey
:
"
****
"
,
...
...
@@ -1118,9 +1123,9 @@ updateNetwork(config: WifiDeviceConfig): number
}
let
ret
=
wifi
.
updateNetwork
(
config
);
console
.
error
(
"
ret:
"
+
ret
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.disableNetwork<sup>7+</sup>
...
...
@@ -1148,15 +1153,15 @@ disableNetwork(netId: number): boolean
| boolean | true:操作成功,
false:操作失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
netId
=
0
;
wifi
.
disableNetwork
(
netId
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.removeAllNetwork<sup>7+</sup>
...
...
@@ -1178,14 +1183,14 @@ removeAllNetwork(): boolean
| boolean | true:操作成功,
false:操作失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
removeAllNetwork
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.removeDevice<sup>7+</sup>
...
...
@@ -1213,15 +1218,15 @@ removeDevice(id: number): boolean
| boolean | true:操作成功,
false:操作失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
id
=
0
;
wifi
.
removeDevice
(
id
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.enableHotspot<sup>7+</sup>
...
...
@@ -1243,14 +1248,14 @@ enableHotspot(): boolean
| boolean | true:操作成功,
false:操作失败。|
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
enableHotspot
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.disableHotspot<sup>7+</sup>
...
...
@@ -1272,14 +1277,14 @@ disableHotspot(): boolean
| boolean | true:操作成功,
false:操作失败。|
**示例:**
```
import wifi from '@ohos.wifiManager';
```
js
import
wifi
from
'
@ohos.wifiManager
'
;
try {
try
{
wifiManager
.
disableHotspot
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.isHotspotDualBandSupported<sup>7+</sup>
...
...
@@ -1301,15 +1306,15 @@ isHotspotDualBandSupported(): boolean
| boolean | true:支持,
false:不支持。|
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
ret
=
wifi
.
isHotspotDualBandSupported
();
console
.
info
(
"
result:
"
+
ret
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.isHotspotActive<sup>7+</sup>
...
...
@@ -1331,15 +1336,15 @@ isHotspotActive(): boolean
| boolean | true:已使能,
false:未使能。|
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
ret
=
wifi
.
isHotspotActive
();
console
.
info
(
"
result:
"
+
ret
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.setHotspotConfig<sup>7+</sup>
...
...
@@ -1367,10 +1372,10 @@ setHotspotConfig(config: HotspotConfig): boolean
| boolean | true:操作成功,
false:操作失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
config
=
{
ssid
:
"
****
"
,
securityType
:
3
,
...
...
@@ -1381,9 +1386,9 @@ setHotspotConfig(config: HotspotConfig): boolean
}
let
ret
=
wifi
.
setHotspotConfig
();
console
.
info
(
"
result:
"
+
ret
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## HotspotConfig<sup>7+</sup>
...
...
@@ -1422,15 +1427,15 @@ getHotspotConfig(): HotspotConfig
|
[
HotspotConfig
](
#hotspotconfig7
)
| 热点的配置信息。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
config
=
wifi
.
getHotspotConfig
();
console
.
info
(
"
result:
"
+
JSON
.
stringify
(
config
));
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.getStations<sup>7+</sup>
...
...
@@ -1452,15 +1457,15 @@ getStations(): Array<[StationInfo](#stationinfo7)>
|
Array
<
[StationInfo](#stationinfo7)
>
| 连接的设备数组。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
stations
=
wifi
.
getStations
();
console
.
info
(
"
result:
"
+
JSON
.
stringify
(
stations
));
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## StationInfo<sup>7+</sup>
...
...
@@ -1538,20 +1543,20 @@ getP2pLinkedInfo(callback: AsyncCallback<WifiP2pLinkedInfo>): void
| callback | AsyncCallback
<
[WifiP2pLinkedInfo](#wifip2plinkedinfo8)
>
| 是 | 回调函数。当操作成功时,err为0,data表示P2P连接信息。如果error为非0,表示处理出现错误。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
wifi.getP2pLinkedInfo((err, data) => {
wifi
.
getP2pLinkedInfo
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
"
get p2p linked info error
"
);
return
;
}
console
.
info
(
"
get wifi p2p linked info:
"
+
JSON
.
stringify
(
data
));
});
});
wifi.getP2pLinkedInfo().then(data => {
wifi
.
getP2pLinkedInfo
().
then
(
data
=>
{
console
.
info
(
"
get wifi p2p linked info:
"
+
JSON
.
stringify
(
data
));
});
});
```
## wifi.getCurrentGroup<sup>8+</sup>
...
...
@@ -1588,20 +1593,20 @@ getCurrentGroup(callback: AsyncCallback<WifiP2pGroupInfo>): void
| callback | AsyncCallback
<
[WifiP2pGroupInfo](#wifip2pgroupinfo8)
>
| 是 | 回调函数。当操作成功时,err为0,data表示当前组信息。如果error为非0,表示处理出现错误。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
wifi.getCurrentGroup((err, data) => {
wifi
.
getCurrentGroup
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
"
get current P2P group error
"
);
return
;
}
console
.
info
(
"
get current P2P group:
"
+
JSON
.
stringify
(
data
));
});
});
wifi.getCurrentGroup().then(data => {
wifi
.
getCurrentGroup
().
then
(
data
=>
{
console
.
info
(
"
get current P2P group:
"
+
JSON
.
stringify
(
data
));
});
});
```
## wifi.getP2pPeerDevices<sup>8+</sup>
...
...
@@ -1638,20 +1643,20 @@ getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void
| callback | AsyncCallback
<
[WifiP2pDevice[]](#wifip2pdevice8)
>
| 是 | 回调函数。当操作成功时,err为0,data表示对端设备列表信息。如果error为非0,表示处理出现错误。 |
**示例:**
```
import wifi from '@ohos.wifiManager';
```
js
import
wifi
from
'
@ohos.wifiManager
'
;
wifi.getP2pPeerDevices((err, data) => {
wifi
.
getP2pPeerDevices
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
"
get P2P peer devices error
"
);
return
;
}
console
.
info
(
"
get P2P peer devices:
"
+
JSON
.
stringify
(
data
));
});
});
wifi.getP2pPeerDevices().then(data => {
wifi
.
getP2pPeerDevices
().
then
(
data
=>
{
console
.
info
(
"
get P2P peer devices:
"
+
JSON
.
stringify
(
data
));
});
});
```
## WifiP2pDevice<sup>8+</sup>
...
...
@@ -1707,10 +1712,10 @@ createGroup(config: WifiP2PConfig): boolean
| boolean | true:创建群组操作执行成功,
false:创建群组操作执行失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
config
=
{
deviceAddress
:
"
****
"
,
netId
:
0
,
...
...
@@ -1720,9 +1725,9 @@ createGroup(config: WifiP2PConfig): boolean
}
wifi
.
createGroup
(
config
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## WifiP2PConfig<sup>8+</sup>
...
...
@@ -1770,14 +1775,14 @@ removeGroup(): boolean
| boolean | true:操作执行成功,
false:操作执行失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
removeGroup
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.p2pConnect<sup>8+</sup>
...
...
@@ -1805,10 +1810,10 @@ p2pConnect(config: WifiP2PConfig): boolean
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvP2pConnectionChangeFunc = result => {
var
recvP2pConnectionChangeFunc
=
result
=>
{
console
.
info
(
"
p2p connection change receive event:
"
+
JSON
.
stringify
(
result
));
wifi
.
getP2pLinkedInfo
((
err
,
data
)
=>
{
if
(
err
)
{
...
...
@@ -1817,15 +1822,15 @@ p2pConnect(config: WifiP2PConfig): boolean
}
console
.
info
(
"
get getP2pLinkedInfo:
"
+
JSON
.
stringify
(
data
));
});
}
wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc);
}
wifi
.
on
(
"
p2pConnectionChange
"
,
recvP2pConnectionChangeFunc
);
var recvP2pDeviceChangeFunc = result => {
var
recvP2pDeviceChangeFunc
=
result
=>
{
console
.
info
(
"
p2p device change receive event:
"
+
JSON
.
stringify
(
result
));
}
wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc);
}
wifi
.
on
(
"
p2pDeviceChange
"
,
recvP2pDeviceChangeFunc
);
var recvP2pPeerDeviceChangeFunc = result => {
var
recvP2pPeerDeviceChangeFunc
=
result
=>
{
console
.
info
(
"
p2p peer device change receive event:
"
+
JSON
.
stringify
(
result
));
wifi
.
getP2pPeerDevices
((
err
,
data
)
=>
{
if
(
err
)
{
...
...
@@ -1848,10 +1853,10 @@ p2pConnect(config: WifiP2PConfig): boolean
}
}
});
}
wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
}
wifi
.
on
(
"
p2pPeerDeviceChange
"
,
recvP2pPeerDeviceChangeFunc
);
var recvP2pPersistentGroupChangeFunc = () => {
var
recvP2pPersistentGroupChangeFunc
=
()
=>
{
console
.
info
(
"
p2p persistent group change receive event
"
);
wifi
.
getCurrentGroup
((
err
,
data
)
=>
{
...
...
@@ -1861,15 +1866,15 @@ p2pConnect(config: WifiP2PConfig): boolean
}
console
.
info
(
"
get current group:
"
+
JSON
.
stringify
(
data
));
});
}
wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
}
wifi
.
on
(
"
p2pPersistentGroupChange
"
,
recvP2pPersistentGroupChangeFunc
);
setTimeout(function() {wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125
*
1000);
setTimeout(function() {wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125
*
1000);
setTimeout(function() {wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125
*
1000);
setTimeout(function() {wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125
*
1000);
console.info("start discover devices -> " + wifi.startDiscoverDevices());
```
setTimeout
(
function
()
{
wifi
.
off
(
"
p2pConnectionChange
"
,
recvP2pConnectionChangeFunc
);},
125
*
1000
);
setTimeout
(
function
()
{
wifi
.
off
(
"
p2pDeviceChange
"
,
recvP2pDeviceChangeFunc
);},
125
*
1000
);
setTimeout
(
function
()
{
wifi
.
off
(
"
p2pPeerDeviceChange
"
,
recvP2pPeerDeviceChangeFunc
);},
125
*
1000
);
setTimeout
(
function
()
{
wifi
.
off
(
"
p2pPersistentGroupChange
"
,
recvP2pPersistentGroupChangeFunc
);},
125
*
1000
);
console
.
info
(
"
start discover devices ->
"
+
wifi
.
startDiscoverDevices
());
```
## wifi.p2pCancelConnect<sup>8+</sup>
...
...
@@ -1888,14 +1893,14 @@ p2pCancelConnect(): boolean
| boolean | true:操作执行成功,
false:操作执行失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
p2pCancelConnect
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.startDiscoverDevices<sup>8+</sup>
...
...
@@ -1915,14 +1920,14 @@ startDiscoverDevices(): boolean
| boolean | true:操作执行成功,
false:操作执行失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
startDiscoverDevices
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.stopDiscoverDevices<sup>8+</sup>
...
...
@@ -1942,14 +1947,14 @@ stopDiscoverDevices(): boolean
| boolean | true:操作执行成功,操作执行失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
wifi
.
stopDiscoverDevices
();
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.deletePersistentGroup<sup>8+</sup>
...
...
@@ -1978,15 +1983,15 @@ deletePersistentGroup(netId: number): boolean
| boolean | true:操作执行成功,操作执行失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
netId
=
0
;
wifi
.
deletePersistentGroup
(
netId
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## WifiP2pGroupInfo<sup>8+</sup>
...
...
@@ -2033,15 +2038,15 @@ setDeviceName(devName: string): boolean
| boolean | true:操作成功,
false:操作失败。 |
**示例:**
```
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
try {
try
{
let
name
=
"
****
"
;
wifi
.
setDeviceName
(
netId
);
}catch(error){
}
catch
(
error
){
console
.
error
(
"
failed:
"
+
JSON
.
stringify
(
error
));
}
}
```
## wifi.on('wifiStateChange')<sup>7+</sup>
...
...
@@ -2089,19 +2094,19 @@ off(type: "wifiStateChange", callback?: Callback<number>): void
| callback | Callback
<
number
>
| 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvPowerNotifyFunc = result => {
var
recvPowerNotifyFunc
=
result
=>
{
console
.
info
(
"
Receive power state change event:
"
+
result
);
}
}
// Register event
wifi.on("wifiStateChange", recvPowerNotifyFunc);
// Register event
wifi
.
on
(
"
wifiStateChange
"
,
recvPowerNotifyFunc
);
// Unregister event
wifi.off("wifiStateChange", recvPowerNotifyFunc);
```
// Unregister event
wifi
.
off
(
"
wifiStateChange
"
,
recvPowerNotifyFunc
);
```
## wifi.on('wifiConnectionChange')<sup>7+</sup>
...
...
@@ -2147,19 +2152,19 @@ off(type: "wifiConnectionChange", callback?: Callback<number>): void
| callback | Callback
<
number
>
| 否 | 连接状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvWifiConnectionChangeFunc = result => {
var
recvWifiConnectionChangeFunc
=
result
=>
{
console
.
info
(
"
Receive wifi connection change event:
"
+
result
);
}
}
// Register event
wifi.on("wifiConnectionChange", recvWifiConnectionChangeFunc);
// Register event
wifi
.
on
(
"
wifiConnectionChange
"
,
recvWifiConnectionChangeFunc
);
// Unregister event
wifi.off("wifiConnectionChange", recvWifiConnectionChangeFunc);
```
// Unregister event
wifi
.
off
(
"
wifiConnectionChange
"
,
recvWifiConnectionChangeFunc
);
```
## wifi.on('wifiScanStateChange')<sup>7+</sup>
...
...
@@ -2204,19 +2209,19 @@ off(type: "wifiScanStateChange", callback?: Callback<number>): void
| callback | Callback
<
number
>
| 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvWifiScanStateChangeFunc = result => {
var
recvWifiScanStateChangeFunc
=
result
=>
{
console
.
info
(
"
Receive Wifi scan state change event:
"
+
result
);
}
}
// Register event
wifi.on("wifiScanStateChange", recvWifiScanStateChangeFunc);
// Register event
wifi
.
on
(
"
wifiScanStateChange
"
,
recvWifiScanStateChangeFunc
);
// Unregister event
wifi.off("wifiScanStateChange", recvWifiScanStateChangeFunc);
```
// Unregister event
wifi
.
off
(
"
wifiScanStateChange
"
,
recvWifiScanStateChangeFunc
);
```
## wifi.on('wifiRssiChange')<sup>7+</sup>
...
...
@@ -2254,20 +2259,19 @@ off(type: "wifiRssiChange", callback?: Callback<number>): void
| callback | Callback
<
number
>
| 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvWifiRssiChangeFunc = result => {
var
recvWifiRssiChangeFunc
=
result
=>
{
console
.
info
(
"
Receive wifi rssi change event:
"
+
result
);
}
// Register event
wifi.on("wifiRssiChange", recvWifiRssiChangeFunc);
}
// Unregister event
wifi.off("wifiRssiChange", recvWifiRssiChangeFunc);
```
// Register event
wifi
.
on
(
"
wifiRssiChange
"
,
recvWifiRssiChangeFunc
);
// Unregister event
wifi
.
off
(
"
wifiRssiChange
"
,
recvWifiRssiChangeFunc
);
```
## wifi.on('hotspotStateChange')<sup>7+</sup>
on(type: "hotspotStateChange", callback: Callback
<
number
>
): void
...
...
@@ -2295,20 +2299,19 @@ on(type: "hotspotStateChange", callback: Callback<number>): void
| 3 | 去激活中。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvHotspotStateChangeFunc = result => {
var
recvHotspotStateChangeFunc
=
result
=>
{
console
.
info
(
"
Receive hotspot state change event:
"
+
result
);
}
// Register event
wifi.on("hotspotStateChange", recvHotspotStateChangeFunc);
}
// Unregister event
wifi.off("hotspotStateChange", recvHotspotStateChangeFunc);
```
// Register event
wifi
.
on
(
"
hotspotStateChange
"
,
recvHotspotStateChangeFunc
);
// Unregister event
wifi
.
off
(
"
hotspotStateChange
"
,
recvHotspotStateChangeFunc
);
```
## wifi.off('hotspotStateChange')<sup>7+</sup>
...
...
@@ -2373,19 +2376,19 @@ off(type: "p2pStateChange", callback?: Callback<number>): void
| callback | Callback
<
number
>
| 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvP2pStateChangeFunc = result => {
var
recvP2pStateChangeFunc
=
result
=>
{
console
.
info
(
"
Receive p2p state change event:
"
+
result
);
}
}
// Register event
wifi.on("p2pStateChange", recvP2pStateChangeFunc);
// Register event
wifi
.
on
(
"
p2pStateChange
"
,
recvP2pStateChangeFunc
);
// Unregister event
wifi.off("p2pStateChange", recvP2pStateChangeFunc);
```
// Unregister event
wifi
.
off
(
"
p2pStateChange
"
,
recvP2pStateChangeFunc
);
```
## wifi.on('p2pConnectionChange')
<sup>
8+
</sup>
...
...
@@ -2423,19 +2426,19 @@ off(type: "p2pConnectionChange", callback?: Callback<WifiP2pLinkedInfo>):
| callback | Callback
<
[WifiP2pLinkedInfo](#wifip2plinkedinfo8)
>
| 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvP2pConnectionChangeFunc = result => {
var
recvP2pConnectionChangeFunc
=
result
=>
{
console
.
info
(
"
Receive p2p connection change event:
"
+
result
);
}
}
// Register event
wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc);
// Register event
wifi
.
on
(
"
p2pConnectionChange
"
,
recvP2pConnectionChangeFunc
);
// Unregister event
wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc);
```
// Unregister event
wifi
.
off
(
"
p2pConnectionChange
"
,
recvP2pConnectionChangeFunc
);
```
## wifi.on('p2pDeviceChange')<sup>8+</sup>
...
...
@@ -2473,19 +2476,19 @@ off(type: "p2pDeviceChange", callback?: Callback<WifiP2pDevice>): void
| callback | Callback
<
[WifiP2pDevice](#wifip2pdevice8)
>
| 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvP2pDeviceChangeFunc = result => {
var
recvP2pDeviceChangeFunc
=
result
=>
{
console
.
info
(
"
Receive recv p2p device change event:
"
+
result
);
}
}
// Register event
wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc);
// Register event
wifi
.
on
(
"
p2pDeviceChange
"
,
recvP2pDeviceChangeFunc
);
// Unregister event
wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);
```
// Unregister event
wifi
.
off
(
"
p2pDeviceChange
"
,
recvP2pDeviceChangeFunc
);
```
## wifi.on('p2pPeerDeviceChange')<sup>8+</sup>
...
...
@@ -2523,19 +2526,19 @@ off(type: "p2pPeerDeviceChange", callback?: Callback<WifiP2pDevice[]>): vo
| callback | Callback
<
[WifiP2pDevice[]](#wifip2pdevice8)
>
| 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvP2pPeerDeviceChangeFunc = result => {
var
recvP2pPeerDeviceChangeFunc
=
result
=>
{
console
.
info
(
"
Receive recv p2p peer device change event:
"
+
result
);
}
}
// Register event
wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
// Register event
wifi
.
on
(
"
p2pPeerDeviceChange
"
,
recvP2pPeerDeviceChangeFunc
);
// Unregister event
wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
```
// Unregister event
wifi
.
off
(
"
p2pPeerDeviceChange
"
,
recvP2pPeerDeviceChangeFunc
);
```
## wifi.on('p2pPersistentGroupChange')<sup>8+</sup>
...
...
@@ -2573,20 +2576,20 @@ off(type: "p2pPersistentGroupChange", callback?: Callback<void>): void
| callback | Callback
<
void
>
| 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvP2pPersistentGroupChangeFunc = result => {
var
recvP2pPersistentGroupChangeFunc
=
result
=>
{
console
.
info
(
"
Receive recv p2p persistent group change event:
"
+
result
);
}
}
// Register event
wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
// Register event
wifi
.
on
(
"
p2pPersistentGroupChange
"
,
recvP2pPersistentGroupChangeFunc
);
// Unregister event
wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
// Unregister event
wifi
.
off
(
"
p2pPersistentGroupChange
"
,
recvP2pPersistentGroupChangeFunc
);
```
```
## wifi.on('p2pDiscoveryChange')<sup>8+</sup>
...
...
@@ -2631,16 +2634,16 @@ off(type: "p2pDiscoveryChange", callback?: Callback<number>): void
| callback | Callback
<
number
>
| 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
**示例:**
```
js
import wifi from '@ohos.wifi';
```
js
import
wifi
from
'
@ohos.wifi
'
;
var recvP2pDiscoveryChangeFunc = result => {
var
recvP2pDiscoveryChangeFunc
=
result
=>
{
console
.
info
(
"
Receive recv p2p discovery change event:
"
+
result
);
}
}
// Register event
wifi.on("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc);
// Register event
wifi
.
on
(
"
p2pDiscoveryChange
"
,
recvP2pDiscoveryChangeFunc
);
// Unregister event
wifi.off("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc);
```
\ No newline at end of file
// Unregister event
wifi
.
off
(
"
p2pDiscoveryChange
"
,
recvP2pDiscoveryChangeFunc
);
```
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录