android 链接固定wifi,Android连接指定SSID的WIFI热点
function ConnectWifi(ssid, keyword, type, level) {var SSID = ssid;var Password = keyword;var Context = plus.android.importClass("android.content.Context");var WifiManager = plus.android.importClass("a
function ConnectWifi(ssid, keyword, type, level) {
var SSID = ssid;
var Password = keyword;
var Context = plus.android.importClass("android.content.Context");
var WifiManager = plus.android.importClass("android.net.wifi.WifiManager");
var wifiManager = plus.android.runtimeMainActivity().getSystemService(Context.WIFI_SERVICE);
var WifiConfiguration = plus.android.importClass('android.net.wifi.WifiConfiguration');
var config = new WifiConfiguration();
if (type == 1) {
var allowedKeyManagement = plus.android.getAttribute(config, 'allowedKeyManagement');
plus.android.importClass(allowedKeyManagement);
allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
}
if (type == 2) {
plus.android.setAttribute(config, 'wepKeys[0]', "\"" + Password + "\"");
plus.android.setAttribute(config, 'hiddenSSID', true);
var allowedAuthAlgorithms = plus.android.getAttribute(config, 'allowedAuthAlgorithms');
plus.android.importClass(allowedAuthAlgorithms);
allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
var allowedGroupCiphers = plus.android.getAttribute(config, 'allowedGroupCiphers');
plus.android.importClass(allowedGroupCiphers);
allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
var allowedKeyManagement = plus.android.getAttribute(config, 'allowedKeyManagement');
plus.android.importClass(allowedKeyManagement);
allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
config.wepTxKeyIndex = 0;
}
if (type == 3) {
plus.android.setAttribute(config, 'SSID', "\"" + SSID + "\"");
plus.android.setAttribute(config, 'preSharedKey', "\"" + Password + "\"");
plus.android.setAttribute(config, 'hiddenSSID', true);
var allowedAuthAlgorithms = plus.android.getAttribute(config, 'allowedAuthAlgorithms');
plus.android.importClass(allowedAuthAlgorithms);
allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
var allowedGroupCiphers = plus.android.getAttribute(config, 'allowedGroupCiphers');
plus.android.importClass(allowedGroupCiphers);
allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
var allowedKeyManagement = plus.android.getAttribute(config, 'allowedKeyManagement');
plus.android.importClass(allowedKeyManagement);
allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
var allowedPairwiseCiphers = plus.android.getAttribute(config, 'allowedPairwiseCiphers');
plus.android.importClass(allowedPairwiseCiphers);
allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
var allowedGroupCiphers = plus.android.getAttribute(config, 'allowedGroupCiphers');
plus.android.importClass(allowedGroupCiphers);
allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
var allowedPairwiseCiphers = plus.android.getAttribute(config, 'allowedPairwiseCiphers');
plus.android.importClass(allowedPairwiseCiphers);
allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
plus.android.setAttribute(config, 'status', WifiConfiguration.Status.ENABLED);
}
var wcgID = wifiManager.addNetwork(config);
var b = wifiManager.enableNetwork(wcgID, true);
//plus.webview.currentWebview().reload();
}
谢谢 磊子哥的帮助 ,分享
更多推荐
所有评论(0)