提交 12c6e1c2 编写于 作者: 打打卡夫卡's avatar 打打卡夫卡

修复部分告警信息

上级 2f2476d5
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
<button @tap="testGetBatteryInfo">获取电池电量</button> <button @tap="testGetBatteryInfo">获取电池电量</button>
<button @tap="testonMemoryWarning">开启内存不足告警监听</button> <button @tap="testonMemoryWarning">开启内存不足告警监听</button>
<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button> <button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
<button @tap="testStartWifi">startWifi</button>
<button @tap="testStartWifi">初始化wifi模块</button>
<button @tap="testGetWifiList">获取当前wifi列表</button> <button @tap="testGetWifiList">获取当前wifi列表</button>
<button @tap="testGetConnnectWifi">获取当前连接的wifi</button> <button @tap="testGetConnnectWifi">获取当前连接的wifi</button>
<button @tap="testStopWifi">stopWifi</button> <button @tap="testStopWifi">关闭wifi模块</button>
</view> </view>
</template> </template>
......
...@@ -45,8 +45,9 @@ class ScreenFileObserver extends FileObserver { ...@@ -45,8 +45,9 @@ class ScreenFileObserver extends FileObserver {
constructor(screenFile: string) { constructor(screenFile: string) {
super(screenFile) super(File(allScreen))
this.allScreen = new File(screenFile); this.allScreen = new File(screenFile);
} }
......
...@@ -59,7 +59,7 @@ class UniWifiInfo { ...@@ -59,7 +59,7 @@ class UniWifiInfo {
// 是否安全,微信的标准是是否需要密码。 来源:https://developers.weixin.qq.com/community/develop/doc/00064cf1790458db19cddf9925ac00?highLine=WifiInfo // 是否安全,微信的标准是是否需要密码。 来源:https://developers.weixin.qq.com/community/develop/doc/00064cf1790458db19cddf9925ac00?highLine=WifiInfo
this.secure = false; this.secure = false;
let capabilities = scanResult.capabilities.trim(); 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; this.secure = false;
} else { } else {
this.secure = true; this.secure = true;
...@@ -76,22 +76,20 @@ class UniWifiInfo { ...@@ -76,22 +76,20 @@ class UniWifiInfo {
if (connectInfo.getBSSID() == null) { if (connectInfo.getBSSID() == null) {
return return
} }
if (connectInfo != null) { if (connectInfo.getSSID() != null) {
if (connectInfo.getSSID() != null) { let s = connectInfo.getSSID();
let s = connectInfo.getSSID(); // 微信不带,这里需要去掉引号
// 微信不带,这里需要去掉引号 if (s.length > 2 && s.charAt(0) == '"' && s.charAt(s.length - 1) == '"') {
if (s.length > 2 && s.charAt(0) == '"' && s.charAt(s.length - 1) == '"') { s = s.substring(1, s.length - 1);
s = s.substring(1, s.length - 1);
}
this.SSID = s;
} }
this.SSID = s;
}
this.BSSID = connectInfo.getBSSID(); this.BSSID = connectInfo.getBSSID();
//Android返回的值是-100~0,而微信API规范是0~100,值越大信号越好,需要+100拉齐 //Android返回的值是-100~0,而微信API规范是0~100,值越大信号越好,需要+100拉齐
this.signalStrength = connectInfo.getRssi() + 100; this.signalStrength = connectInfo.getRssi() + 100;
this.frequency = connectInfo.getFrequency(); this.frequency = connectInfo.getFrequency();
}
} }
...@@ -147,10 +145,11 @@ class CustomBroadcastReceiver extends BroadcastReceiver { ...@@ -147,10 +145,11 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
setTimeout(function() { setTimeout(function() {
// BroadcastReceiver 中不能执行耗时任务,需要使用setTimeout // BroadcastReceiver 中不能执行耗时任务,需要使用setTimeout
console.log(Thread.currentThread().getName()) console.log(Thread.currentThread().getName())
// @ts-ignore
let winfo = this.mWifiManager!.getConnectionInfo(); let winfo = this.mWifiManager!.getConnectionInfo();
while (winfo.bssid == null) { while (winfo.bssid == null) {
Thread.sleep(1000) Thread.sleep(1000)
winfo = this.mWifiManager!!.getConnectionInfo(); winfo = this.mWifiManager!.getConnectionInfo();
} }
// 封装成数据对象 // 封装成数据对象
...@@ -160,7 +159,6 @@ class CustomBroadcastReceiver extends BroadcastReceiver { ...@@ -160,7 +159,6 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
errCode: 0, errCode: 0,
wifi: uniWifiInfo wifi: uniWifiInfo
} }
console.log("Global.onWifiConnectCallbackList == " + Global.onWifiConnectCallbackList.length);
// wifi状态可用了,分发当前的链接状态给已注册的监听集合 // wifi状态可用了,分发当前的链接状态给已注册的监听集合
for (let perCallback in Global.onWifiConnectCallbackList) { for (let perCallback in Global.onWifiConnectCallbackList) {
perCallback(res); perCallback(res);
...@@ -216,7 +214,7 @@ export function getWifiList(option: WifiOption) { ...@@ -216,7 +214,7 @@ export function getWifiList(option: WifiOption) {
// 还没调用startWifi 提示报错 // 还没调用startWifi 提示报错
var result = { var result = {
errCode: 12000, errCode: 12000,
errMsg: "getWifiList:fail fail:not init,you shall call startWifi first" errMsg: "getWifiList:fail:not invoke startWifi"
} }
option.fail?.(result) option.fail?.(result)
option.complete?.(result) option.complete?.(result)
...@@ -232,8 +230,8 @@ export function getWifiList(option: WifiOption) { ...@@ -232,8 +230,8 @@ export function getWifiList(option: WifiOption) {
errCode: 0, errCode: 0,
errMsg: "getWifiList:ok" errMsg: "getWifiList:ok"
} }
option?.success?.(ret) option.success?.(ret)
option?.complete?.(ret) option.complete?.(ret)
} }
...@@ -272,8 +270,9 @@ export function offGetWifiList(callback: UTSCallback) { ...@@ -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) { ...@@ -281,20 +280,20 @@ export function connectWifi(option: WifiOption) {
*/ */
export function startWifi(option: WifiOption) { export function startWifi(option: WifiOption) {
// 需要先开启wifi,才能使用后续的功能 // 需要先开启wifi,才能使用后续的功能
let requestCode = 1001; let requestCode = 1001;
let permissionWifi = arrayOf("android.permission.ACCESS_FINE_LOCATION"); 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) { if (ActivityCompat.checkSelfPermission(getUniActivity()!, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getUniActivity()!, permissionWifi, requestCode) ActivityCompat.requestPermissions(getUniActivity()!, permissionWifi, requestCode)
// 尚不具备权限,返回错误 // 尚不具备权限,返回错误
var result = {
errNo: 0,
errCode: 0,
errMsg: "startWifi:premission loss"
}
option.fail?.(result) option.fail?.(result)
option.complete?.(result) option.complete?.(result)
...@@ -311,16 +310,16 @@ export function startWifi(option: WifiOption) { ...@@ -311,16 +310,16 @@ export function startWifi(option: WifiOption) {
let filter = new IntentFilter() let filter = new IntentFilter()
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)
// @ts-ignore
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION) filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION)
// @ts-ignore
filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
getUniActivity()!.registerReceiver(Global.mReceiver, filter) getUniActivity()!.registerReceiver(Global.mReceiver, filter)
wifiManager.startScan() wifiManager.startScan()
var result = { result.errCode = 0
errNo: 0, result.errMsg = "startWifi:ok"
errCode: 0,
errMsg: "startWifi:ok"
}
option.success?.(result) option.success?.(result)
option.complete?.(result) option.complete?.(result)
...@@ -360,30 +359,30 @@ export function stopWifi(option: WifiOption) { ...@@ -360,30 +359,30 @@ export function stopWifi(option: WifiOption) {
*/ */
export function getConnectedWifi(option: GetConnectedWifiOptions) { 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) { if (Global.mReceiver == null) {
var result = { // 还没调用startWifi 提示报错
errNo: 12000, option.fail?.(res)
errCode: 12000, option.complete?.(res)
errMsg: "startWifi:not init"
}
option.fail?.(result)
option.complete?.(result)
return 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) { if (ActivityCompat.checkSelfPermission(getUniActivity()!, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// 尚不具备权限,返回错误 // 尚不具备权限,返回错误
res.errCode = 12001
res.errMsg = "getConnectedWifi:permission loss"
option.fail?.(res) option.fail?.(res)
option.complete?.(res) option.complete?.(res)
return; return;
...@@ -397,13 +396,14 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) { ...@@ -397,13 +396,14 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
Context.WIFI_SERVICE Context.WIFI_SERVICE
) as WifiManager; ) as WifiManager;
// 测试android 12上可以使用 // 测试android 12上可以使用
//@ts-ignore
const winfo = wm.getConnectionInfo(); const winfo = wm.getConnectionInfo();
// 封装成数据对象 // 封装成数据对象
WifiInfo.wrapConnectInfo(winfo); wifiInfo.wrapConnectInfo(winfo);
res.errCode = 0 res.errCode = 0
res.errMsg = "getConnectedWifi:ok" res.errMsg = "getConnectedWifi:ok"
res.wifi = WifiInfo; res.wifi = wifiInfo;
option.success?.(res) option.success?.(res)
option.complete?.(res) option.complete?.(res)
return return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册