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

后端 未结 2 1688
不知归路
不知归路 2020-12-14 12:28

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

2条回答
  •  不知归路
    2020-12-14 12:55

    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:

     
     
     
    

    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.

提交回复
热议问题