我想知道如何为密码保护的wifi列表编写验证。我正在使用 WifiWizard 插件基本连接,但它没有连接所有网络(特别是密码保护)。所以我想知道如何为受密码保护的wifi列表编写代码。我还使用网络信息插件注册networkSSID,我也使用 InAppBrowser 在传递验证后连接到浏览器。
答案 0 :(得分:1)
我写了一个示例cordova应用程序,它有助于启动wifi,搜索和扫描可用的wifi网络并连接到特定的密码保护网络。代码如下:
<强>的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");
}
}