Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
f66129ce
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看板
未验证
提交
f66129ce
编写于
12月 01, 2022
作者:
O
openharmony_ci
提交者:
Gitee
12月 01, 2022
浏览文件
操作
浏览文件
下载
差异文件
!11898 【仅md一致性及格式问题】WiFi接口文档一致性检查
Merge pull request !11898 from xiaosi/master
上级
f784a2ec
c673267e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
2517 addition
and
375 deletion
+2517
-375
zh-cn/application-dev/reference/apis/js-apis-wifi.md
zh-cn/application-dev/reference/apis/js-apis-wifi.md
+95
-372
zh-cn/application-dev/reference/apis/js-apis-wifiManager.md
zh-cn/application-dev/reference/apis/js-apis-wifiManager.md
+2269
-0
zh-cn/application-dev/reference/apis/js-apis-wifiManagerExt.md
.../application-dev/reference/apis/js-apis-wifiManagerExt.md
+150
-0
zh-cn/application-dev/reference/apis/js-apis-wifiext.md
zh-cn/application-dev/reference/apis/js-apis-wifiext.md
+3
-3
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-wifi.md
浏览文件 @
f66129ce
...
@@ -166,20 +166,17 @@ WLAN热点信息。
...
@@ -166,20 +166,17 @@ WLAN热点信息。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**
读写属性
**
|
**说明**
|
|
**参数名**
|
**类型**
|
**
可读**
|
**可写
**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| ssid | string | 只读 | 热点的SSID,编码格式为UTF-8。 |
| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
| bssid | string | 只读 | 热点的BSSID。 |
| bssid | string | 是 | 否 | 热点的BSSID。 |
| capabilities | string | 只读 | 热点能力。 |
| capabilities | string | 是 | 否 | 热点能力。 |
| securityType |
[
WifiSecurityType
](
#wifisecuritytype
)
| 只读 | WLAN加密类型。 |
| securityType |
[
WifiSecurityType
](
#wifisecuritytype
)
| 是 | 否 | WLAN加密类型。 |
| rssi | number | 只读 | 热点的信号强度(dBm)。 |
| rssi | number | 是 | 否 | 热点的信号强度(dBm)。 |
| band | number | 只读 | WLAN接入点的频段。 |
| band | number | 是 | 否 | WLAN接入点的频段。 |
| frequency | number | 只读 | WLAN接入点的频率。 |
| frequency | number | 是 | 否 | WLAN接入点的频率。 |
| channelWidth | number | 只读 | WLAN接入点的带宽。 |
| channelWidth | number | 是 | 否 | WLAN接入点的带宽。 |
| centerFrequency0
<sup>
9+
</sup>
| number | 只读 | 热点的中心频率。 |
| timestamp | number | 是 | 否 | 时间戳。 |
| centerFrequency1
<sup>
9+
</sup>
| number | 只读 | 热点的中心频率。如果热点使用两个不重叠的WLAN信道,则返回两个中心频率,分别用centerFrequency0和centerFrequency1表示。 |
| infoElems
<sup>
9+
</sup>
| Array
<
[WifiInfoElem](#wifiinfoelem9)
>
| 只读 | 信息元素。 |
| timestamp | number | 只读 | 时间戳。 |
## WifiSecurityType
## WifiSecurityType
...
@@ -189,50 +186,13 @@ WLAN热点信息。
...
@@ -189,50 +186,13 @@ WLAN热点信息。
**系统能力:**
SystemCapability.Communication.WiFi.Core
**系统能力:**
SystemCapability.Communication.WiFi.Core
|
**名称**
|
**
默认
值**
|
**说明**
|
|
**名称**
|
**值**
|
**说明**
|
| -------- | -------- | -------- |
| -------- | -------- | -------- |
| WIFI_SEC_TYPE_INVALID | 0 | 无效加密类型。 |
| WIFI_SEC_TYPE_INVALID | 0 | 无效加密类型。 |
| WIFI_SEC_TYPE_OPEN | 1 | 开放加密类型。 |
| WIFI_SEC_TYPE_OPEN | 1 | 开放加密类型。 |
| WIFI_SEC_TYPE_WEP | 2 | Wired
Equivalent
Privacy
(WEP)加密类型。 |
| WIFI_SEC_TYPE_WEP | 2 | Wired
Equivalent
Privacy
(WEP)加密类型。 |
| WIFI_SEC_TYPE_PSK | 3 | Pre-shared
key
(PSK)加密类型。 |
| WIFI_SEC_TYPE_PSK | 3 | Pre-shared
key
(PSK)加密类型。 |
| WIFI_SEC_TYPE_SAE | 4 | Simultaneous
Authentication
of
Equals
(SAE)加密类型。 |
| WIFI_SEC_TYPE_SAE | 4 | Simultaneous
Authentication
of
Equals
(SAE)加密类型。 |
| WIFI_SEC_TYPE_EAP
<sup>
9+
</sup>
| 5 | EAP加密类型。 |
| WIFI_SEC_TYPE_EAP_SUITE_B
<sup>
9+
</sup>
| 6 | Suite-B 192位加密类型。 |
| WIFI_SEC_TYPE_OWE
<sup>
9+
</sup>
| 7 | 机会性无线加密类型。 |
| WIFI_SEC_TYPE_WAPI_CERT
<sup>
9+
</sup>
| 8 | WAPI-Cert加密类型。 |
| WIFI_SEC_TYPE_WAPI_PSK
<sup>
9+
</sup>
| 9 | WAPI-PSK加密类型。 |
## WifiInfoElem<sup>9+</sup>
WLAN热点信息。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**读写属性**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| eid | number | 只读 | 元素ID。 |
| content | Uint8Array | 只读 | 元素内容。 |
## WifiChannelWidth<sup>9+</sup>
表示带宽类型的枚举。
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**名称**
|
**默认值**
|
**说明**
|
| -------- | -------- | -------- |
| WIDTH_20MHZ | 0 | 20MHZ。 |
| WIDTH_40MHZ | 1 | 40MHZ。 |
| WIDTH_80MHZ | 2 | 80MHZ。 |
| WIDTH_160MHZ | 3 | 160MHZ。 |
| WIDTH_80MHZ_PLUS | 4 | 80MHZ
<sup>
+
</sup>
。 |
| WIDTH_INVALID | 5 | 无效值 |
## wifi.getScanInfosSync<sup>9+</sup>
## wifi.getScanInfosSync<sup>9+</sup>
...
@@ -283,21 +243,20 @@ WLAN配置信息。
...
@@ -283,21 +243,20 @@ WLAN配置信息。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**
读写属性
**
|
**说明**
|
|
**参数名**
|
**类型**
|
**
可读**
|
**可写
**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| ssid | string | 只读 | 热点的SSID,编码格式为UTF-8。 |
| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
| bssid | string | 只读 | 热点的BSSID。 |
| bssid | string | 是 | 否 | 热点的BSSID。 |
| preSharedKey | string | 只读 | 热点的密钥。 |
| preSharedKey | string | 是 | 否 | 热点的密钥。 |
| isHiddenSsid | boolean | 只读 | 是否是隐藏网络。 |
| isHiddenSsid | boolean | 是 | 否 | 是否是隐藏网络。 |
| securityType |
[
WifiSecurityType
](
#wifisecuritytype
)
| 只读 | 加密类型。 |
| securityType |
[
WifiSecurityType
](
#wifisecuritytype
)
| 是 | 否 | 加密类型。 |
| creatorUid | number | 只读 | 创建用户的ID。
<br
/>
**系统接口:**
此接口为系统接口。 |
| creatorUid | number | 是 | 否 | 创建用户的ID。
<br
/>
**系统接口:**
此接口为系统接口。 |
| disableReason | number | 只读 | 禁用原因。
<br
/>
**系统接口:**
此接口为系统接口。 |
| disableReason | number | 是 | 否 | 禁用原因。
<br
/>
**系统接口:**
此接口为系统接口。 |
| netId | number | 只读 | 分配的网络ID。
<br
/>
**系统接口:**
此接口为系统接口。 |
| netId | number | 是 | 否 | 分配的网络ID。
<br
/>
**系统接口:**
此接口为系统接口。 |
| randomMacType | number | 只读 | 随机MAC类型。
<br
/>
**系统接口:**
此接口为系统接口。 |
| randomMacType | number | 是 | 否 | 随机MAC类型。
<br
/>
**系统接口:**
此接口为系统接口。 |
| randomMacAddr | string | 只读 | 随机MAC地址。
<br
/>
**系统接口:**
此接口为系统接口。 |
| randomMacAddr | string | 是 | 否 | 随机MAC地址。
<br
/>
**系统接口:**
此接口为系统接口。 |
| ipType |
[
IpType
](
#iptype7
)
| 只读 | IP地址类型。
<br
/>
**系统接口:**
此接口为系统接口。 |
| ipType |
[
IpType
](
#iptype7
)
| 是 | 否 | IP地址类型。
<br
/>
**系统接口:**
此接口为系统接口。 |
| staticIp |
[
IpConfig
](
#ipconfig7
)
| 只读 | 静态IP配置信息。
<br
/>
**系统接口:**
此接口为系统接口。 |
| staticIp |
[
IpConfig
](
#ipconfig7
)
| 是 | 否 | 静态IP配置信息。
<br
/>
**系统接口:**
此接口为系统接口。 |
| eapConfig
<sup>
9+
</sup>
|
[
WifiEapConfig
](
#wifieapconfig9
)
| 只读 | 可扩展身份验证协议配置。
<br
/>
**系统接口:**
此接口为系统接口。 |
## IpType<sup>7+</sup>
## IpType<sup>7+</sup>
...
@@ -309,7 +268,7 @@ WLAN配置信息。
...
@@ -309,7 +268,7 @@ WLAN配置信息。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 名称 |
默认
值 | 说明 |
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| -------- | -------- | -------- |
| STATIC | 0 | 静态IP。 |
| STATIC | 0 | 静态IP。 |
| DHCP | 1 | 通过DHCP获取。 |
| DHCP | 1 | 通过DHCP获取。 |
...
@@ -324,78 +283,12 @@ IP配置信息。
...
@@ -324,78 +283,12 @@ IP配置信息。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**
读写属性
**
|
**说明**
|
|
**参数名**
|
**类型**
|
**
可读**
|
**可写
**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| ipAddress | number | 只读 | IP地址。 |
| ipAddress | number | 是 | 否 | IP地址。 |
| gateway | number | 只读 | 网关。 |
| gateway | number | 是 | 否 | 网关。 |
| dnsServers | number[] | 只读 | DNS服务器。 |
| dnsServers | number[] | 是 | 否 | DNS服务器。 |
| domains | Array
<
string
>
| 只读 | 域信息。 |
| domains | Array
<
string
>
| 是 | 否 | 域信息。 |
## WifiEapConfig<sup>9+</sup>
可扩展身份验证协议配置信息。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**读写属性**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| eapMethod |
[
EapMethod
](
#eapmethod9
)
| 只读 | EAP认证方式。 |
| phase2Method |
[
Phase2Method
](
#phase2method9
)
| 只读 | 第二阶段认证方式。 |
| identity | string | 只读 | 身份信息。 |
| anonymousIdentity | string | 只读 | 匿名身份。 |
| password | string | 只读 | 密码。 |
| caCertAliases | string | 只读 | CA 证书别名。 |
| caPath | string | 只读 | CA 证书路径。 |
| clientCertAliases | string | 只读 | 客户端证书别名。 |
| altSubjectMatch | string | 只读 | 替代主题匹配。 |
| domainSuffixMatch | string | 只读 | 域后缀匹配。 |
| realm | string | 只读 | 通行证凭证的领域。 |
| plmn | string | 只读 | 公共陆地移动网的直通凭证提供商。 |
| eapSubId | number | 只读 | SIM卡的子ID。 |
## EapMethod<sup>9+</sup>
表示EAP认证方式的枚举。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| EAP_NONE | 0 | 不指定。 |
| EAP_PEAP | 1 | PEAP类型。 |
| EAP_TLS | 2 | TLS类型。 |
| EAP_TTLS | 3 | TTLS类型。 |
| EAP_PWD | 4 | PWD类型。 |
| EAP_SIM | 5 | SIM类型。 |
| EAP_AKA | 6 | AKA类型。 |
| EAP_AKA_PRIME | 7 | AKA Prime类型。 |
| EAP_UNAUTH_TLS | 8 | UNAUTH TLS类型。 |
## Phase2Method<sup>9+</sup>
表示第二阶段认证方式的枚举。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| PHASE2_NONE | 0 | 不指定。 |
| PHASE2_PAP | 1 | PAP类型。 |
| PHASE2_MSCHAP | 2 | MSCHAP类型。 |
| PHASE2_MSCHAPV2 | 3 | MSCHAPV2类型。 |
| PHASE2_GTC | 4 | GTC类型。 |
| PHASE2_SIM | 5 | SIM类型。 |
| PHASE2_AKA | 6 | AKA类型。 |
| PHASE2_AKA_PRIME | 7 | AKA Prime类型。 |
## wifi.addDeviceConfig
## wifi.addDeviceConfig
...
@@ -500,122 +393,6 @@ removeUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback<boole
...
@@ -500,122 +393,6 @@ removeUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback<boole
| callback | AsyncCallback
<
boolean
>
| 是 | 回调函数。当操作成功时,err为0,data表示操作结果,true: 成功, false: 失败。如果error为非0,表示处理出现错误。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调函数。当操作成功时,err为0,data表示操作结果,true: 成功, false: 失败。如果error为非0,表示处理出现错误。 |
## wifi.addCandidateConfig<sup>9+</sup>
addCandidateConfig(config: WifiDeviceConfig): Promise
<
number
>
添加候选网络配置,使用Promise异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| Promise
<
number
>
| Promise对象。表示网络配置ID。 |
## wifi.addCandidateConfig<sup>9+</sup>
addCandidateConfig(config: WifiDeviceConfig, callback: AsyncCallback
<
number
>
): void
添加候选网络配置,使用callback异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数。当操作成功时,err为0,data为添加的网络配置ID,如果data值为-1,表示添加失败。如果操作出现错误,err为非0值。 |
## wifi.removeCandidateConfig<sup>9+</sup>
removeCandidateConfig(networkId: number): Promise
<
void
>
移除候选网络配置,使用Promise异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| networkId | number | 是 | 网络配置ID。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| Promise
<
void
>
| Promise对象。 |
## wifi.removeCandidateConfig<sup>9+</sup>
removeCandidateConfig(networkId: number, callback: AsyncCallback
<
void
>
): void
移除候选网络配置,使用callback异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| networkId | number | 是 | 网络配置ID。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。当操作成功时,err为0。如果error为非0,表示处理出现错误。 |
## wifi.getCandidateConfigs<sup>9+</sup>
getCandidateConfigs():
Array
<
[WifiDeviceConfig](#wifideviceconfig)
>
获取候选网络配置。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
|
Array
<
[WifiDeviceConfig](#wifideviceconfig)
>
| 候选网络配置数组。 |
## wifi.connectToCandidateConfig<sup>9+</sup>
connectToCandidateConfig(networkId: number): void
连接到候选网络。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| networkId | number | 是 | 候选网络配置的ID。 |
## wifi.connectToNetwork
## wifi.connectToNetwork
connectToNetwork(networkId: number): boolean
connectToNetwork(networkId: number): boolean
...
@@ -770,24 +547,23 @@ getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void
...
@@ -770,24 +547,23 @@ getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void
**系统能力:**
SystemCapability.Communication.WiFi.STA
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 参数名 | 类型 |
读写属性
| 说明 |
| 参数名 | 类型 |
可读 | 可写
| 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| ssid | string | 只读 | 热点的SSID,编码格式为UTF-8。 |
| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
| bssid | string | 只读 | 热点的BSSID。 |
| bssid | string | 是 | 否 | 热点的BSSID。 |
| networkId | number | 只读 | 网络配置ID。
<br
/>
**系统接口:**
此接口为系统接口。 |
| networkId | number | 是 | 否 | 网络配置ID。
<br
/>
**系统接口:**
此接口为系统接口。 |
| rssi | number | 只读 | 热点的信号强度(dBm)。 |
| rssi | number | 是 | 否 | 热点的信号强度(dBm)。 |
| band | number | 只读 | WLAN接入点的频段。 |
| band | number | 是 | 否 | WLAN接入点的频段。 |
| linkSpeed | number | 只读 | WLAN接入点的速度。 |
| linkSpeed | number | 是 | 否 | WLAN接入点的速度。 |
| frequency | number | 只读 | WLAN接入点的频率。 |
| frequency | number | 是 | 否 | WLAN接入点的频率。 |
| isHidden | boolean | 只读 | WLAN接入点是否是隐藏网络。 |
| isHidden | boolean | 是 | 否 | WLAN接入点是否是隐藏网络。 |
| isRestricted | boolean | 只读 | WLAN接入点是否限制数据量。 |
| isRestricted | boolean | 是 | 否 | WLAN接入点是否限制数据量。 |
| chload | number | 只读 | 连接负载,值越大表示负载约高。
<br
/>
**系统接口:**
此接口为系统接口。 |
| chload | number | 是 | 否 | 连接负载,值越大表示负载约高。
<br
/>
**系统接口:**
此接口为系统接口。 |
| snr | number | 只读 | 信噪比。
<br
/>
**系统接口:**
此接口为系统接口。 |
| snr | number | 是 | 否 | 信噪比。
<br
/>
**系统接口:**
此接口为系统接口。 |
| macType
<sup>
9+
</sup>
| number | 只读 | MAC地址类型。 |
| macAddress | string | 是 | 否 | 设备的MAC地址。 |
| macAddress | string | 只读 | 设备的MAC地址。 |
| ipAddress | number | 是 | 否 | WLAN连接的IP地址。 |
| ipAddress | number | 只读 | WLAN连接的IP地址。 |
| suppState |
[
SuppState
](
#suppstate
)
| 是 | 否 | 请求状态。
<br
/>
**系统接口:**
此接口为系统接口。 |
| suppState |
[
SuppState
](
#suppstate
)
| 只读 | 请求状态。
<br
/>
**系统接口:**
此接口为系统接口。 |
| connState |
[
ConnState
](
#connstate
)
| 是 | 否 | WLAN连接状态。 |
| connState |
[
ConnState
](
#connstate
)
| 只读 | WLAN连接状态。 |
## ConnState
## ConnState
...
@@ -796,7 +572,7 @@ getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void
...
@@ -796,7 +572,7 @@ getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void
**系统能力:**
SystemCapability.Communication.WiFi.STA
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 名称 |
默认
值 | 说明 |
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| -------- | -------- | -------- |
| SCANNING | 0 | 设备正在搜索可用的AP。 |
| SCANNING | 0 | 设备正在搜索可用的AP。 |
| CONNECTING | 1 | 正在建立WLAN连接。 |
| CONNECTING | 1 | 正在建立WLAN连接。 |
...
@@ -816,7 +592,7 @@ getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void
...
@@ -816,7 +592,7 @@ getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void
**系统能力:**
SystemCapability.Communication.WiFi.STA
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 名称 |
默认
值 | 说明 |
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| -------- | -------- | -------- |
| DISCONNECTED | 0 | 已断开。 |
| DISCONNECTED | 0 | 已断开。 |
| INTERFACE_DISABLED | 1 | 接口禁用。 |
| INTERFACE_DISABLED | 1 | 接口禁用。 |
...
@@ -949,15 +725,15 @@ IP信息。
...
@@ -949,15 +725,15 @@ IP信息。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**
读写属性
**
|
**说明**
|
|
**参数名**
|
**类型**
|
**
可读**
|
**可写
**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| ipAddress | number |
只读
| IP地址。 |
| ipAddress | number |
是 | 否
| IP地址。 |
| gateway | number |
只读
| 网关。 |
| gateway | number |
是 | 否
| 网关。 |
| netmask | number |
只读
| 掩码。 |
| netmask | number |
是 | 否
| 掩码。 |
| primaryDns | number |
只读
| 主DNS服务器IP地址。 |
| primaryDns | number |
是 | 否
| 主DNS服务器IP地址。 |
| secondDns | number |
只读
| 备DNS服务器IP地址。 |
| secondDns | number |
是 | 否
| 备DNS服务器IP地址。 |
| serverIp | number |
只读
| DHCP服务端IP地址。 |
| serverIp | number |
是 | 否
| DHCP服务端IP地址。 |
| leaseDuration | number |
只读
| IP地址租用时长。 |
| leaseDuration | number |
是 | 否
| IP地址租用时长。 |
## wifi.getCountryCode<sup>7+</sup>
## wifi.getCountryCode<sup>7+</sup>
...
@@ -1237,13 +1013,13 @@ setHotspotConfig(config: HotspotConfig): boolean
...
@@ -1237,13 +1013,13 @@ setHotspotConfig(config: HotspotConfig): boolean
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
|
**参数名**
|
**类型**
|
**
读写属性
**
|
**说明**
|
|
**参数名**
|
**类型**
|
**
可读**
|
**可写
**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| ssid | string |
只读
| 热点的SSID,编码格式为UTF-8。 |
| ssid | string |
是 | 否
| 热点的SSID,编码格式为UTF-8。 |
| securityType |
[
WifiSecurityType
](
#wifisecuritytype
)
|
只读
| 加密类型。 |
| securityType |
[
WifiSecurityType
](
#wifisecuritytype
)
|
是 | 否
| 加密类型。 |
| band | number |
只读
| 热点的带宽。1: 2.4G, 2: 5G, 3: 双模频段 |
| band | number |
是 | 否
| 热点的带宽。1: 2.4G, 2: 5G, 3: 双模频段 |
| preSharedKey | string |
只读
| 热点的密钥。 |
| preSharedKey | string |
是 | 否
| 热点的密钥。 |
| maxConn | number |
只读
| 最大设备连接数。 |
| maxConn | number |
是 | 否
| 最大设备连接数。 |
## wifi.getHotspotConfig<sup>7+</sup>
## wifi.getHotspotConfig<sup>7+</sup>
...
@@ -1292,11 +1068,11 @@ getStations(): Array<[StationInfo](#stationinfo7)>
...
@@ -1292,11 +1068,11 @@ getStations(): Array<[StationInfo](#stationinfo7)>
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
|
**参数名**
|
**类型**
|
**
读写属性
**
|
**说明**
|
|
**参数名**
|
**类型**
|
**
可读**
|
**可写
**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| name | string |
只读
| 设备名称。 |
| name | string |
是 | 否
| 设备名称。 |
| macAddress | string |
只读
| MAC地址。 |
| macAddress | string |
是 | 否
| MAC地址。 |
| ipAddress | string |
只读
| IP地址。 |
| ipAddress | string |
是 | 否
| IP地址。 |
## wifi.getP2pLinkedInfo<sup>8+</sup>
## wifi.getP2pLinkedInfo<sup>8+</sup>
...
@@ -1323,11 +1099,11 @@ getP2pLinkedInfo(): Promise<WifiP2pLinkedInfo>
...
@@ -1323,11 +1099,11 @@ getP2pLinkedInfo(): Promise<WifiP2pLinkedInfo>
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 参数名 | 类型 |
读写属性
| 说明 |
| 参数名 | 类型 |
可读 | 可写
| 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| connectState |
[
P2pConnectState
](
#p2pconnectstate8
)
|
只读
| P2P连接状态。 |
| connectState |
[
P2pConnectState
](
#p2pconnectstate8
)
|
是 | 否
| P2P连接状态。 |
| isGroupOwner | boolean |
只读
| 是否是群主。 |
| isGroupOwner | boolean |
是 | 否
| 是否是群主。 |
| groupOwnerAddr | string |
只读
| 群组MAC地址。
| groupOwnerAddr | string |
是 | 否
| 群组MAC地址。
## P2pConnectState<sup>8+</sup>
## P2pConnectState<sup>8+</sup>
...
@@ -1336,7 +1112,7 @@ getP2pLinkedInfo(): Promise<WifiP2pLinkedInfo>
...
@@ -1336,7 +1112,7 @@ getP2pLinkedInfo(): Promise<WifiP2pLinkedInfo>
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 名称 |
默认
值 | 说明 |
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| -------- | -------- | -------- |
| DISCONNECTED | 0 | 断开状态。 |
| DISCONNECTED | 0 | 断开状态。 |
| CONNECTED | 1 | 连接状态。 |
| CONNECTED | 1 | 连接状态。 |
...
@@ -1433,13 +1209,13 @@ getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void
...
@@ -1433,13 +1209,13 @@ getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 参数名 | 类型 |
读写属性
| 说明 |
| 参数名 | 类型 |
可读 | 可写
| 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| deviceName | string |
只读
| 设备名称。 |
| deviceName | string |
是 | 否
| 设备名称。 |
| deviceAddress | string |
只读
| 设备MAC地址。 |
| deviceAddress | string |
是 | 否
| 设备MAC地址。 |
| primaryDeviceType | string |
只读
| 主设备类型。 |
| primaryDeviceType | string |
是 | 否
| 主设备类型。 |
| deviceStatus |
[
P2pDeviceStatus
](
#p2pdevicestatus8
)
|
只读
| 设备状态。 |
| deviceStatus |
[
P2pDeviceStatus
](
#p2pdevicestatus8
)
|
是 | 否
| 设备状态。 |
| groupCapabilitys | number |
只读
| 群组能力。 |
| groupCapabilitys | number |
是 | 否
| 群组能力。 |
## P2pDeviceStatus<sup>8+</sup>
## P2pDeviceStatus<sup>8+</sup>
...
@@ -1448,7 +1224,7 @@ getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void
...
@@ -1448,7 +1224,7 @@ getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 名称 |
默认
值 | 说明 |
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| -------- | -------- | -------- |
| CONNECTED | 0 | 连接状态。 |
| CONNECTED | 0 | 连接状态。 |
| INVITED | 1 | 邀请状态。 |
| INVITED | 1 | 邀请状态。 |
...
@@ -1457,40 +1233,6 @@ getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void
...
@@ -1457,40 +1233,6 @@ getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void
| UNAVAILABLE | 4 | 不可用状态。 |
| UNAVAILABLE | 4 | 不可用状态。 |
## wifi.getP2pLocalDevice<sup>9+</sup>
getP2pLocalDevice(): Promise
<
WifiP2pDevice
>
获取P2P本端设备信息,使用Promise异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
[WifiP2pDevice](#wifip2pdevice8)
>
| Promise对象。表示本端设备信息。 |
## wifi.getP2pLocalDevice<sup>9+</sup>
getP2pLocalDevice(callback: AsyncCallback
<
WifiP2pDevice
>
): void
获取P2P本端设备信息,使用callback异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
[WifiP2pDevice](#wifip2pdevice8)
>
| 是 | 回调函数。当操作成功时,err为0,data表示本端设备信息。如果error为非0,表示处理出现错误。 |
## wifi.createGroup<sup>8+</sup>
## wifi.createGroup<sup>8+</sup>
createGroup(config: WifiP2PConfig): boolean
createGroup(config: WifiP2PConfig): boolean
...
@@ -1520,13 +1262,13 @@ createGroup(config: WifiP2PConfig): boolean
...
@@ -1520,13 +1262,13 @@ createGroup(config: WifiP2PConfig): boolean
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 参数名 | 类型 |
读写属性
| 说明 |
| 参数名 | 类型 |
可读 | 可写
| 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| deviceAddress | string |
只读
| 设备地址。 |
| deviceAddress | string |
是 | 否
| 设备地址。 |
| netId | number |
只读
| 网络ID。创建群组时-1表示创建临时组,-2表示创建永久组。 |
| netId | number |
是 | 否
| 网络ID。创建群组时-1表示创建临时组,-2表示创建永久组。 |
| passphrase | string |
只读
| 群组密钥。 |
| passphrase | string |
是 | 否
| 群组密钥。 |
| groupName | string |
只读
| 群组名称。 |
| groupName | string |
是 | 否
| 群组名称。 |
| goBand |
[
GroupOwnerBand
](
#groupownerband8
)
|
只读
| 群组带宽。 |
| goBand |
[
GroupOwnerBand
](
#groupownerband8
)
|
是 | 否
| 群组带宽。 |
## GroupOwnerBand<sup>8+</sup>
## GroupOwnerBand<sup>8+</sup>
...
@@ -1535,7 +1277,7 @@ createGroup(config: WifiP2PConfig): boolean
...
@@ -1535,7 +1277,7 @@ createGroup(config: WifiP2PConfig): boolean
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 名称 |
默认
值 | 说明 |
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| -------- | -------- | -------- |
| GO_BAND_AUTO | 0 | 自动模式。 |
| GO_BAND_AUTO | 0 | 自动模式。 |
| GO_BAND_2GHZ | 1 | 2GHZ。 |
| GO_BAND_2GHZ | 1 | 2GHZ。 |
...
@@ -1727,42 +1469,23 @@ deletePersistentGroup(netId: number): boolean
...
@@ -1727,42 +1469,23 @@ deletePersistentGroup(netId: number): boolean
| boolean | true:操作执行成功,操作执行失败。 |
| boolean | true:操作执行成功,操作执行失败。 |
## wifi.getP2pGroups<sup>9+</sup>
getP2pGroups(): Promise
<
Array
<
WifiP2pGroupInfo
>>
获取创建的所有P2P群组信息,使用Promise异步回调。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
Array
<
[WifiP2pGroupInfo](#wifip2pgroupinfo8)
> >
| Promise对象。表示所有群组信息。 |
## WifiP2pGroupInfo<sup>8+</sup>
## WifiP2pGroupInfo<sup>8+</sup>
表示P2P群组相关信息。
表示P2P群组相关信息。
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 参数名 | 类型 |
读写属性
| 说明 |
| 参数名 | 类型 |
可读 | 可写
| 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| isP2pGo | boolean |
只读
| 是否是群主。 |
| isP2pGo | boolean |
是 | 否
| 是否是群主。 |
| ownerInfo |
[
WifiP2pDevice
](
#wifip2pdevice8
)
|
只读
| 群组的设备信息。 |
| ownerInfo |
[
WifiP2pDevice
](
#wifip2pdevice8
)
|
是 | 否
| 群组的设备信息。 |
| passphrase | string |
只读
| 群组密钥。 |
| passphrase | string |
是 | 否
| 群组密钥。 |
| interface | string |
只读
| 接口名称。 |
| interface | string |
是 | 否
| 接口名称。 |
| groupName | string |
只读
| 群组名称。 |
| groupName | string |
是 | 否
| 群组名称。 |
| networkId | number |
只读
| 网络ID。 |
| networkId | number |
是 | 否
| 网络ID。 |
| frequency | number |
只读
| 群组的频率。 |
| frequency | number |
是 | 否
| 群组的频率。 |
| clientDevices |
[
WifiP2pDevice[]
](
#wifip2pdevice8
)
|
只读
| 接入的设备列表信息。 |
| clientDevices |
[
WifiP2pDevice[]
](
#wifip2pdevice8
)
|
是 | 否
| 接入的设备列表信息。 |
| goIpAddress | string |
只读
| 群组IP地址。 |
| goIpAddress | string |
是 | 否
| 群组IP地址。 |
## wifi.getP2pGroups<sup>9+</sup>
## wifi.getP2pGroups<sup>9+</sup>
...
...
zh-cn/application-dev/reference/apis/js-apis-wifiManager.md
0 → 100644
浏览文件 @
f66129ce
# WLAN
该模块主要提供WLAN基础功能、P2P(peer-to-peer)功能和WLAN消息通知的相应服务,让应用可以通过WLAN和其他设备互联互通。
>  **说明:**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```
js
import
wifi
from
'
@ohos.wifi
'
;
```
## wifi.enableWifi
enableWifi(): boolean
使能WLAN。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。|
## wifi.disableWifi
disableWifi(): boolean
去使能WLAN。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。|
## wifi.isWifiActive
isWifiActive(): boolean
查询WLAN是否已使能。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:已使能,
false:未使能。 |
## wifi.scan
scan(): boolean
启动WLAN扫描。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:扫描操作执行成功,
false:扫描操作执行失败。 |
## wifi.getScanInfos
getScanInfos(): Promise
<
Array
<
WifiScanInfo
>>
获取扫描结果,使用Promise异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 (ohos.permission.GET_WIFI_PEERS_MAC 或 ohos.permission.LOCATION)
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| Promise
<
Array
<
[WifiScanInfo](#wifiscaninfo)
> >
| Promise对象。返回扫描到的热点列表。 |
## wifi.getScanInfos
getScanInfos(callback: AsyncCallback
<
Array
<
WifiScanInfo
>>
): void
获取扫描结果,使用callback异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 (ohos.permission.GET_WIFI_PEERS_MAC 或 ohos.permission.LOCATION)
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
Array
<
[WifiScanInfo](#wifiscaninfo)
>>
| 是 | 回调函数。当成功时,err为0,data为扫描到的热点;否则err为非0值,data为空。 |
**示例:**
```
js
import
wifi
from
'
@ohos.wifi
'
;
wifi
.
getScanInfos
((
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
"
get scan info error
"
);
return
;
}
var
len
=
Object
.
keys
(
result
).
length
;
console
.
log
(
"
wifi received scan info:
"
+
len
);
for
(
var
i
=
0
;
i
<
len
;
++
i
)
{
console
.
info
(
"
ssid:
"
+
result
[
i
].
ssid
);
console
.
info
(
"
bssid:
"
+
result
[
i
].
bssid
);
console
.
info
(
"
capabilities:
"
+
result
[
i
].
capabilities
);
console
.
info
(
"
securityType:
"
+
result
[
i
].
securityType
);
console
.
info
(
"
rssi:
"
+
result
[
i
].
rssi
);
console
.
info
(
"
band:
"
+
result
[
i
].
band
);
console
.
info
(
"
frequency:
"
+
result
[
i
].
frequency
);
console
.
info
(
"
channelWidth:
"
+
result
[
i
].
channelWidth
);
console
.
info
(
"
timestamp:
"
+
result
[
i
].
timestamp
);
}
});
wifi
.
getScanInfos
().
then
(
result
=>
{
var
len
=
Object
.
keys
(
result
).
length
;
console
.
log
(
"
wifi received scan info:
"
+
len
);
for
(
var
i
=
0
;
i
<
len
;
++
i
)
{
console
.
info
(
"
ssid:
"
+
result
[
i
].
ssid
);
console
.
info
(
"
bssid:
"
+
result
[
i
].
bssid
);
console
.
info
(
"
capabilities:
"
+
result
[
i
].
capabilities
);
console
.
info
(
"
securityType:
"
+
result
[
i
].
securityType
);
console
.
info
(
"
rssi:
"
+
result
[
i
].
rssi
);
console
.
info
(
"
band:
"
+
result
[
i
].
band
);
console
.
info
(
"
frequency:
"
+
result
[
i
].
frequency
);
console
.
info
(
"
channelWidth:
"
+
result
[
i
].
channelWidth
);
console
.
info
(
"
timestamp:
"
+
result
[
i
].
timestamp
);
}
});
```
## WifiScanInfo
WLAN热点信息。
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**可读**
|
**可写**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
| bssid | string | 是 | 否 | 热点的BSSID。 |
| capabilities | string | 是 | 否 | 热点能力。 |
| securityType |
[
WifiSecurityType
](
#wifisecuritytype
)
| 是 | 否 | WLAN加密类型。 |
| rssi | number | 是 | 否 | 热点的信号强度(dBm)。 |
| band | number | 是 | 否 | WLAN接入点的频段。 |
| frequency | number | 是 | 否 | WLAN接入点的频率。 |
| channelWidth | number | 是 | 否 | WLAN接入点的带宽。 |
| centerFrequency0
<sup>
9+
</sup>
| number | 是 | 否 | 热点的中心频率。 |
| centerFrequency1
<sup>
9+
</sup>
| number | 是 | 否 | 热点的中心频率。如果热点使用两个不重叠的WLAN信道,则返回两个中心频率,分别用centerFrequency0和centerFrequency1表示。 |
| infoElems
<sup>
9+
</sup>
| Array
<
[WifiInfoElem](#wifiinfoelem9)
>
| 是 | 否 | 信息元素。 |
| timestamp | number | 是 | 否 | 时间戳。 |
## WifiSecurityType
表示加密类型的枚举。
**系统能力:**
SystemCapability.Communication.WiFi.Core
|
**名称**
|
**值**
|
**说明**
|
| -------- | -------- | -------- |
| WIFI_SEC_TYPE_INVALID | 0 | 无效加密类型。 |
| WIFI_SEC_TYPE_OPEN | 1 | 开放加密类型。 |
| WIFI_SEC_TYPE_WEP | 2 | Wired
Equivalent
Privacy
(WEP)加密类型。 |
| WIFI_SEC_TYPE_PSK | 3 | Pre-shared
key
(PSK)加密类型。 |
| WIFI_SEC_TYPE_SAE | 4 | Simultaneous
Authentication
of
Equals
(SAE)加密类型。 |
| WIFI_SEC_TYPE_EAP
<sup>
9+
</sup>
| 5 | EAP加密类型。 |
| WIFI_SEC_TYPE_EAP_SUITE_B
<sup>
9+
</sup>
| 6 | Suite-B 192位加密类型。 |
| WIFI_SEC_TYPE_OWE
<sup>
9+
</sup>
| 7 | 机会性无线加密类型。 |
| WIFI_SEC_TYPE_WAPI_CERT
<sup>
9+
</sup>
| 8 | WAPI-Cert加密类型。 |
| WIFI_SEC_TYPE_WAPI_PSK
<sup>
9+
</sup>
| 9 | WAPI-PSK加密类型。 |
## WifiInfoElem<sup>9+</sup>
WLAN热点信息。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**读写属性**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| eid | number | 只读 | 元素ID。 |
| content | Uint8Array | 只读 | 元素内容。 |
## WifiChannelWidth<sup>9+</sup>
表示带宽类型的枚举。
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**名称**
|
**默认值**
|
**说明**
|
| -------- | -------- | -------- |
| WIDTH_20MHZ | 0 | 20MHZ。 |
| WIDTH_40MHZ | 1 | 40MHZ。 |
| WIDTH_80MHZ | 2 | 80MHZ。 |
| WIDTH_160MHZ | 3 | 160MHZ。 |
| WIDTH_80MHZ_PLUS | 4 | 80MHZ
<sup>
+
</sup>
。 |
| WIDTH_INVALID | 5 | 无效值 |
## wifi.getScanInfosSync<sup>9+</sup>
getScanInfosSync():
Array
<
[WifiScanInfo](#wifiscaninfo)
>
获取扫描结果,使用同步方式返回结果。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 (ohos.permission.GET_WIFI_PEERS_MAC 或 ohos.permission.LOCATION)
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
|
Array
<
[WifiScanInfo](#wifiscaninfo)
>
| 扫描结果数组。 |
## wifi.addDeviceConfig
addDeviceConfig(config: WifiDeviceConfig): Promise
<
number
>
添加网络配置,使用Promise异步回调。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.SET_WIFI_CONFIG
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| Promise
<
number
>
| Promise对象。返回添加的网络配置ID,如果值为-1表示添加失败。 |
## WifiDeviceConfig
WLAN配置信息。
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**可读**
|
**可写**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
| bssid | string | 是 | 否 | 热点的BSSID。 |
| preSharedKey | string | 是 | 否 | 热点的密钥。 |
| isHiddenSsid | boolean | 是 | 否 | 是否是隐藏网络。 |
| securityType |
[
WifiSecurityType
](
#wifisecuritytype
)
| 是 | 否 | 加密类型。 |
| creatorUid | number | 是 | 否 | 创建用户的ID。
<br
/>
**系统接口:**
此接口为系统接口。 |
| disableReason | number | 是 | 否 | 禁用原因。
<br
/>
**系统接口:**
此接口为系统接口。 |
| netId | number | 是 | 否 | 分配的网络ID。
<br
/>
**系统接口:**
此接口为系统接口。 |
| randomMacType | number | 是 | 否 | 随机MAC类型。
<br
/>
**系统接口:**
此接口为系统接口。 |
| randomMacAddr | string | 是 | 否 | 随机MAC地址。
<br
/>
**系统接口:**
此接口为系统接口。 |
| ipType |
[
IpType
](
#iptype7
)
| 是 | 否 | IP地址类型。
<br
/>
**系统接口:**
此接口为系统接口。 |
| staticIp |
[
IpConfig
](
#ipconfig7
)
| 是 | 否 | 静态IP配置信息。
<br
/>
**系统接口:**
此接口为系统接口。 |
| eapConfig
<sup>
9+
</sup>
|
[
WifiEapConfig
](
#wifieapconfig9
)
| 是 | 否 | 可扩展身份验证协议配置。
<br
/>
**系统接口:**
此接口为系统接口。 |
## IpType<sup>7+</sup>
表示IP类型的枚举。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| STATIC | 0 | 静态IP。 |
| DHCP | 1 | 通过DHCP获取。 |
| UNKNOWN | 2 | 未指定。 |
## IpConfig<sup>7+</sup>
IP配置信息。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**可读**
|
**可写**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| ipAddress | number | 是 | 否 | IP地址。 |
| gateway | number | 是 | 否 | 网关。 |
| dnsServers | number[] | 是 | 否 | DNS服务器。 |
| domains | Array
<
string
>
| 是 | 否 | 域信息。 |
## WifiEapConfig<sup>9+</sup>
可扩展身份验证协议配置信息。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**读写属性**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| eapMethod |
[
EapMethod
](
#eapmethod9
)
| 只读 | EAP认证方式。 |
| phase2Method |
[
Phase2Method
](
#phase2method9
)
| 只读 | 第二阶段认证方式。 |
| identity | string | 只读 | 身份信息。 |
| anonymousIdentity | string | 只读 | 匿名身份。 |
| password | string | 只读 | 密码。 |
| caCertAliases | string | 只读 | CA 证书别名。 |
| caPath | string | 只读 | CA 证书路径。 |
| clientCertAliases | string | 只读 | 客户端证书别名。 |
| altSubjectMatch | string | 只读 | 替代主题匹配。 |
| domainSuffixMatch | string | 只读 | 域后缀匹配。 |
| realm | string | 只读 | 通行证凭证的领域。 |
| plmn | string | 只读 | 公共陆地移动网的直通凭证提供商。 |
| eapSubId | number | 只读 | SIM卡的子ID。 |
## EapMethod<sup>9+</sup>
表示EAP认证方式的枚举。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| EAP_NONE | 0 | 不指定。 |
| EAP_PEAP | 1 | PEAP类型。 |
| EAP_TLS | 2 | TLS类型。 |
| EAP_TTLS | 3 | TTLS类型。 |
| EAP_PWD | 4 | PWD类型。 |
| EAP_SIM | 5 | SIM类型。 |
| EAP_AKA | 6 | AKA类型。 |
| EAP_AKA_PRIME | 7 | AKA Prime类型。 |
| EAP_UNAUTH_TLS | 8 | UNAUTH TLS类型。 |
## Phase2Method<sup>9+</sup>
表示第二阶段认证方式的枚举。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| PHASE2_NONE | 0 | 不指定。 |
| PHASE2_PAP | 1 | PAP类型。 |
| PHASE2_MSCHAP | 2 | MSCHAP类型。 |
| PHASE2_MSCHAPV2 | 3 | MSCHAPV2类型。 |
| PHASE2_GTC | 4 | GTC类型。 |
| PHASE2_SIM | 5 | SIM类型。 |
| PHASE2_AKA | 6 | AKA类型。 |
| PHASE2_AKA_PRIME | 7 | AKA Prime类型。 |
## wifi.addDeviceConfig
addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback
<
number
>
): void
添加网络配置,使用callback异步回调。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.SET_WIFI_CONFIG
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数。当操作成功时,err为0,data为添加的网络配置ID,如果data值为-1,表示添加失败。当error为非0,表示处理出现错误。 |
## wifi.addUntrustedConfig<sup>7+</sup>
addUntrustedConfig(config: WifiDeviceConfig): Promise
<
boolean
>
添加不可信网络配置,使用Promise异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| Promise
<
boolean
>
| Promise对象。表示操作结果,true: 成功, false: 失败。 |
## wifi.addUntrustedConfig<sup>7+</sup>
addUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback
<
boolean
>
): void
添加不可信网络配置,使用callback异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调函数。当操作成功时,err为0,data表示操作结果,true: 成功, false: 失败。如果error为非0,表示处理出现错误。 |
## wifi.removeUntrustedConfig<sup>7+</sup>
removeUntrustedConfig(config: WifiDeviceConfig): Promise
<
boolean
>
移除不可信网络配置,使用Promise异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| Promise
<
boolean
>
| Promise对象。表示操作结果,true: 成功, false: 失败。 |
## wifi.removeUntrustedConfig<sup>7+</sup>
removeUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback
<
boolean
>
): void
移除不可信网络配置,使用callback异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调函数。当操作成功时,err为0,data表示操作结果,true: 成功, false: 失败。如果error为非0,表示处理出现错误。 |
## wifi.addCandidateConfig<sup>9+</sup>
addCandidateConfig(config: WifiDeviceConfig): Promise
<
number
>
添加候选网络配置,使用Promise异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| Promise
<
number
>
| Promise对象。表示网络配置ID。 |
## wifi.addCandidateConfig<sup>9+</sup>
addCandidateConfig(config: WifiDeviceConfig, callback: AsyncCallback
<
number
>
): void
添加候选网络配置,使用callback异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数。当操作成功时,err为0,data为添加的网络配置ID,如果data值为-1,表示添加失败。如果操作出现错误,err为非0值。 |
## wifi.removeCandidateConfig<sup>9+</sup>
removeCandidateConfig(networkId: number): Promise
<
void
>
移除候选网络配置,使用Promise异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| networkId | number | 是 | 网络配置ID。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| Promise
<
void
>
| Promise对象。 |
## wifi.removeCandidateConfig<sup>9+</sup>
removeCandidateConfig(networkId: number, callback: AsyncCallback
<
void
>
): void
移除候选网络配置,使用callback异步回调。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| networkId | number | 是 | 网络配置ID。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。当操作成功时,err为0。如果error为非0,表示处理出现错误。 |
## wifi.getCandidateConfigs<sup>9+</sup>
getCandidateConfigs():
Array
<
[WifiDeviceConfig](#wifideviceconfig)
>
获取候选网络配置。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
|
Array
<
[WifiDeviceConfig](#wifideviceconfig)
>
| 候选网络配置数组。 |
## wifi.connectToCandidateConfig<sup>9+</sup>
connectToCandidateConfig(networkId: number): void
连接到候选网络。
**需要权限:**
ohos.permission.SET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| networkId | number | 是 | 候选网络配置的ID。 |
## wifi.connectToNetwork
connectToNetwork(networkId: number): boolean
连接到指定网络。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| networkId | number | 是 | 待连接的网络配置ID。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。 |
## wifi.connectToDevice
connectToDevice(config: WifiDeviceConfig): boolean
连接到指定网络。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.SET_WIFI_CONFIG 和 ohos.permissio.MANAGE_WIFI_CONNECTION,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。 |
## wifi.disconnect
disconnect(): boolean
断开连接的网络。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。 |
## wifi.getSignalLevel
getSignalLevel(rssi: number, band: number): number
查询WLAN信号强度。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| rssi | number | 是 | 热点的信号强度(dBm)。 |
| band | number | 是 | WLAN接入点的频段。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| number | 信号强度,取值范围为[0,
4]。 |
## wifi.getLinkedInfo
getLinkedInfo(): Promise
<
WifiLinkedInfo
>
获取WLAN连接信息,使用Promise异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
[WifiLinkedInfo](#wifilinkedinfo)
>
| Promise对象。表示WLAN连接信息。 |
## wifi.getLinkedInfo
getLinkedInfo(callback: AsyncCallback
<
WifiLinkedInfo
>
): void
获取WLAN连接信息,使用callback异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
[WifiLinkedInfo](#wifilinkedinfo)
>
| 是 | 回调函数。当获取成功时,err为0,data表示WLAN连接信息。如果error为非0,表示处理出现错误。 |
**示例:**
```
js
import
wifi
from
'
@ohos.wifi
'
;
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
=>
{
console
.
info
(
"
get wifi linked info:
"
+
JSON
.
stringify
(
data
));
}).
catch
(
error
=>
{
console
.
info
(
"
get linked info error
"
);
});
```
## WifiLinkedInfo
提供WLAN连接的相关信息。
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 参数名 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- |
| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
| bssid | string | 是 | 否 | 热点的BSSID。 |
| networkId | number | 是 | 否 | 网络配置ID。
<br
/>
**系统接口:**
此接口为系统接口。 |
| rssi | number | 是 | 否 | 热点的信号强度(dBm)。 |
| band | number | 是 | 否 | WLAN接入点的频段。 |
| linkSpeed | number | 是 | 否 | WLAN接入点的速度。 |
| frequency | number | 是 | 否 | WLAN接入点的频率。 |
| isHidden | boolean | 是 | 否 | WLAN接入点是否是隐藏网络。 |
| isRestricted | boolean | 是 | 否 | WLAN接入点是否限制数据量。 |
| chload | number | 是 | 否 | 连接负载,值越大表示负载约高。
<br
/>
**系统接口:**
此接口为系统接口。 |
| snr | number | 是 | 否 | 信噪比。
<br
/>
**系统接口:**
此接口为系统接口。 |
| macType
<sup>
9+
</sup>
| number | 是 | 否 | MAC地址类型。 |
| macAddress | string | 是 | 否 | 设备的MAC地址。 |
| ipAddress | number | 是 | 否 | WLAN连接的IP地址。 |
| suppState |
[
SuppState
](
#suppstate
)
| 是 | 否 | 请求状态。
<br
/>
**系统接口:**
此接口为系统接口。 |
| connState |
[
ConnState
](
#connstate
)
| 是 | 否 | WLAN连接状态。 |
## ConnState
表示WLAN连接状态的枚举。
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| SCANNING | 0 | 设备正在搜索可用的AP。 |
| CONNECTING | 1 | 正在建立WLAN连接。 |
| AUTHENTICATING | 2 | WLAN连接正在认证中。 |
| OBTAINING_IPADDR | 3 | 正在获取WLAN连接的IP地址。 |
| CONNECTED | 4 | WLAN连接已建立。 |
| DISCONNECTING | 5 | WLAN连接正在断开。 |
| DISCONNECTED | 6 | WLAN连接已断开。 |
| UNKNOWN | 7 | WLAN连接建立失败。 |
## SuppState
表示请求状态的枚举。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.STA
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| DISCONNECTED | 0 | 已断开。 |
| INTERFACE_DISABLED | 1 | 接口禁用。 |
| INACTIVE | 2 | 未激活。 |
| SCANNING | 3 | 扫描中。 |
| AUTHENTICATING | 4 | 认证中。 |
| ASSOCIATING | 5 | 关联中。 |
| ASSOCIATED | 6 | 已关联。 |
| FOUR_WAY_HANDSHAKE | 7 | 四次握手。 |
| GROUP_HANDSHAKE | 8 | 组握手。 |
| COMPLETED | 9 | 所有认证已完成。 |
| UNINITIALIZED | 10 | 连接建立失败。 |
| INVALID | 11 | 无效值。 |
## wifi.isConnected<sup>7+</sup>
isConnected(): boolean
查询WLAN是否已连接。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:已连接,
false:未连接。 |
## wifi.getSupportedFeatures<sup>7+</sup>
getSupportedFeatures(): number
查询设备支持的特性。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.Core
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| number | 支持的特性值。 |
**特性ID值枚举:**
| 枚举值 | 说明 |
| -------- | -------- |
| 0x0001 | 基础结构模式特性。 |
| 0x0002 | 5
GHz带宽特性。 |
| 0x0004 | GAS/ANQP特性。 |
| 0x0008 | Wifi-Direct特性。 |
| 0x0010 | Soft
AP特性。 |
| 0x0040 | Wi-Fi
AWare组网特性。 |
| 0x8000 | AP
STA共存特性。 |
| 0x8000000 | WPA3-Personal
SAE特性。 |
| 0x10000000 | WPA3-Enterprise
Suite-B |
| 0x20000000 | 增强开放特性。 |
## wifi.isFeatureSupported<sup>7+</sup>
isFeatureSupported(featureId: number): boolean
判断设备是否支持相关WLAN特性。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.Core
**参数:**
|
**参数名**
|
**类型**
| 必填 |
**说明**
|
| -------- | -------- | -------- | -------- |
| featureId | number | 是 | 特性ID值。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:支持,
false:不支持。 |
## wifi.getDeviceMacAddress<sup>7+</sup>
getDeviceMacAddress(): string[]
获取设备的MAC地址。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.GET_WIFI_LOCAL_MAC 和 ohos.permission.GET_WIFI_INFO,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| string[] | MAC地址。 |
## wifi.getIpInfo<sup>7+</sup>
getIpInfo(): IpInfo
获取IP信息。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
|
[
IpInfo
](
#ipinfo7
)
| IP信息。 |
## IpInfo<sup>7+</sup>
IP信息。
**系统能力:**
SystemCapability.Communication.WiFi.STA
|
**参数名**
|
**类型**
|
**可读**
|
**可写**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| ipAddress | number | 是 | 否 | IP地址。 |
| gateway | number | 是 | 否 | 网关。 |
| netmask | number | 是 | 否 | 掩码。 |
| primaryDns | number | 是 | 否 | 主DNS服务器IP地址。 |
| secondDns | number | 是 | 否 | 备DNS服务器IP地址。 |
| serverIp | number | 是 | 否 | DHCP服务端IP地址。 |
| leaseDuration | number | 是 | 否 | IP地址租用时长。 |
## wifi.getCountryCode<sup>7+</sup>
getCountryCode(): string
获取国家码信息。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.Core
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| string | 国家码。 |
## wifi.reassociate<sup>7+</sup>
reassociate(): boolean
重新关联网络。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。 |
## wifi.reconnect<sup>7+</sup>
reconnect(): boolean
重新连接网络。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。 |
## wifi.getDeviceConfigs<sup>7+</sup>
getDeviceConfigs():
Array
<
[WifiDeviceConfig](#wifideviceconfig)
>
获取网络配置。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION 和 ohos.permission.GET_WIFI_CONFIG
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
|
Array
<
[WifiDeviceConfig](#wifideviceconfig)
>
| 网络配置信息的数组。 |
## wifi.updateNetwork<sup>7+</sup>
updateNetwork(config: WifiDeviceConfig): number
更新网络配置。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.SET_WIFI_CONFIG
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiDeviceConfig
](
#wifideviceconfig
)
| 是 | WLAN配置信息。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| number | 返回更新的网络配置ID,如果值为-1表示更新失败。 |
## wifi.disableNetwork<sup>7+</sup>
disableNetwork(netId: number): boolean
去使能网络配置。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| netId | number | 是 | 网络配置ID。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。 |
## wifi.removeAllNetwork<sup>7+</sup>
removeAllNetwork(): boolean
移除所有网络配置。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。 |
## wifi.removeDevice<sup>7+</sup>
removeDevice(id: number): boolean
移除指定的网络配置。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| id | number | 是 | 网络配置ID。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。 |
## wifi.enableHotspot<sup>7+</sup>
enableHotspot(): boolean
使能热点。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。|
## wifi.disableHotspot<sup>7+</sup>
disableHotspot(): boolean
去使能热点。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。|
## wifi.isHotspotDualBandSupported<sup>7+</sup>
isHotspotDualBandSupported(): boolean
热点是否支持双频。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:支持,
false:不支持。|
## wifi.isHotspotActive<sup>7+</sup>
isHotspotActive(): boolean
热点是否已使能。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:已使能,
false:未使能。|
## wifi.setHotspotConfig<sup>7+</sup>
setHotspotConfig(config: HotspotConfig): boolean
设置热点配置信息。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
HotspotConfig
](
#hotspotconfig7
)
| 是 | 热点配置信息。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。 |
## HotspotConfig<sup>7+</sup>
热点配置信息。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
|
**参数名**
|
**类型**
|
**可读**
|
**可写**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
| securityType |
[
WifiSecurityType
](
#wifisecuritytype
)
| 是 | 否 | 加密类型。 |
| band | number | 是 | 否 | 热点的带宽。1: 2.4G, 2: 5G, 3: 双模频段 |
| preSharedKey | string | 是 | 否 | 热点的密钥。 |
| maxConn | number | 是 | 否 | 最大设备连接数。 |
## wifi.getHotspotConfig<sup>7+</sup>
getHotspotConfig(): HotspotConfig
获取热点配置信息。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
|
[
HotspotConfig
](
#hotspotconfig7
)
| 热点的配置信息。 |
## wifi.getStations<sup>7+</sup>
getStations():
Array
<
[StationInfo](#stationinfo7)
>
获取连接的设备。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION 和 ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
|
Array
<
[StationInfo](#stationinfo7)
>
| 连接的设备数组。 |
## StationInfo<sup>7+</sup>
接入的设备信息。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
|
**参数名**
|
**类型**
|
**可读**
|
**可写**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| name | string | 是 | 否 | 设备名称。 |
| macAddress | string | 是 | 否 | MAC地址。 |
| ipAddress | string | 是 | 否 | IP地址。 |
## wifi.getP2pLinkedInfo<sup>8+</sup>
getP2pLinkedInfo(): Promise
<
WifiP2pLinkedInfo
>
获取P2P连接信息,使用Promise异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
[WifiP2pLinkedInfo](#wifip2plinkedinfo8)
>
| Promise对象。表示P2P连接信息。 |
## WifiP2pLinkedInfo<sup>8+</sup>
提供WLAN连接的相关信息。
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 参数名 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- |
| connectState |
[
P2pConnectState
](
#p2pconnectstate8
)
| 是 | 否 | P2P连接状态。 |
| isGroupOwner | boolean | 是 | 否 | 是否是群主。 |
| groupOwnerAddr | string | 是 | 否 | 群组MAC地址。
## P2pConnectState<sup>8+</sup>
表示P2P连接状态的枚举。
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| DISCONNECTED | 0 | 断开状态。 |
| CONNECTED | 1 | 连接状态。 |
## wifi.getP2pLinkedInfo<sup>8+</sup>
getP2pLinkedInfo(callback: AsyncCallback
<
WifiP2pLinkedInfo
>
): void
获取P2P连接信息,使用callback异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
[WifiP2pLinkedInfo](#wifip2plinkedinfo8)
>
| 是 | 回调函数。当操作成功时,err为0,data表示P2P连接信息。如果error为非0,表示处理出现错误。 |
## wifi.getCurrentGroup<sup>8+</sup>
getCurrentGroup(): Promise
<
WifiP2pGroupInfo
>
获取P2P当前组信息,使用Promise异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
[WifiP2pGroupInfo](#wifip2pgroupinfo8)
>
| Promise对象。表示当前组信息。 |
## wifi.getCurrentGroup<sup>8+</sup>
getCurrentGroup(callback: AsyncCallback
<
WifiP2pGroupInfo
>
): void
获取P2P当前组信息,使用callback异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
[WifiP2pGroupInfo](#wifip2pgroupinfo8)
>
| 是 | 回调函数。当操作成功时,err为0,data表示当前组信息。如果error为非0,表示处理出现错误。 |
## wifi.getP2pPeerDevices<sup>8+</sup>
getP2pPeerDevices(): Promise
<
WifiP2pDevice[]
>
获取P2P对端设备列表信息,使用Promise异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
[WifiP2pDevice[]](#wifip2pdevice8)
>
| Promise对象。表示对端设备列表信息。 |
## wifi.getP2pPeerDevices<sup>8+</sup>
getP2pPeerDevices(callback: AsyncCallback
<
WifiP2pDevice[]
>
): void
获取P2P对端设备列表信息,使用callback异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
[WifiP2pDevice[]](#wifip2pdevice8)
>
| 是 | 回调函数。当操作成功时,err为0,data表示对端设备列表信息。如果error为非0,表示处理出现错误。 |
## WifiP2pDevice<sup>8+</sup>
表示P2P设备信息。
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 参数名 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- |
| deviceName | string | 是 | 否 | 设备名称。 |
| deviceAddress | string | 是 | 否 | 设备MAC地址。 |
| primaryDeviceType | string | 是 | 否 | 主设备类型。 |
| deviceStatus |
[
P2pDeviceStatus
](
#p2pdevicestatus8
)
| 是 | 否 | 设备状态。 |
| groupCapabilitys | number | 是 | 否 | 群组能力。 |
## P2pDeviceStatus<sup>8+</sup>
表示设备状态的枚举。
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| CONNECTED | 0 | 连接状态。 |
| INVITED | 1 | 邀请状态。 |
| FAILED | 2 | 失败状态。 |
| AVAILABLE | 3 | 可用状态。 |
| UNAVAILABLE | 4 | 不可用状态。 |
## wifi.getP2pLocalDevice<sup>9+</sup>
getP2pLocalDevice(): Promise
<
WifiP2pDevice
>
获取P2P本端设备信息,使用Promise异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
[WifiP2pDevice](#wifip2pdevice8)
>
| Promise对象。表示本端设备信息。 |
## wifi.getP2pLocalDevice<sup>9+</sup>
getP2pLocalDevice(callback: AsyncCallback
<
WifiP2pDevice
>
): void
获取P2P本端设备信息,使用callback异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
[WifiP2pDevice](#wifip2pdevice8)
>
| 是 | 回调函数。当操作成功时,err为0,data表示本端设备信息。如果error为非0,表示处理出现错误。 |
## wifi.createGroup<sup>8+</sup>
createGroup(config: WifiP2PConfig): boolean
创建群组。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
| 必填 |
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiP2PConfig
](
#wifip2pconfig8
)
| 是 | 群组配置信息。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | true:创建群组操作执行成功,
false:创建群组操作执行失败。 |
## WifiP2PConfig<sup>8+</sup>
表示P2P配置信息。
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 参数名 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- |
| deviceAddress | string | 是 | 否 | 设备地址。 |
| netId | number | 是 | 否 | 网络ID。创建群组时-1表示创建临时组,-2表示创建永久组。 |
| passphrase | string | 是 | 否 | 群组密钥。 |
| groupName | string | 是 | 否 | 群组名称。 |
| goBand |
[
GroupOwnerBand
](
#groupownerband8
)
| 是 | 否 | 群组带宽。 |
## GroupOwnerBand<sup>8+</sup>
表示群组带宽的枚举。
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| GO_BAND_AUTO | 0 | 自动模式。 |
| GO_BAND_2GHZ | 1 | 2GHZ。 |
| GO_BAND_5GHZ | 2 | 5GHZ。 |
## wifi.removeGroup<sup>8+</sup>
removeGroup(): boolean
移除群组。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | true:操作执行成功,
false:操作执行失败。 |
## wifi.p2pConnect<sup>8+</sup>
p2pConnect(config: WifiP2PConfig): boolean
执行P2P连接。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
| 必填 |
**说明**
|
| -------- | -------- | -------- | -------- |
| config |
[
WifiP2PConfig
](
#wifip2pconfig8
)
| 是 | 连接配置信息。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | true:操作执行成功,
false:操作执行失败。 |
**示例:**
```
js
import
wifi
from
'
@ohos.wifi
'
;
var
recvP2pConnectionChangeFunc
=
result
=>
{
console
.
info
(
"
p2p connection change receive event:
"
+
JSON
.
stringify
(
result
));
wifi
.
getP2pLinkedInfo
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
failed to get getP2pLinkedInfo:
'
+
JSON
.
stringify
(
err
));
return
;
}
console
.
info
(
"
get getP2pLinkedInfo:
"
+
JSON
.
stringify
(
data
));
});
}
wifi
.
on
(
"
p2pConnectionChange
"
,
recvP2pConnectionChangeFunc
);
var
recvP2pDeviceChangeFunc
=
result
=>
{
console
.
info
(
"
p2p device change receive event:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
"
p2pDeviceChange
"
,
recvP2pDeviceChangeFunc
);
var
recvP2pPeerDeviceChangeFunc
=
result
=>
{
console
.
info
(
"
p2p peer device change receive event:
"
+
JSON
.
stringify
(
result
));
wifi
.
getP2pPeerDevices
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
failed to get peer devices:
'
+
JSON
.
stringify
(
err
));
return
;
}
console
.
info
(
"
get peer devices:
"
+
JSON
.
stringify
(
data
));
var
len
=
Object
.
keys
(
data
).
length
;
for
(
var
i
=
0
;
i
<
len
;
++
i
)
{
if
(
data
[
i
].
deviceName
===
"
my_test_device
"
)
{
console
.
info
(
"
p2p connect to test device:
"
+
data
[
i
].
deviceAddress
);
var
config
=
{
"
deviceAddress
"
:
data
[
i
].
deviceAddress
,
"
netId
"
:
-
2
,
"
passphrase
"
:
""
,
"
groupName
"
:
""
,
"
goBand
"
:
0
,
}
wifi
.
p2pConnect
(
config
);
}
}
});
}
wifi
.
on
(
"
p2pPeerDeviceChange
"
,
recvP2pPeerDeviceChangeFunc
);
var
recvP2pPersistentGroupChangeFunc
=
()
=>
{
console
.
info
(
"
p2p persistent group change receive event
"
);
wifi
.
getCurrentGroup
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
failed to get current group:
'
+
JSON
.
stringify
(
err
));
return
;
}
console
.
info
(
"
get current group:
"
+
JSON
.
stringify
(
data
));
});
}
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
());
```
## wifi.p2pCancelConnect<sup>8+</sup>
p2pCancelConnect(): boolean
取消P2P连接。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | true:操作执行成功,
false:操作执行失败。 |
## wifi.startDiscoverDevices<sup>8+</sup>
startDiscoverDevices(): boolean
开始发现设备。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | true:操作执行成功,
false:操作执行失败。 |
## wifi.stopDiscoverDevices<sup>8+</sup>
stopDiscoverDevices(): boolean
停止发现设备。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | true:操作执行成功,操作执行失败。 |
## wifi.deletePersistentGroup<sup>8+</sup>
deletePersistentGroup(netId: number): boolean
删除永久组。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
| 必填 |
**说明**
|
| -------- | -------- | -------- | -------- |
| netId | number | 是 | 组的ID。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | true:操作执行成功,操作执行失败。 |
## wifi.getP2pGroups<sup>9+</sup>
getP2pGroups(): Promise
<
Array
<
WifiP2pGroupInfo
>>
获取创建的所有P2P群组信息,使用Promise异步回调。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
Array
<
[WifiP2pGroupInfo](#wifip2pgroupinfo8)
> >
| Promise对象。表示所有群组信息。 |
## WifiP2pGroupInfo<sup>8+</sup>
表示P2P群组相关信息。
**系统能力:**
SystemCapability.Communication.WiFi.P2P
| 参数名 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- |
| isP2pGo | boolean | 是 | 否 | 是否是群主。 |
| ownerInfo |
[
WifiP2pDevice
](
#wifip2pdevice8
)
| 是 | 否 | 群组的设备信息。 |
| passphrase | string | 是 | 否 | 群组密钥。 |
| interface | string | 是 | 否 | 接口名称。 |
| groupName | string | 是 | 否 | 群组名称。 |
| networkId | number | 是 | 否 | 网络ID。 |
| frequency | number | 是 | 否 | 群组的频率。 |
| clientDevices |
[
WifiP2pDevice[]
](
#wifip2pdevice8
)
| 是 | 否 | 接入的设备列表信息。 |
| goIpAddress | string | 是 | 否 | 群组IP地址。 |
## wifi.getP2pGroups<sup>9+</sup>
getP2pGroups(callback: AsyncCallback
<
Array
<
WifiP2pGroupInfo
>>
): void
获取创建的所有P2P群组信息,使用callback方式作为异步方法。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
Array
<
[WifiP2pGroupInfo](#wifip2pgroupinfo8)
>>
| 是 | 回调函数。当操作成功时,err为0,data表示所有群组信息。如果error为非0,表示处理出现错误。 |
## wifi.setDeviceName<sup>8+</sup>
setDeviceName(devName: string): boolean
设置设备名称。
**系统接口:**
此接口为系统接口。
**需要权限:**
ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| devName | string | 是 | 设备名称。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | true:操作成功,
false:操作失败。 |
## wifi.on('wifiStateChange')<sup>7+</sup>
on(type: "wifiStateChange", callback: Callback
<
number
>
): void
注册WLAN状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"wifiStateChange"字符串。 |
| callback | Callback
<
number
>
| 是 | 状态改变回调函数。 |
**状态改变事件的枚举:**
|
**枚举值**
|
**说明**
|
| -------- | -------- |
| 0 | 未激活。 |
| 1 | 已激活。 |
| 2 | 激活中。 |
| 3 | 去激活中。 |
## wifi.off('wifiStateChange')<sup>7+</sup>
off(type: "wifiStateChange", callback?: Callback
<
number
>
): void
取消注册WLAN状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"wifiStateChange"字符串。 |
| callback | Callback
<
number
>
| 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 |
**示例:**
```
js
import
wifi
from
'
@ohos.wifi
'
;
var
recvPowerNotifyFunc
=
result
=>
{
console
.
info
(
"
Receive power state change event:
"
+
result
);
}
// Register event
wifi
.
on
(
"
wifiStateChange
"
,
recvPowerNotifyFunc
);
// Unregister event
wifi
.
off
(
"
wifiStateChange
"
,
recvPowerNotifyFunc
);
```
## wifi.on('wifiConnectionChange')<sup>7+</sup>
on(type: "wifiConnectionChange", callback: Callback
<
number
>
): void
注册WLAN连接状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"wifiConnectionChange"字符串。 |
| callback | Callback
<
number
>
| 是 | 状态改变回调函数。 |
**连接状态改变事件的枚举:**
|
**枚举值**
|
**说明**
|
| -------- | -------- |
| 0 | 已断开。 |
| 1 | 已连接。 |
## wifi.off('wifiConnectionChange')<sup>7+</sup>
off(type: "wifiConnectionChange", callback?: Callback
<
number
>
): void
取消注册WLAN连接状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"wifiConnectionChange"字符串。 |
| callback | Callback
<
number
>
| 否 | 连接状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 |
## wifi.on('wifiScanStateChange')<sup>7+</sup>
on(type: "wifiScanStateChange", callback: Callback
<
number
>
): void
注册扫描状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"wifiScanStateChange"字符串。 |
| callback | Callback
<
number
>
| 是 | 状态改变回调函数。 |
**扫描状态改变事件的枚举:**
|
**枚举值**
|
**说明**
|
| -------- | -------- |
| 0 | 扫描失败。 |
| 1 | 扫描成功。 |
## wifi.off('wifiScanStateChange')<sup>7+</sup>
off(type: "wifiScanStateChange", callback?: Callback
<
number
>
): void
取消注册扫描状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"wifiScanStateChange"字符串。 |
| callback | Callback
<
number
>
| 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 |
## wifi.on('wifiRssiChange')<sup>7+</sup>
on(type: "wifiRssiChange", callback: Callback
<
number
>
): void
注册RSSI状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"wifiRssiChange"字符串。 |
| callback | Callback
<
number
>
| 是 | 状态改变回调函数,返回以dBm为单位的RSSI值。 |
## wifi.off('wifiRssiChange')<sup>7+</sup>
off(type: "wifiRssiChange", callback?: Callback
<
number
>
): void
取消注册RSSI状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.STA
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"wifiRssiChange"字符串。 |
| callback | Callback
<
number
>
| 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 |
## wifi.on('hotspotStateChange')<sup>7+</sup>
on(type: "hotspotStateChange", callback: Callback
<
number
>
): void
注册热点状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"hotspotStateChange"字符串。 |
| callback | Callback
<
number
>
| 是 | 状态改变回调函数。 |
**热点状态改变事件的枚举:**
|
**枚举值**
|
**说明**
|
| -------- | -------- |
| 0 | 未激活。 |
| 1 | 已激活。 |
| 2 | 激活中。 |
| 3 | 去激活中。 |
## wifi.off('hotspotStateChange')<sup>7+</sup>
off(type: "hotspotStateChange", callback?: Callback
<
number
>
): void
取消注册热点状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.AP.Core
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"hotspotStateChange"字符串。 |
| callback | Callback
<
number
>
| 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 |
## wifi.on('p2pStateChange')<sup>8+</sup>
on(type: "p2pStateChange", callback: Callback
<
number
>
): void
注册P2P开关状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pStateChange"字符串。 |
| callback | Callback
<
number
>
| 是 | 状态改变回调函数。 |
**P2P状态改变事件的枚举:**
|
**枚举值**
|
**说明**
|
| -------- | -------- |
| 1 | 空闲。 |
| 2 | 打开中。 |
| 3 | 已打开。 |
| 4 | 关闭中。 |
| 5 | 已关闭。 |
## wifi.off('p2pStateChange')<sup>8+</sup>
off(type: "p2pStateChange", callback?: Callback
<
number
>
): void
取消注册P2P开关状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pStateChange"字符串。 |
| callback | Callback
<
number
>
| 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 |
## wifi.on('p2pConnectionChange')
<sup>
8+
</sup>
on(type: "p2pConnectionChange", callback: Callback
<
WifiP2pLinkedInfo
>
): void
注册P2P连接状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pConnectionChange"字符串。 |
| callback | Callback
<
[WifiP2pLinkedInfo](#wifip2plinkedinfo8)
>
| 是 | 状态改变回调函数。 |
## wifi.off('p2pConnectionChange')<sup>8+</sup>
off(type: "p2pConnectionChange", callback?: Callback
<
WifiP2pLinkedInfo
>
): void
取消注册P2P连接状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pConnectionChange"字符串。 |
| callback | Callback
<
[WifiP2pLinkedInfo](#wifip2plinkedinfo8)
>
| 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 |
## wifi.on('p2pDeviceChange')<sup>8+</sup>
on(type: "p2pDeviceChange", callback: Callback
<
WifiP2pDevice
>
): void
注册P2P设备状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pDeviceChange"字符串。 |
| callback | Callback
<
[WifiP2pDevice](#wifip2pdevice8)
>
| 是 | 状态改变回调函数。 |
## wifi.off('p2pDeviceChange')<sup>8+</sup>
off(type: "p2pDeviceChange", callback?: Callback
<
WifiP2pDevice
>
): void
取消注册P2P设备状态改变事件。
**需要权限:**
ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pDeviceChange"字符串。 |
| callback | Callback
<
[WifiP2pDevice](#wifip2pdevice8)
>
| 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 |
## wifi.on('p2pPeerDeviceChange')<sup>8+</sup>
on(type: "p2pPeerDeviceChange", callback: Callback
<
WifiP2pDevice[]
>
): void
注册P2P对端设备状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO 和 ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pPeerDeviceChange"字符串。 |
| callback | Callback
<
[WifiP2pDevice[]](#wifip2pdevice8)
>
| 是 | 状态改变回调函数。 |
## wifi.off('p2pPeerDeviceChange')<sup>8+</sup>
off(type: "p2pPeerDeviceChange", callback?: Callback
<
WifiP2pDevice[]
>
): void
取消注册P2P对端设备状态改变事件。
**需要权限:**
ohos.permission.LOCATION
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pPeerDeviceChange"字符串。 |
| callback | Callback
<
[WifiP2pDevice[]](#wifip2pdevice8)
>
| 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 |
## wifi.on('p2pPersistentGroupChange')<sup>8+</sup>
on(type: "p2pPersistentGroupChange", callback: Callback
<
void
>
): void
注册P2P永久组状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pPersistentGroupChange"字符串。 |
| callback | Callback
<
void
>
| 是 | 状态改变回调函数。 |
## wifi.off('p2pPersistentGroupChange')<sup>8+</sup>
off(type: "p2pPersistentGroupChange", callback?: Callback
<
void
>
): void
取消注册P2P永久组状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pPersistentGroupChange"字符串。 |
| callback | Callback
<
void
>
| 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 |
## wifi.on('p2pDiscoveryChange')<sup>8+</sup>
on(type: "p2pDiscoveryChange", callback: Callback
<
number
>
): void
注册发现设备状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pDiscoveryChange"字符串。 |
| callback | Callback
<
number
>
| 是 | 状态改变回调函数。 |
**发现设备状态改变事件的枚举:**
|
**枚举值**
|
**说明**
|
| -------- | -------- |
| 0 | 初始状态。 |
| 1 | 发现成功。 |
## wifi.off('p2pDiscoveryChange')<sup>8+</sup>
off(type: "p2pDiscoveryChange", callback?: Callback
<
number
>
): void
取消注册发现设备状态改变事件。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.P2P
**参数:**
|
**参数名**
|
**类型**
|
**必填**
|
**说明**
|
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"p2pDiscoveryChange"字符串。 |
| callback | Callback
<
number
>
| 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 |
zh-cn/application-dev/reference/apis/js-apis-wifiManagerExt.md
0 → 100644
浏览文件 @
f66129ce
# WLAN扩展接口
该模块主要提供WLAN扩展接口,供非通用类型产品使用。
>  **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
该文档中的接口只供非通用类型产品使用,如路由器等,对于常规类型产品,不应该使用这些接口。
## 导入模块
```
js
import
wifiext
from
'
@ohos.wifiext
'
;
```
## wifiext.enableHotspot
enableHotspot(): boolean;
使能WLAN热点。
**需要权限:**
ohos.permission.MANAGE_WIFI_HOTSPOT_EXT
**系统能力:**
SystemCapability.Communication.WiFi.AP.Extension
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | 操作结果, true: 成功, false: 失败。 |
## wifiext.disableHotspot
disableHotspot(): boolean;
去使能WLAN热点。
**需要权限:**
ohos.permission.MANAGE_WIFI_HOTSPOT_EXT
**系统能力:**
SystemCapability.Communication.WiFi.AP.Extension
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | 操作结果, true: 成功, false: 失败。 |
## wifiext.getSupportedPowerModel
getSupportedPowerModel(): Promise
<
Array
<
PowerModel
>>
获取支持的功率模式,使用Promise异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.AP.Extension
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
Array
<
[PowerModel](#powermodel)
>>
| Promise对象。表示功率模式。 |
## PowerModel
表示功率模式的枚举。
**系统能力:**
SystemCapability.Communication.WiFi.AP.Extension
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| SLEEPING | 0 | 睡眠模式。 |
| GENERAL | 1 | 常规模式。 |
| THROUGH_WALL | 2 | 穿墙模式。 |
## wifiext.getSupportedPowerModel
getSupportedPowerModel(callback: AsyncCallback
<
Array
<
PowerModel
>>
): void
获取支持的功率模式,使用callback异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.AP.Extension
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
Array
<
[PowerModel](#powermodel)
>>
| 是 | 回调函数。当操作成功时,err为0,data表示支持的功率模式。如果error为非0,表示处理出现错误。 |
## wifiext.getPowerModel
getPowerModel(): Promise
<
PowerModel
>
获取功率模式,使用Promise异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.AP.Extension
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
[PowerModel](#powermodel)
>
| Promise对象。表示功率模式。 |
## wifiext.getPowerModel
getPowerModel(callback: AsyncCallback
<
PowerModel
>
): void
获取功率模式,使用callback异步回调。
**需要权限:**
ohos.permission.GET_WIFI_INFO
**系统能力:**
SystemCapability.Communication.WiFi.AP.Extension
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
[PowerModel](#powermodel)
>
| 是 | 回调函数。当操作成功时,err为0,data表示功率模式。如果error为非0,表示处理出现错误。 |
## wifiext.setPowerModel
setPowerModel(model: PowerModel) : boolean;
设置功率模式。
**需要权限:**
ohos.permission.MANAGE_WIFI_HOTSPOT_EXT
**系统能力:**
SystemCapability.Communication.WiFi.AP.Extension
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| model |
[
PowerModel
](
#powermodel
)
| 是 | 功率模式。 |
**返回值:**
|
**类型**
|
**说明**
|
| -------- | -------- |
| boolean | 操作结果, true: 成功, false: 失败。 |
zh-cn/application-dev/reference/apis/js-apis-wifiext.md
浏览文件 @
f66129ce
...
@@ -69,7 +69,7 @@ getSupportedPowerModel(): Promise<Array<PowerModel>>
...
@@ -69,7 +69,7 @@ getSupportedPowerModel(): Promise<Array<PowerModel>>
**系统能力:**
SystemCapability.Communication.WiFi.AP.Extension
**系统能力:**
SystemCapability.Communication.WiFi.AP.Extension
| 名称 |
默认
值 | 说明 |
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| -------- | -------- | -------- |
| SLEEPING | 0 | 睡眠模式。 |
| SLEEPING | 0 | 睡眠模式。 |
| GENERAL | 1 | 常规模式。 |
| GENERAL | 1 | 常规模式。 |
...
@@ -90,7 +90,7 @@ getSupportedPowerModel(callback: AsyncCallback<Array<PowerModel>>):
...
@@ -90,7 +90,7 @@ getSupportedPowerModel(callback: AsyncCallback<Array<PowerModel>>):
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
[PowerModel](#powermodel)
>
| 是 | 回调函数。当操作成功时,err为0,data表示支持的功率模式。如果error为非0,表示处理出现错误。 |
| callback | AsyncCallback
<
Array
<
[PowerModel](#powermodel)
>
>
| 是 | 回调函数。当操作成功时,err为0,data表示支持的功率模式。如果error为非0,表示处理出现错误。 |
## wifiext.getPowerModel
## wifiext.getPowerModel
...
@@ -141,7 +141,7 @@ setPowerModel(model: PowerModel) : boolean;
...
@@ -141,7 +141,7 @@ setPowerModel(model: PowerModel) : boolean;
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| model |
AsyncCallback
<
[PowerModel](#powermodel)
>
| 是 | 功率模式。 |
| model |
[
PowerModel
](
#powermodel
)
| 是 | 功率模式。 |
**返回值:**
**返回值:**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录