From 9377f404a1f379311f407007f0a891eaf5d58d45 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Fri, 4 Nov 2022 20:09:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84wifi=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 5 ++++- uni_modules/uni-wifi/utssdk/app-android/index.uts | 14 +++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index 4f9bdff..5924776 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -34,7 +34,10 @@ }, testGetConnnectWifi(){ uni.getConnectedWifi({ - partialInfo:false + partialInfo:false, + complete:(res)=>{ + console.log(res); + } }); }, testStartWifi(){ diff --git a/uni_modules/uni-wifi/utssdk/app-android/index.uts b/uni_modules/uni-wifi/utssdk/app-android/index.uts index 7b17729..3a9a304 100644 --- a/uni_modules/uni-wifi/utssdk/app-android/index.uts +++ b/uni_modules/uni-wifi/utssdk/app-android/index.uts @@ -249,7 +249,7 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) { let res = { errMsg: 'getConnectedWifi:fail. please check permission about location or enable wifi or connect wifi', errCode: -1, - WifiInfo: WifiInfo + wifi: WifiInfo } @@ -272,14 +272,13 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) { Context.WIFI_SERVICE ) as WifiManager; const winfo = wm.getConnectionInfo(); // TODO 这个方法在Android12标记为已废弃。替代方法还没找到 - console.log(winfo); if (winfo != null) { let s = winfo.getSSID(); - console.log(s); // TODO 注意此值带着双引号。需要验证微信的值是否带双引号,如微信不带,这里需要去掉 - // if (s.length() > 2 && s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') { - // s = s.substring(1, s.length() - 1); - // } - // console.log("new s:",s); + + // 微信不带,这里需要去掉 + if (s.length > 2 && s.charAt(0) == '"' && s.charAt(s.length - 1) == '"') { + s = s.substring(1, s.length - 1); + } WifiInfo.SSID = s; WifiInfo.BSSID = winfo.getBSSID(); WifiInfo.signalStrength = winfo.getRssi()+100; //Android返回的值是-100~0,而微信API规范是0~100,值越大信号越好,需要+100拉齐 @@ -287,6 +286,7 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) { // WifiInfo.macAddress = winfo.getMacAddress(); //注意此代码涉及隐私,首先需要配置权限,没有权限会返回"02:00:00:00:00:00";然后需要在隐私协议中声明用途。如不需要,可注释掉本行 res.errCode = 0 res.errMsg = "getConnectedWifi:ok" + res.wifi = WifiInfo; option.success?.(res) option.complete?.(res) return -- GitLab