diff --git a/pages/index/index.vue b/pages/index/index.vue index 6f023fc9f9ae4242266eef73e09f224397143862..ea087bcfb08853f2e097621eec7c04116ac985e0 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 3306d9dc10adc8afd99acb4446a57f7155362ce8..ec5f6c9af046258e9d7009db6eb4a9eb6a3a9d63 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 cdfa968ce242ed2efe91ad7f6edb76a6ef4cee31..e7114f9fabf9f8b3106a41cc0caacfcb23121890 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