提交 bf7484bc 编写于 作者: W wanganxp

提交dev分支,补充onmemorywarning和getConnectwifi,还有不少TODO

上级 03f385f5
......@@ -5,16 +5,16 @@
<text class="title">{{title}}</text>
</view>
<button @tap="testScreenShotListen">开启截屏监听</button>
<button @tap="testScreenShotOff">关闭截屏监听</button>
<button @tap="testGetBatteryInfo">获取电池电量</button>
<button @tap="testScreenShotOff">关闭截屏监听</button>
<button @tap="testGetBatteryInfo">获取电池电量</button>
<button @tap="testonMemoryWarning">开启内存不足告警监听</button>
<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
<button @tap="testGetConnectedWifi">获取当前wifi信息</button>
</view>
</template>
<script>
import getBatteryInfo from "@/uni_modules/uni-getbatteryinfo";
export default {
data() {
return {
......@@ -25,7 +25,23 @@
},
methods: {
testGetConnectedWifi() {
uni.getConnectedWifi({
success(res) {
console.log(res);
}
})
},
testonMemoryWarning() {
uni.onMemoryWarning(function(res) {
console.log(res);
})
},
testoffMemoryWarning(){
uni.offMemoryWarning(function(res) {
console.log(res);
})
},
testScreenShotListen() {
var that = this;
uni.onUserCaptureScreen(function(res) {
......@@ -67,7 +83,6 @@
}
},
testScreenShotOff() {
var that = this;
uni.offUserCaptureScreen(function(res) {
console.log(res);
});
......@@ -78,7 +93,6 @@
})
},
testGetBatteryInfo() {
var that = this;
uni.getBatteryInfo({
success(res) {
uni.showToast({
......
{
"id": "uni-memorywarning",
"displayName": "uni-MemoryWarning",
"version": "1.0.0",
"description": "内存不足告警",
"keywords": [
"onMemoryWarning"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.0"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"uni-ext-api":{
"uni": {
"onMemoryWarning": "onMemoryWarning"
},
"mp-weixin":false,
"mp-alipay":false,
"mp-baidu":false,
"mp-qq":false,
"mp-kuaishou":false,
"mp-jd":false
},
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "n",
"vue3": "y"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# wa-onMemoryWarning
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
\ No newline at end of file
import { onAppTrimMemory } from "io.dcloud.uts.android";
export function onMemoryWarning(callback: (res:Number) => void) {
// console.log("here");
onAppTrimMemory((level:Number) => {
console.log(level);
callback(level);
});
// return ;
}
export function offMemoryWarning(success: (res: any) => void) {
// TODO 没有实现卸载监听
let ret = {
code:0
}
success(ret);
}
{
"id": "uni-wifi",
"displayName": "uni-wifi",
"version": "1.0.0",
"description": "wifi管理",
"keywords": [
"wifi"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"uni-ext-api":{
"uni": {
"getConnectedWifi": "getConnectedWifi",
"startWifi": "startWifi"
}
},
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# wa-wifi
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
\ No newline at end of file
import Context from "android.content.Context";
import { getAppContext } from "io.dcloud.uts.android";
import WifiManager from "android.net.wifi.WifiManager";
type GetConnectedWifiOptions = {
success?: (res: UTSJSONObject) => void
fail?: (res: UTSJSONObject) => void
complete?: (res: UTSJSONObject) => void
}
export function startWifi() { //TODO
}
export function getConnectedWifi(options: GetConnectedWifiOptions) {
let WifiInfo = {
SSID : "",
BSSID : "",
// secure : Boolean, // TODO 此值是微信的规范,Android原生并没有。不确定其的逻辑,需要在微信环境做各种测试才能验证
signalStrength : 0,
frequency : 0,
// macAddress : ""
}
let res = {
errMsg: 'getConnectedWifi:fail. please check permission about location or enable wifi or connect wifi',
errCode: -1,
WifiInfo: WifiInfo
}
// TODO 应该try catch一下,把系统的错误码给返回来,然后和微信的错误码拉齐
// 需要先校验权限,没有位置权限无法获取wifi
const context = getAppContext();
if (context != null) {
const wm = context.getSystemService(
Context.WIFI_SERVICE
) as WifiManager;
const winfo = wm.getConnectionInfo(); // TODO 这个方法在Android12标记为已废弃。替代方法还没找到
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);
WifiInfo.SSID = s;
WifiInfo.BSSID = winfo.getBSSID();
WifiInfo.signalStrength = winfo.getRssi()+100; //Android返回的值是-100~0,而微信API规范是0~100,值越大信号越好,需要+100拉齐
WifiInfo.frequency = winfo.getFrequency();
// WifiInfo.macAddress = winfo.getMacAddress(); //注意此代码涉及隐私,首先需要配置权限,没有权限会返回"02:00:00:00:00:00";然后需要在隐私协议中声明用途。如不需要,可注释掉本行
res.errCode = 0
res.errMsg = "getConnectedWifi:ok"
options.success?.(res)
options.complete?.(res)
return
}
}
options.fail?.(res)
options.complete?.(res)
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册