diff --git a/pages/index/index.vue b/pages/index/index.vue
index 28fdc873a652a74525b0512e92a30b3ae96ba910..6f023fc9f9ae4242266eef73e09f224397143862 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -9,10 +9,11 @@
-
-
+
+
+
@@ -48,12 +49,14 @@
uni.startWifi({
success:(res)=> {
console.log("success: " + JSON.stringify(res));
+ // wifi 开启成功后,注册wifi链接状态监听和wifi列表获取监听
uni.onGetWifiList(function(res){
+ console.log("onGetWifiList");
console.log(res);
});
uni.onWifiConnected(function(res){
- console.log("11199");
- console.log("onWifiConnected = " + JSON.stringify(res));
+ console.log("onWifiConnected");
+ console.log(res);
});
},fail:(res)=>{
diff --git a/uni_modules/uni-wifi/utssdk/app-android/index.uts b/uni_modules/uni-wifi/utssdk/app-android/index.uts
index 131f1f08cf2f7f013999186daf7e324584e15a20..cdfa968ce242ed2efe91ad7f6edb76a6ef4cee31 100644
--- a/uni_modules/uni-wifi/utssdk/app-android/index.uts
+++ b/uni_modules/uni-wifi/utssdk/app-android/index.uts
@@ -201,18 +201,34 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
}
+
+
/************************* 下面是对外提供的函数 *************************/
/**
* 获取wifi列表
*/
export function getWifiList(option: WifiOption) {
+
+
+
+ if (Global.mReceiver == null) {
+ // 还没调用startWifi 提示报错
+ var result = {
+ errCode: 12000,
+ errMsg: "getWifiList:fail fail:not init,you shall call startWifi first"
+ }
+ option.fail?.(result)
+ option.complete?.(result)
+
+ return
+ }
+
let wifiManager: WifiManager =
getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager
wifiManager.startScan()
let ret = {
- errNo: 0,
errCode: 0,
errMsg: "getWifiList:ok"
}
@@ -264,6 +280,7 @@ export function connectWifi(option: WifiOption) {
* 开启wifi
*/
export function startWifi(option: WifiOption) {
+
// 需要先开启wifi,才能使用后续的功能
let requestCode = 1001;
let permissionWifi = arrayOf("android.permission.ACCESS_FINE_LOCATION");
@@ -343,7 +360,18 @@ export function stopWifi(option: WifiOption) {
*/
export function getConnectedWifi(option: GetConnectedWifiOptions) {
- console.log(option);
+ if (Global.mReceiver == null) {
+ var result = {
+ errNo: 12000,
+ errCode: 12000,
+ errMsg: "startWifi:not init"
+ }
+ option.fail?.(result)
+ option.complete?.(result)
+
+ return
+ }
+
let WifiInfo = new UniWifiInfo(null)