How can I get WiFi Network information (SSID) in a Phonegap app?

拥有回忆 提交于 2019-11-27 14:05:07

问题


I am making a Phonegap app. My requirement is to show different views to users depending on whether they are using a home network or a public network. Is there any plugin or any other way that can help to get the connected network information. (Network SSID).

Thanks.


回答1:


There is this plugin for Android and iOS :

cordova plugin add wifiwizard

If you want to get the current SSID of the network you are connected to:

function ssidHandler(s) {
    alert("Current SSID"+s);
}

function fail(e) {
    alert("Failed"+e);
}

function getCurrentSSID() {
    WifiWizard.getCurrentSSID(ssidHandler, fail);
}

If you want to get the list of SSID you have configured before :

function listHandler(a) {
    alert(a);
}

function getWifiList() {
   WifiWizard.listNetworks(listHandler, fail);
}

If you want to return a complete scan result :

function listHandler2(a) {
    alert(JSON.stringify(a));
}

function getScanResult() {
    WifiWizard.getScanResults(listHandler2, fail);
 }

To test:

<button onclick="getCurrentSSID()">Get Current SSID</button> 
<button onclick="getWifiList()">Get configured SSID list</button> 
<button onclick="getScanResult()">Get Scan result</button> 

Please see what you exactly need to get work from the list of the functions that the link I provided is offering and if you are encountering issues, reply.




回答2:


While WifiWizard is great, it seems that it's no longer being maintained on GitHub.

As a replacement, you can use WifiWizard2 (link) which is under active development, as supports the same methods:

cordova plugin add https://github.com/tripflex/WifiWizard2.git

WifiWizard2.getConnectedSSID(success, fail)

WifiWizard2.getConnectedBSSID(success, fail)

WifiWizard2.scan([options], success, fail)

WifiWizard2 also supports both Android and iOS.


However, if like me you also need to use the device's Hotspot or Wifi Tetheting on cordova, I recommend the cordova-hotspot-plugin instead.

The project is unfortunately discontinued, but for older Android API levels, still seems to work.

This plugin supports a myriad of methods, full list available here.



来源:https://stackoverflow.com/questions/31182536/how-can-i-get-wifi-network-information-ssid-in-a-phonegap-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!