From 419173724e9e108c510f83cb549a6c4843035680 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Wed, 29 Mar 2023 18:31:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20getWifilIST=20=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=A4=9A=E6=AC=A1=E5=9B=9E=E8=B0=83=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 39 ++++++++++--------- .../uni-wifi/utssdk/app-android/config.json | 3 ++ .../uni-wifi/utssdk/app-android/index.uts | 38 ++++++++++-------- 3 files changed, 45 insertions(+), 35 deletions(-) create mode 100644 uni_modules/uni-wifi/utssdk/app-android/config.json diff --git a/pages/index/index.vue b/pages/index/index.vue index f64e148..e62e0ac 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -31,7 +31,8 @@ memListener:null, setUserCaptureScreenFlag: false, setUserCaptureScreenText: '禁止截屏', - permissionGranted: false + permissionGranted: false, + id:0 } }, onLoad() { @@ -45,23 +46,25 @@ console.log(res) }, onGetWifiList2_assert0() { - const fn = res => console.log('onGetWifiList res', res) - uni.startWifi({success(){ - uni.onGetWifiList(fn) - uni.getWifiList({ - success() { - console.log('getWifiList success'); - uni.offGetWifiList(fn) - uni.stopWifi({ - success() {}, - fail(e) { - console.log("stopWifi fail: ",e); - } - }) - } - }) - }}) - }, + console.log(" ------- onGetWifiList2_assert0: ",this.id); + const fn = res => console.log('onGetWifiList res', res) + uni.startWifi({success(){ + uni.onGetWifiList(fn) + uni.getWifiList({ + success() { + console.log('getWifiList success'); + uni.offGetWifiList(fn) + uni.stopWifi({ + success() {}, + fail(e) { + console.log("stopWifi fail: ",e); + } + }) + } + }) + }}) + this.id++ + }, testConnnectWifi(){ diff --git a/uni_modules/uni-wifi/utssdk/app-android/config.json b/uni_modules/uni-wifi/utssdk/app-android/config.json new file mode 100644 index 0000000..7ed4299 --- /dev/null +++ b/uni_modules/uni-wifi/utssdk/app-android/config.json @@ -0,0 +1,3 @@ +{ + "minSdkVersion": "19" +} \ No newline at end of file diff --git a/uni_modules/uni-wifi/utssdk/app-android/index.uts b/uni_modules/uni-wifi/utssdk/app-android/index.uts index 6a9dc9b..4396536 100644 --- a/uni_modules/uni-wifi/utssdk/app-android/index.uts +++ b/uni_modules/uni-wifi/utssdk/app-android/index.uts @@ -306,17 +306,8 @@ class CustomBroadcastReceiver extends BroadcastReceiver { if (intent.action == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) { startWifiScaning = false; - let ret : UniWifiResult = { - errCode: 0, - errSubject: "uni-getWifiList", - errMsg: "getWifiList:ok" - } - if(Global.supendGetWifiSuccess != null){ - Global.supendGetWifiSuccess?.(ret) - } - if(Global.supendGetWifiComplete != null){ - Global.supendGetWifiComplete?.(ret) - } + + // wifi 扫描结果回调 let results = this.mWifiManager!.scanResults; @@ -336,15 +327,27 @@ class CustomBroadcastReceiver extends BroadcastReceiver { const data = new JSONObject(); data["wifiList"] = Global.scanList Global.onGetWifiListCallback?.(data); + /** + * 确保onGetWifiList 只会被执行一次 + */ + Global.onGetWifiListCallback = null } - // for (let perCallback in Global.onGetWifiListCallback) { - // const data = new JSONObject(); - // data["wifiList"] = Global.scanList - // perCallback(data); - // } } + let ret : UniWifiResult = { + errCode: 0, + errSubject: "uni-getWifiList", + errMsg: "getWifiList:ok" + } + if(Global.supendGetWifiSuccess != null){ + Global.supendGetWifiSuccess?.(ret) + Global.supendGetWifiSuccess = null + } + if(Global.supendGetWifiComplete != null){ + Global.supendGetWifiComplete?.(ret) + Global.supendGetWifiComplete = null + } } } @@ -845,4 +848,5 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) { } option.fail?.(res) option.complete?.(res) -} \ No newline at end of file +} + -- GitLab