提交 2f2476d5 编写于 作者: 打打卡夫卡's avatar 打打卡夫卡

修改部分错误代码 符合 uniError要求

上级 5b805bb5
...@@ -9,10 +9,11 @@ ...@@ -9,10 +9,11 @@
<button @tap="testGetBatteryInfo">获取电池电量</button> <button @tap="testGetBatteryInfo">获取电池电量</button>
<button @tap="testonMemoryWarning">开启内存不足告警监听</button> <button @tap="testonMemoryWarning">开启内存不足告警监听</button>
<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button> <button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
<button @tap="testStartWifi">开启wifi功能</button> <button @tap="testStartWifi">startWifi</button>
<button @tap="testStopWifi">关闭wifi功能</button>
<button @tap="testGetWifiList">获取当前wifi列表</button> <button @tap="testGetWifiList">获取当前wifi列表</button>
<button @tap="testGetConnnectWifi">获取当前连接的wifi</button> <button @tap="testGetConnnectWifi">获取当前连接的wifi</button>
<button @tap="testStopWifi">stopWifi</button>
</view> </view>
</template> </template>
...@@ -48,12 +49,14 @@ ...@@ -48,12 +49,14 @@
uni.startWifi({ uni.startWifi({
success:(res)=> { success:(res)=> {
console.log("success: " + JSON.stringify(res)); console.log("success: " + JSON.stringify(res));
// wifi 开启成功后,注册wifi链接状态监听和wifi列表获取监听
uni.onGetWifiList(function(res){ uni.onGetWifiList(function(res){
console.log("onGetWifiList");
console.log(res); console.log(res);
}); });
uni.onWifiConnected(function(res){ uni.onWifiConnected(function(res){
console.log("11199"); console.log("onWifiConnected");
console.log("onWifiConnected = " + JSON.stringify(res)); console.log(res);
}); });
},fail:(res)=>{ },fail:(res)=>{
......
...@@ -201,18 +201,34 @@ class CustomBroadcastReceiver extends BroadcastReceiver { ...@@ -201,18 +201,34 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
} }
/************************* 下面是对外提供的函数 *************************/ /************************* 下面是对外提供的函数 *************************/
/** /**
* 获取wifi列表 * 获取wifi列表
*/ */
export function getWifiList(option: WifiOption) { 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 = let wifiManager: WifiManager =
getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager
wifiManager.startScan() wifiManager.startScan()
let ret = { let ret = {
errNo: 0,
errCode: 0, errCode: 0,
errMsg: "getWifiList:ok" errMsg: "getWifiList:ok"
} }
...@@ -264,6 +280,7 @@ export function connectWifi(option: WifiOption) { ...@@ -264,6 +280,7 @@ export function connectWifi(option: WifiOption) {
* 开启wifi * 开启wifi
*/ */
export function startWifi(option: WifiOption) { export function startWifi(option: WifiOption) {
// 需要先开启wifi,才能使用后续的功能 // 需要先开启wifi,才能使用后续的功能
let requestCode = 1001; let requestCode = 1001;
let permissionWifi = arrayOf("android.permission.ACCESS_FINE_LOCATION"); let permissionWifi = arrayOf("android.permission.ACCESS_FINE_LOCATION");
...@@ -343,7 +360,18 @@ export function stopWifi(option: WifiOption) { ...@@ -343,7 +360,18 @@ export function stopWifi(option: WifiOption) {
*/ */
export function getConnectedWifi(option: GetConnectedWifiOptions) { 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) let WifiInfo = new UniWifiInfo(null)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册