Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
910 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...