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

修复部分告警信息

上级 2f2476d5
......@@ -9,11 +9,11 @@
<button @tap="testGetBatteryInfo">获取电池电量</button>
<button @tap="testonMemoryWarning">开启内存不足告警监听</button>
<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
<button @tap="testStartWifi">startWifi</button>
<button @tap="testStartWifi">初始化wifi模块</button>
<button @tap="testGetWifiList">获取当前wifi列表</button>
<button @tap="testGetConnnectWifi">获取当前连接的wifi</button>
<button @tap="testStopWifi">stopWifi</button>
<button @tap="testStopWifi">关闭wifi模块</button>
</view>
</template>
......
......@@ -45,8 +45,9 @@ class ScreenFileObserver extends FileObserver {
constructor(screenFile: string) {
super(screenFile)
super(File(allScreen))
this.allScreen = new File(screenFile);
}
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册