Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
4fd9a53f
U
uni-api
项目概览
DCloud
/
uni-api
通知
670
Star
23
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
4fd9a53f
编写于
3月 28, 2023
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修补与微信wifi 部分api 差异
上级
0da6006d
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
55 addition
and
35 deletion
+55
-35
pages/index/index.vue
pages/index/index.vue
+8
-8
uni_modules/uni-wifi/utssdk/app-android/index.uts
uni_modules/uni-wifi/utssdk/app-android/index.uts
+47
-27
未找到文件。
pages/index/index.vue
浏览文件 @
4fd9a53f
...
...
@@ -43,14 +43,14 @@
uni
.
startWifi
({
success
:(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
uni
.
connectWifi
({
maunal
:
false
,
SSID
:
"
Xiaomi_20D0
"
,
password
:
"
BBB111
"
,
complete
:(
res
)
=>
{
console
.
log
(
res
);
}
});
//
uni.connectWifi({
//
maunal:false,
//
SSID:"Xiaomi_20D0",
//
password:"BBB111",
//
complete:(res)=>{
//
console.log(res);
//
}
//
});
},
fail
:(
res
)
=>
{
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:(
res
)
=>
{
...
...
uni_modules/uni-wifi/utssdk/app-android/index.uts
浏览文件 @
4fd9a53f
...
...
@@ -32,7 +32,9 @@ class Global {
// 扫描wifi结果
static scanList : AndroidUniWifiInfo[] = []
// 获取wifi列表监听
static getWifiListCallbackList : UTSCallback[] = []
static onGetWifiListCallback : UTSCallback | null = null
static supendGetWifiSuccess : ((res: UniWifiResult) => void) | null = null
static supendGetWifiComplete : ((res: UniWifiResult) => void) | null = null
// wifi链接监听
static onWifiConnectCallbackList : UTSCallback[] = []
static onWifiConnectWithPartialInfoCallbackList : UTSCallback[] = []
...
...
@@ -303,9 +305,23 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
if (intent.action == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) {
startWifiScaning = false;
let ret : UniWifiResult = {
errCode: 0,
errSubject: "uni-getWifiList",
errMsg: "getWifiList:ok"
}
if(Global.supendGetWifiSuccess != null){
Global.supendGetWifiSuccess?.(ret)
}
if(Global.supendGetWifiComplete != null){
Global.supendGetWifiComplete?.(ret)
}
// wifi 扫描结果回调
let results = this.mWifiManager!.scanResults;
if (results != null) {
Global.scanList = []
for (let scanResult in results) {
...
...
@@ -316,13 +332,16 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
}
// 挨个通知,所有的监听器
for (let perCallback in Global.getWifiListCallbackList) {
if(Global.onGetWifiListCallback != null){
const data = new JSONObject();
// let mainJsonStr = Gson().toJson(Global.scanList);
data["wifiList"] = Global.scanList
perCallback
(data);
Global.onGetWifiListCallback?.
(data);
}
// for (let perCallback in Global.onGetWifiListCallback) {
// const data = new JSONObject();
// data["wifiList"] = Global.scanList
// perCallback(data);
// }
}
...
...
@@ -378,10 +397,19 @@ export function startWifi(option : WifiOption) {
return;
}
// 初始化wifi 状态广播监听,后续所有的api,均基于此
if (Global.mReceiver == null) {
Global.mReceiver = new CustomBroadcastReceiver(wifiManager)
if(Global.mReceiver != null){
// 说明已经注册过了
result.errCode = 0
result.errMsg = "startWifi:ok"
option.success?.(result)
option.complete?.(result)
return
}
Global.mReceiver = new CustomBroadcastReceiver(wifiManager)
let filter = new IntentFilter()
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)
// @ts-ignore
...
...
@@ -401,7 +429,7 @@ export function startWifi(option : WifiOption) {
Global.mReceiver = null
Global.scanList = []
Global.
getWifiListCallbackList = []
Global.
onGetWifiListCallback = null
Global.onWifiConnectCallbackList = []
Global.onWifiConnectWithPartialInfoCallbackList = []
}
...
...
@@ -442,15 +470,13 @@ export function getWifiList(option : WifiOption) {
let wifiManager : WifiManager =
UTSAndroid.getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager
Global.supendGetWifiSuccess = option.success
Global.supendGetWifiComplete = option.complete
wifiManager.startScan()
let ret : UniWifiResult = {
errCode: 0,
errSubject: "uni-getWifiList",
errMsg: "getWifiList:ok"
}
option.success?.(ret)
option.complete?.(ret)
}
...
...
@@ -505,21 +531,14 @@ export function offWifiConnectedWithPartialInfo(callback? : UTSCallback) {
* 注册Wifi列表的监听事件
*/
export function onGetWifiList(callback : UTSCallback) {
Global.
getWifiListCallbackList.push(callback)
Global.
onGetWifiListCallback = callback
}
/**
* 取消注册Wifi列表的监听事件
*/
export function offGetWifiList(callback? : UTSCallback) {
if(callback == null){
Global.getWifiListCallbackList = []
return
}
let callbackIndex = Global.getWifiListCallbackList.indexOf(callback)
if (callbackIndex >= 0) {
Global.getWifiListCallbackList.splice(callbackIndex, 1);
}
Global.onGetWifiListCallback = null
}
...
...
@@ -737,9 +756,10 @@ export function stopWifi(option : WifiOption) {
//TODO handle the exception
}
Global.
getWifiListCallbackList = []
Global.
onGetWifiListCallback = null
Global.onWifiConnectWithPartialInfoCallbackList = []
Global.onWifiConnectCallbackList = []
Global.mReceiver = null
let result : UniWifiResult = {
errCode: 0,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录