WifiManager自動連線wifi接入點

2021-06-08 14:28:18 字數 2317 閱讀 9255

/**

* * wifi管理類

* *

*/public class wifioperator

/*** 切換網路

* @param type 網路型別(1為中心網路 2 為車載網路)

* @return 結果碼 -1-本地設定為空;0-連線成功;1-已經為當前連線

* @see [類、類#方法、類#成員]

*/public int access2wifi(string type)

// 無線未開啟時,開啟無線

if (!wm.iswifienabled() && wifimanager.wifi_state_enabling != wm.getwifistate())

// 獲取本地的配置資訊

string sssid = "\"" + setting.getssid() + "\"";

string skey = "\"" + setting.getpassword() + "\"";

int encryptiontype = getkeymgmttype(setting.getencryptiontype());

listconfigurations = wm.getconfigurednetworks();

wificonfiguration config = null;

boolean i***isted = false;

int networkid = -1;

for (int i = configurations.size() - 1; i >= 0; i--)

}if (!i***isted)

config.hiddenssid = false;

config.priority = 30;

config.status = wificonfiguration.status.enabled;

config.allowedauthalgorithms.set(wificonfiguration.authalgorithm.open);

config.allowedgroupciphers.set(wificonfiguration.groupcipher.ccmp);

config.allowedgroupciphers.set(wificonfiguration.groupcipher.tkip);

config.allowedgroupciphers.set(wificonfiguration.groupcipher.wep104);

config.allowedgroupciphers.set(wificonfiguration.groupcipher.wep40);

config.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.tkip);

config.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.ccmp);

config.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.none);

config.allowedprotocols.set(wificonfiguration.protocol.wpa);

// 必須新增,否則無線路由無法連線

config.allowedprotocols.set(wificonfiguration.protocol.rsn);

networkid = wm.addnetwork(config);

if (networkid != -1)

}else

config.allowedkeymanagement.set(encryptiontype);

if (encryptiontype != 0)

wm.updatenetwork(config);

}if (networkid != -1)

return 0;

}/**

* 獲取加密型別

* @param type 加密型別

* @return 加密型別

* @see [類、類#方法、類#成員]

*/private int getkeymgmttype(string type)

if ("wep".equals(type))

else if ("wpa-psk".equals(type))

else if ("wpa2-psk".equals(type))

return wificonfiguration.keymgmt.none;

}}

WifiManager 實現Wifi快捷開關

wifi快捷快捷開關 獲取wifi狀態 public static boolean iswifienable context context 設定wifi狀態 public static void setwifienable context context,boolean enable 那麼跟gpr...

自動連線wifi

public class lhywifi 開啟wifi public void openwifi 關閉wifi public void closewifi 檢查當前wifi狀態 public int checkstate 鎖定wifilock public void acquirewifilock ...

mysql 自動連線 mysql 自連線

自連線 自連線是一種特殊的表連線,它是指相互連線的表在物理上同為一張表,但是邏輯上是多張表。自連線通常用於表中的資料有層次結構,如區域表 選單表 商品分類表等。自連線語法 select a.column,b.column from table a,table b where a.column b.c...