android接続指定wifi
876 ワード
public WifiManager wifiManager;
public WifiConfiguration config;
public void connectGS() {
System.out.println(" "+AP_NAME);
config = new WifiConfiguration();
config.SSID = "\"" + AP_NAME + "\"";
config.allowedKeyManagement.set(KeyMgmt.NONE);
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
int networkId = wifiManager.addNetwork(config);
if(networkId != -1){
wifiManager.enableNetwork(networkId, true);
wifiManager.saveConfiguration();
System.out.println(" "+AP_NAME);
}else {
System.out.println(" "+AP_NAME+",networkId = -1");
}