diff --git a/pages/index/index.vue b/pages/index/index.vue index f64e148578503d6c5cbc4b004ab9acff01ac86a3..e62e0accda636f636264eb779c7cf90cf7a67f7f 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 0000000000000000000000000000000000000000..7ed4299898bcce833a4b7b6de7c4ef4d4ac999da --- /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 6a9dc9b93e727a8fcee3b0ae3a1fbdec468db084..43965368256327549f164ae4e3708355851b9eb8 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 +} +