提交 fcdbe12a 编写于 作者: lizhongyi_'s avatar lizhongyi_

Merge branch 'dev' of https://gitcode.net/dcloud/uni-api into dev

...@@ -253,43 +253,37 @@ class CustomBroadcastReceiver extends BroadcastReceiver { ...@@ -253,43 +253,37 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
if (intent.action == WifiManager.WIFI_STATE_CHANGED_ACTION) { if (intent.action == WifiManager.WIFI_STATE_CHANGED_ACTION) {
let state = let state =
intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN) intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN)
if (state == WifiManager.WIFI_STATE_ENABLED) { if (state == WifiManager.WIFI_STATE_ENABLED) {
// 获取当前的connectInfo 并且进行数据封装 // 获取当前的connectInfo 并且进行数据封装
// let uniWifiInfo = new UniWifiInfo(null) let uniWifiInfo = new UniWifiInfo("","",false,0,0)
let uniWifiInfo : UniWifiInfo = {
SSID: "",
secure: false,
signalStrength: 0,
frequency: 0,
}
//做一些异步操作 //做一些异步操作
setTimeout(function () { setTimeout(function () {
// BroadcastReceiver 中不能执行耗时任务,需要使用setTimeout // BroadcastReceiver 中不能执行耗时任务,需要使用setTimeout
// @ts-ignore // @ts-ignore
let winfo = this.mWifiManager!.getConnectionInfo(); let winfo = this.mWifiManager!.getConnectionInfo();
while (winfo.bssid == null || zeroCountNum(winfo.bssid) > 4) { if(winfo != null && winfo.bssid != null && zeroCountNum(winfo.bssid) < 3){
Thread.sleep(1000) // 当前设备链接到了某个具体的wifi.封装成数据对象
winfo = this.mWifiManager!.getConnectionInfo(); uniWifiInfo = wrapUniWifiInfoFromConnectInfo(winfo)
} let res = new UniWifiResult(0,UniErrorSubject,'onWifiConnected:ok',uniWifiInfo)
// 封装成数据对象 // wifi状态可用了,分发当前的链接状态给已注册的监听集合
uniWifiInfo = wrapUniWifiInfoFromConnectInfo(winfo) for (let perCallback in Global.onWifiConnectCallbackList) {
perCallback(res);
let res = new UniWifiResult(0,UniErrorSubject,'onWifiConnected:ok',uniWifiInfo) }
// 封装仅SSID 数据对象
// wifi状态可用了,分发当前的链接状态给已注册的监听集合 let connectedWithPartialInfo = new UniWifiInfoWithPartialInfo(uniWifiInfo.SSID)
for (let perCallback in Global.onWifiConnectCallbackList) {
perCallback(res); for (let perCallback in Global.onWifiConnectWithPartialInfoCallbackList) {
} perCallback(connectedWithPartialInfo);
// 封装仅SSID 数据对象 }
let connectedWithPartialInfo = new UniWifiInfoWithPartialInfo(uniWifiInfo.SSID) } else {
// 开启了wifi 开关,但是尚未链接到某个具体的wifi
for (let perCallback in Global.onWifiConnectWithPartialInfoCallbackList) { }
perCallback(connectedWithPartialInfo);
}
}, 100); }, 100);
} }
...@@ -352,6 +346,7 @@ var startWifiScaning = false ...@@ -352,6 +346,7 @@ var startWifiScaning = false
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
export function startWifiImpl(option : WifiOption) { export function startWifiImpl(option : WifiOption) {
// 具备了权限,继续前进 // 具备了权限,继续前进
let wifiManager : WifiManager = let wifiManager : WifiManager =
UTSAndroid.getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager UTSAndroid.getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager
...@@ -668,11 +663,8 @@ export function connectWifi(option : WifiConnectOption) { ...@@ -668,11 +663,8 @@ export function connectWifi(option : WifiConnectOption) {
let manunalIntent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS); let manunalIntent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
UTSAndroid.getUniActivity()!.startActivity(manunalIntent); UTSAndroid.getUniActivity()!.startActivity(manunalIntent);
let result : UniWifiResult = {
errCode: 0, let result = new UniWifiResult(0,UniErrorSubject,"connectWifi:ok",null)
errMsg: "connectWifi:ok",
errSubject: "uni-connectWifi",
}
option.success?.(result) option.success?.(result)
option.complete?.(result) option.complete?.(result)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册