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 @@
...
@@ -43,14 +43,14 @@
uni
.
startWifi
({
uni
.
startWifi
({
success
:(
res
)
=>
{
success
:(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
uni
.
connectWifi
({
//
uni.connectWifi({
maunal
:
false
,
//
maunal:false,
SSID
:
"
Xiaomi_20D0
"
,
//
SSID:"Xiaomi_20D0",
password
:
"
BBB111
"
,
//
password:"BBB111",
complete
:(
res
)
=>
{
//
complete:(res)=>{
console
.
log
(
res
);
//
console.log(res);
}
//
}
});
//
});
},
fail
:(
res
)
=>
{
},
fail
:(
res
)
=>
{
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:(
res
)
=>
{
},
complete
:(
res
)
=>
{
...
...
uni_modules/uni-wifi/utssdk/app-android/index.uts
浏览文件 @
4fd9a53f
...
@@ -32,7 +32,9 @@ class Global {
...
@@ -32,7 +32,9 @@ class Global {
// 扫描wifi结果
// 扫描wifi结果
static scanList : AndroidUniWifiInfo[] = []
static scanList : AndroidUniWifiInfo[] = []
// 获取wifi列表监听
// 获取wifi列表监听
static getWifiListCallbackList : UTSCallback[] = []
static onGetWifiListCallback : UTSCallback | null = null
static supendGetWifiSuccess : ((res: UniWifiResult) => void) | null = null
static supendGetWifiComplete : ((res: UniWifiResult) => void) | null = null
// wifi链接监听
// wifi链接监听
static onWifiConnectCallbackList : UTSCallback[] = []
static onWifiConnectCallbackList : UTSCallback[] = []
static onWifiConnectWithPartialInfoCallbackList : UTSCallback[] = []
static onWifiConnectWithPartialInfoCallbackList : UTSCallback[] = []
...
@@ -303,9 +305,23 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
...
@@ -303,9 +305,23 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
if (intent.action == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) {
if (intent.action == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) {
startWifiScaning = false;
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 扫描结果回调
// wifi 扫描结果回调
let results = this.mWifiManager!.scanResults;
let results = this.mWifiManager!.scanResults;
if (results != null) {
if (results != null) {
Global.scanList = []
Global.scanList = []
for (let scanResult in results) {
for (let scanResult in results) {
...
@@ -316,13 +332,16 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
...
@@ -316,13 +332,16 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
}
}
// 挨个通知,所有的监听器
// 挨个通知,所有的监听器
for (let perCallback in Global.getWifiListCallbackList) {
if(Global.onGetWifiListCallback != null){
const data = new JSONObject();
const data = new JSONObject();
// let mainJsonStr = Gson().toJson(Global.scanList);
data["wifiList"] = 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,9 +397,18 @@ export function startWifi(option : WifiOption) {
...
@@ -378,9 +397,18 @@ export function startWifi(option : WifiOption) {
return;
return;
}
}
// 初始化wifi 状态广播监听,后续所有的api,均基于此
// 初始化wifi 状态广播监听,后续所有的api,均基于此
if (Global.mReceiver == null) {
if(Global.mReceiver != null){
Global.mReceiver = new CustomBroadcastReceiver(wifiManager)
// 说明已经注册过了
result.errCode = 0
result.errMsg = "startWifi:ok"
option.success?.(result)
option.complete?.(result)
return
}
}
Global.mReceiver = new CustomBroadcastReceiver(wifiManager)
let filter = new IntentFilter()
let filter = new IntentFilter()
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)
...
@@ -401,7 +429,7 @@ export function startWifi(option : WifiOption) {
...
@@ -401,7 +429,7 @@ export function startWifi(option : WifiOption) {
Global.mReceiver = null
Global.mReceiver = null
Global.scanList = []
Global.scanList = []
Global.
getWifiListCallbackList = []
Global.
onGetWifiListCallback = null
Global.onWifiConnectCallbackList = []
Global.onWifiConnectCallbackList = []
Global.onWifiConnectWithPartialInfoCallbackList = []
Global.onWifiConnectWithPartialInfoCallbackList = []
}
}
...
@@ -442,15 +470,13 @@ export function getWifiList(option : WifiOption) {
...
@@ -442,15 +470,13 @@ export function getWifiList(option : WifiOption) {
let wifiManager : WifiManager =
let wifiManager : WifiManager =
UTSAndroid.getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager
UTSAndroid.getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager
wifiManager.startScan()
let ret : UniWifiResult = {
errCode: 0,
Global.supendGetWifiSuccess = option.success
errSubject: "uni-getWifiList",
Global.supendGetWifiComplete = option.complete
errMsg: "getWifiList:ok"
}
wifiManager.startScan()
option.success?.(ret)
option.complete?.(ret)
}
}
...
@@ -505,21 +531,14 @@ export function offWifiConnectedWithPartialInfo(callback? : UTSCallback) {
...
@@ -505,21 +531,14 @@ export function offWifiConnectedWithPartialInfo(callback? : UTSCallback) {
* 注册Wifi列表的监听事件
* 注册Wifi列表的监听事件
*/
*/
export function onGetWifiList(callback : UTSCallback) {
export function onGetWifiList(callback : UTSCallback) {
Global.
getWifiListCallbackList.push(callback)
Global.
onGetWifiListCallback = callback
}
}
/**
/**
* 取消注册Wifi列表的监听事件
* 取消注册Wifi列表的监听事件
*/
*/
export function offGetWifiList(callback? : UTSCallback) {
export function offGetWifiList(callback? : UTSCallback) {
if(callback == null){
Global.onGetWifiListCallback = null
Global.getWifiListCallbackList = []
return
}
let callbackIndex = Global.getWifiListCallbackList.indexOf(callback)
if (callbackIndex >= 0) {
Global.getWifiListCallbackList.splice(callbackIndex, 1);
}
}
}
...
@@ -737,10 +756,11 @@ export function stopWifi(option : WifiOption) {
...
@@ -737,10 +756,11 @@ export function stopWifi(option : WifiOption) {
//TODO handle the exception
//TODO handle the exception
}
}
Global.
getWifiListCallbackList = []
Global.
onGetWifiListCallback = null
Global.onWifiConnectWithPartialInfoCallbackList = []
Global.onWifiConnectWithPartialInfoCallbackList = []
Global.onWifiConnectCallbackList = []
Global.onWifiConnectCallbackList = []
Global.mReceiver = null
let result : UniWifiResult = {
let result : UniWifiResult = {
errCode: 0,
errCode: 0,
errSubject: "uni-stopWifi",
errSubject: "uni-stopWifi",
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录