HomeDocs
跳到主要内容

connectWifi

简介

连接 Wi-Fi。若已知 Wi-Fi 信息,可以直接利用该接口连接(对于 Android 10 及以上版本,设备连接 wifi 之后,(受系统能力限制)其他进程无法使用当前连接的 wifi ;即连接上的 wifi 只对当前小程序有效,如果想要对整个系统生效,需要配置 maunal 来连接 wifi。)

入参

参数类型是否必填说明
SSIDStringtrueWi-Fi 名称 ssid
BSSIDStringfalseWi-Fi mac 地址
passwordStringtrueWi-Fi 密码
maunalBooleanfalse默认值 false, 拉起设置 Wi-Fi 页面手动连接

示例代码

Page({
data: {
wifiStatus: '',
connectWifi: '',
},
onReady() {
this.startWifi().then(() => {
this.connectWifi();
});
},
startWifi() {
const _that = this;
return new Promise((resolve, reject) => {
dlt.startWifi({
success: function (res) {
console.log('startWifi success', res);
_that.setData({
wifiStatus: 'startWifi',
});
resolve(res);
},
complete: function (res) {
console.log('startWifi complete', res);
},
fail: function (res) {
console.log('startWifi fail', res);
reject(res);
},
});
});
},
connectWifi() {
const _that = this;
dlt.connectWifi({
SSID: this.data.SSID,
BSSID: '',
password: this.data.password,
maunal: false,
success: function (res) {
console.log('connectWifi success', res);
_that.setData({
connectWifi: res,
});
},
complete: function (res) {
console.log('connectWifi complete', res);
},
fail: function (res) {
console.log('connectWifi fail', res);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.