From 2f2476d519a189abc12619d620f4eff7b4931225 Mon Sep 17 00:00:00 2001 From: duqingquan-jpc Date: Sat, 12 Nov 2022 16:21:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BB=A3=E7=A0=81=20=E7=AC=A6=E5=90=88=20uniError?= =?UTF-8?q?=E8=A6=81=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 11 ++++--- .../uni-wifi/utssdk/app-android/index.uts | 32 +++++++++++++++++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index 28fdc87..6f023fc 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -9,10 +9,11 @@ - - + + + @@ -48,12 +49,14 @@ uni.startWifi({ success:(res)=> { console.log("success: " + JSON.stringify(res)); + // wifi 开启成功后,注册wifi链接状态监听和wifi列表获取监听 uni.onGetWifiList(function(res){ + console.log("onGetWifiList"); console.log(res); }); uni.onWifiConnected(function(res){ - console.log("11199"); - console.log("onWifiConnected = " + JSON.stringify(res)); + console.log("onWifiConnected"); + console.log(res); }); },fail:(res)=>{ diff --git a/uni_modules/uni-wifi/utssdk/app-android/index.uts b/uni_modules/uni-wifi/utssdk/app-android/index.uts index 131f1f0..cdfa968 100644 --- a/uni_modules/uni-wifi/utssdk/app-android/index.uts +++ b/uni_modules/uni-wifi/utssdk/app-android/index.uts @@ -201,18 +201,34 @@ class CustomBroadcastReceiver extends BroadcastReceiver { } + + /************************* 下面是对外提供的函数 *************************/ /** * 获取wifi列表 */ export function getWifiList(option: WifiOption) { + + + + if (Global.mReceiver == null) { + // 还没调用startWifi 提示报错 + var result = { + errCode: 12000, + errMsg: "getWifiList:fail fail:not init,you shall call startWifi first" + } + option.fail?.(result) + option.complete?.(result) + + return + } + let wifiManager: WifiManager = getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager wifiManager.startScan() let ret = { - errNo: 0, errCode: 0, errMsg: "getWifiList:ok" } @@ -264,6 +280,7 @@ export function connectWifi(option: WifiOption) { * 开启wifi */ export function startWifi(option: WifiOption) { + // 需要先开启wifi,才能使用后续的功能 let requestCode = 1001; let permissionWifi = arrayOf("android.permission.ACCESS_FINE_LOCATION"); @@ -343,7 +360,18 @@ export function stopWifi(option: WifiOption) { */ export function getConnectedWifi(option: GetConnectedWifiOptions) { - console.log(option); + if (Global.mReceiver == null) { + var result = { + errNo: 12000, + errCode: 12000, + errMsg: "startWifi:not init" + } + option.fail?.(result) + option.complete?.(result) + + return + } + let WifiInfo = new UniWifiInfo(null) -- GitLab