Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

uni-app 获取手机连接的WiFi信息和wifi列表

 Share


Recommended Posts

最近在做个项目要求app获取当前连接的wifi信息和可用WiFi列表。

 

uni.getNetworkType({
    success: function (res) {
            console.log(res.networkType);
            if(res.networkType != "wifi"){
                uni.showToast({
                    icon:'none',duration:2000,
                    title:"未连接WIFI",
                })
            }else{
                //判断获取的WiFi是否为机型WiFi
                // 主窗体  
                var MainActivity = plus.android.runtimeMainActivity()  
                // 上下文  
                var Context = plus.android.importClass('android.content.Context')  
                // 导入WIFI管理 和 WIFI 信息 的class  
                plus.android.importClass("android.net.wifi.WifiManager")  
                plus.android.importClass("android.net.wifi.WifiInfo")  
                plus.android.importClass("android.net.wifi.ScanResult")  
                plus.android.importClass("java.util.ArrayList")  
                // 获取 WIFI 管理实例  
                var wifiManager = MainActivity.getSystemService(Context.WIFI_SERVICE)  

                // 获取当前连接WIFI的信息  
                var info = wifiManager.getConnectionInfo()  
                
                // 获取当前 WIFI 连接的 SSID (WIFI 名称)  
                var ssid = info.getSSID()  
                // 这里的 获取到的名称 是 带 双引号的 如 "cmcc"    
                // 所以我们这里处理一下  
                ssid = ssid.replace(/(^\"*)|(\"*$)/g, "")  
                console.log("info",ssid)
                var resultList = wifiManager.getScanResults(),  
                    len = resultList.size()  

                for(var i = 0; i < len; i++) {  
                    console.log(resultList.get(i).plusGetAttribute('SSID'))
            //将每一个ssid都添加到wifiArray数组中,用于绑定显示,根据个人业务取舍 wifiArray=[{name:WiFi的SSID}]

            let oneWiFi={
                name:resultList.get(i).plusGetAttribute('SSID')
            }
              this.wifiArray.push(oneWiFi);

                }
            }
        }
})

 

 

 

本文参考:https://blog.csdn.net/yjl23332/article/details/115666943

Link to post
Link to comment
Share on other sites

 Share

discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...