From 12c6e1c282d6d7e1bd8df83cfb02e8c4e75f1259 Mon Sep 17 00:00:00 2001 From: duqingquan-jpc Date: Sat, 12 Nov 2022 19:32:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 4 +- .../utssdk/app-android/index.uts | 3 +- .../uni-wifi/utssdk/app-android/index.uts | 100 +++++++++--------- 3 files changed, 54 insertions(+), 53 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index 6f023fc..ea087bc 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -9,11 +9,11 @@ - + - + diff --git a/uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts b/uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts index 3306d9d..ec5f6c9 100644 --- a/uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts +++ b/uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts @@ -45,8 +45,9 @@ class ScreenFileObserver extends FileObserver { constructor(screenFile: string) { - super(screenFile) + super(File(allScreen)) this.allScreen = new File(screenFile); + } diff --git a/uni_modules/uni-wifi/utssdk/app-android/index.uts b/uni_modules/uni-wifi/utssdk/app-android/index.uts index cdfa968..e7114f9 100644 --- a/uni_modules/uni-wifi/utssdk/app-android/index.uts +++ b/uni_modules/uni-wifi/utssdk/app-android/index.uts @@ -59,7 +59,7 @@ class UniWifiInfo { // 是否安全,微信的标准是是否需要密码。 来源:https://developers.weixin.qq.com/community/develop/doc/00064cf1790458db19cddf9925ac00?highLine=WifiInfo this.secure = false; let capabilities = scanResult.capabilities.trim(); - if (capabilities != null && (capabilities.equals(Global.WIFI_AUTH_OPEN) || capabilities.equals(Global.WIFI_AUTH_ROAM))) { + if ((capabilities.equals(Global.WIFI_AUTH_OPEN) || capabilities.equals(Global.WIFI_AUTH_ROAM))) { this.secure = false; } else { this.secure = true; @@ -76,22 +76,20 @@ class UniWifiInfo { if (connectInfo.getBSSID() == null) { return } - if (connectInfo != null) { - if (connectInfo.getSSID() != null) { - let s = connectInfo.getSSID(); - // 微信不带,这里需要去掉引号 - if (s.length > 2 && s.charAt(0) == '"' && s.charAt(s.length - 1) == '"') { - s = s.substring(1, s.length - 1); - } - this.SSID = s; + if (connectInfo.getSSID() != null) { + let s = connectInfo.getSSID(); + // 微信不带,这里需要去掉引号 + if (s.length > 2 && s.charAt(0) == '"' && s.charAt(s.length - 1) == '"') { + s = s.substring(1, s.length - 1); } + this.SSID = s; + } - this.BSSID = connectInfo.getBSSID(); - //Android返回的值是-100~0,而微信API规范是0~100,值越大信号越好,需要+100拉齐 - this.signalStrength = connectInfo.getRssi() + 100; - this.frequency = connectInfo.getFrequency(); + this.BSSID = connectInfo.getBSSID(); + //Android返回的值是-100~0,而微信API规范是0~100,值越大信号越好,需要+100拉齐 + this.signalStrength = connectInfo.getRssi() + 100; + this.frequency = connectInfo.getFrequency(); - } } @@ -147,10 +145,11 @@ class CustomBroadcastReceiver extends BroadcastReceiver { setTimeout(function() { // BroadcastReceiver 中不能执行耗时任务,需要使用setTimeout console.log(Thread.currentThread().getName()) + // @ts-ignore let winfo = this.mWifiManager!.getConnectionInfo(); while (winfo.bssid == null) { Thread.sleep(1000) - winfo = this.mWifiManager!!.getConnectionInfo(); + winfo = this.mWifiManager!.getConnectionInfo(); } // 封装成数据对象 @@ -160,7 +159,6 @@ class CustomBroadcastReceiver extends BroadcastReceiver { errCode: 0, wifi: uniWifiInfo } - console.log("Global.onWifiConnectCallbackList == " + Global.onWifiConnectCallbackList.length); // wifi状态可用了,分发当前的链接状态给已注册的监听集合 for (let perCallback in Global.onWifiConnectCallbackList) { perCallback(res); @@ -216,7 +214,7 @@ export function getWifiList(option: WifiOption) { // 还没调用startWifi 提示报错 var result = { errCode: 12000, - errMsg: "getWifiList:fail fail:not init,you shall call startWifi first" + errMsg: "getWifiList:fail:not invoke startWifi" } option.fail?.(result) option.complete?.(result) @@ -232,8 +230,8 @@ export function getWifiList(option: WifiOption) { errCode: 0, errMsg: "getWifiList:ok" } - option?.success?.(ret) - option?.complete?.(ret) + option.success?.(ret) + option.complete?.(ret) } @@ -272,8 +270,9 @@ export function offGetWifiList(callback: UTSCallback) { } } -export function connectWifi(option: WifiOption) { - +export function connectWifi(_option: WifiOption) { + // todo + console.log(_option) } /** @@ -281,20 +280,20 @@ export function connectWifi(option: WifiOption) { */ export function startWifi(option: WifiOption) { + + // 需要先开启wifi,才能使用后续的功能 let requestCode = 1001; let permissionWifi = arrayOf("android.permission.ACCESS_FINE_LOCATION"); - + var result = { + errCode: 12001, + errMsg: "startWifi:premission loss" + } // 检查权限 if (ActivityCompat.checkSelfPermission(getUniActivity()!, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(getUniActivity()!, permissionWifi, requestCode) // 尚不具备权限,返回错误 - var result = { - errNo: 0, - errCode: 0, - errMsg: "startWifi:premission loss" - } option.fail?.(result) option.complete?.(result) @@ -311,16 +310,16 @@ export function startWifi(option: WifiOption) { let filter = new IntentFilter() filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) + // @ts-ignore filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION) + // @ts-ignore filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); getUniActivity()!.registerReceiver(Global.mReceiver, filter) wifiManager.startScan() - var result = { - errNo: 0, - errCode: 0, - errMsg: "startWifi:ok" - } + result.errCode = 0 + result.errMsg = "startWifi:ok" + option.success?.(result) option.complete?.(result) @@ -360,30 +359,30 @@ export function stopWifi(option: WifiOption) { */ export function getConnectedWifi(option: GetConnectedWifiOptions) { + let wifiInfo = new UniWifiInfo(null) + + var res = { + errCode: 12000, + errMsg: "getConnectedWifi:fail:not invoke startWifi", + wifi:wifiInfo + } + if (Global.mReceiver == null) { - var result = { - errNo: 12000, - errCode: 12000, - errMsg: "startWifi:not init" - } - option.fail?.(result) - option.complete?.(result) + // 还没调用startWifi 提示报错 + option.fail?.(res) + option.complete?.(res) return } - let WifiInfo = new UniWifiInfo(null) - - let res = { - errMsg: 'getConnectedWifi:fail. please check permission about location or enable wifi or connect wifi', - errCode: -1, - wifi: WifiInfo - } - - + + if (ActivityCompat.checkSelfPermission(getUniActivity()!, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // 尚不具备权限,返回错误 + res.errCode = 12001 + res.errMsg = "getConnectedWifi:permission loss" + option.fail?.(res) option.complete?.(res) return; @@ -397,13 +396,14 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) { Context.WIFI_SERVICE ) as WifiManager; // 测试android 12上可以使用 + //@ts-ignore const winfo = wm.getConnectionInfo(); // 封装成数据对象 - WifiInfo.wrapConnectInfo(winfo); + wifiInfo.wrapConnectInfo(winfo); res.errCode = 0 res.errMsg = "getConnectedWifi:ok" - res.wifi = WifiInfo; + res.wifi = wifiInfo; option.success?.(res) option.complete?.(res) return -- GitLab