连接密码保护wifi列表cordova [英] connection for password protected wifi lists cordova

查看:1307
本文介绍了连接密码保护wifi列表cordova的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何为受密码保护的WiFi列表进行验证。我使用 WifiWizard 插件基本上连接,但它不是连接所有的网络(特别是密码保护)。所以我想知道如何编写密码保护的WiFi列表的代码。我也使用网络信息插件注册networkSSID,我也使用 InAppBrowser 在通过验证后连接到浏览器。

I would like to know how to write validations for the password protected wifi lists. I'm using WifiWizard plugin to connect basically but it is not connecting all the networks(especially password protected). So I would like to know how to write code for the password protected wifi lists. I'm also using Network Information plugin to register the networkSSID and I'm also using InAppBrowser to connect to the browser after passing the validations.

推荐答案

我写了一个示例cordova应用程序,帮助启动wifi,搜索和扫描可用的无线网络,并连接到特定的密码保护网络。代码如下:

I have wrote a sample cordova app that helps in starting the wifi, search and scan for available wifi networks and connect to a particular password protected network. The code is follows:

index.html

<!DOCTYPE html>
    <head>
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Wifi Wizard</title>
    </head>
    <body>      
        <br>        
        <br>
        Start Wifi <input type="button" value="wifi" name="Wifi" id="wifi"/>     <br>
        Search Wifi <input type="button" value="search" name="Search" id="search"/>  <br>
        Scan Wifi <input type="button" value="scan" name="Scan" id="scan"/>  <br>
        Connect Wifi <input type="button" value="connect" name="Connect" id="connect"/>  <br>
        <script type="text/javascript" src="js/jquery.js"></script> 
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/app.js"></script>
    </body>
</html>

app.js

$(document).ready(function() {
    document.addEventListener("deviceready", onDeviceReady, false);
});

function onDeviceReady() {      
     $('#wifi').click( function() 
        {   
            try {               
                WifiWizard.isWifiEnabled(win, fail);
            }
            catch(err) {
                alert("Plugin Error - " + err.message);
            }

        }); 

    function win(e) {
        if(e) {
            alert("Wifi enabled already");
        }
        else {
            WifiWizard.setWifiEnabled(true, winEnable, failEnable);
        }

    }

    function fail(e) {
        alert("Error checking Wifi status");
    }

    function winEnable(e) {
        alert("Wifi enabled successfully");
    }

    function failEnable(e) {
        alert("Error enabling Wifi ");
    }

    $('#search').click( function() 
        {   
            try {               
                WifiWizard.listNetworks(listHandler, fail);
            }
            catch(err) {
                alert("Plugin Error - " + err.message);
            }

        }); 

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

    $('#scan').click( function() 
        {   
            try {               
                WifiWizard.getScanResults({numLevels: 1},listHandler1, fail);
            }
            catch(err) {
                alert("Plugin Error - " + err.message);
            }

        });

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

    $('#connect').click( function() 
        {   
            try {   
                var config = WifiWizard.formatWPAConfig("NETWORK_NAME", "PASSWORD");
                WifiWizard.addNetwork(config, function() {
                    WifiWizard.connectNetwork("NETWORK_NAME");
                });             
            }
            catch(err) {
                alert("Plugin Error - " + err.message);
            }

        });

    function connectSuccess(e)
    {
        alert("Connect success");
    }

}

这篇关于连接密码保护wifi列表cordova的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆