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

18,511

Solution 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.

Solution 2

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

As a replacement, you can use WifiWizard2 which is under active development, as it 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 seems to also support both Android and iOS.


However, if like me you also need to use the device's Hotspot or Wifi Tethering with Cordova, I recommend the cordova-hotspot-plugin package instead. The project is unfortunately discontinued; but for older Android API levels, it still seems to work.

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

Share:
18,511
Varun Nayyar
Author by

Varun Nayyar

Updated on June 29, 2022

Comments

  • Varun Nayyar
    Varun Nayyar almost 2 years

    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.

  • Subjective Effect
    Subjective Effect almost 9 years
    Yeah, let us know. I'm interested in this too.
  • Janek Olszak
    Janek Olszak over 8 years
    iOS is supported by WifiWizard
  • LeRoy
    LeRoy over 7 years
    This should be in the documentation :/
  • Reza
    Reza over 7 years
    Based on documentation they mentioned if app is using other apis than GetCurrentSSID(for example GetScanResult or listNetworks) apple will reject the app, any body has gone that far?
  • Dean Meehan
    Dean Meehan over 7 years
    Error: Registry returned 404 for GET on registry.npmjs.org/com.pylonproducts.wifiwizard
  • Mayank
    Mayank about 7 years
    Updated to "cordova plugin add wifiwizard"
  • David Refoua
    David Refoua over 6 years
    For most recent patches and pull requests, check WifiWizard2 here: github.com/tripflex/WifiWizard2
  • 1x2x3x4x
    1x2x3x4x over 6 years
    Thanks for this, 1st two options work, however the scan one gives [] back. Do you have an idea why? Using latest version of the plugin on Android device.
  • 1x2x3x4x
    1x2x3x4x over 6 years
    Just to let anyone know, if you get an empty [] in a newer version of Android, it's because you need to give Location permission to the app. Settings >> Apps >> theApp >> Permissions >> Location
  • Toufic Batache
    Toufic Batache about 6 years
    I've been trying for several times to make this work with this code but it's not working: WifiWizard2.scan(function(response) { ‎ alert(JSON.stringify(response)); ‎}); Woud you mind helping please? @xxxxxxxxxxxxx I'm trying to get a list of available networks
  • Joe Naber
    Joe Naber about 3 years
    WifiWizard2 is no longer supported and does not work with Android 11+ or iOS 14.5+
  • Joe Naber
    Joe Naber about 3 years
    WifiWizard2 is no longer supported and does not work with Android 11+ or iOS 14.5+