我正在添加Android上的Wifi网络,我想知道您应该如何连接到不广播其SSID的wifi网络(无论它是否有空SSID或带有\ 0s的清晰SSID) 。

这是我目前用于广播其SSID的Wifi网络的内容:

WifiConfiguration conf = new WifiConfiguration();
conf.SSID = quote(input);
conf.preSharedKey = quote("somepassword");

WifiManager wifiManager = (WifiManager)MainActivity.this.getSystemService(Context.WIFI_SERVICE);

wifiManager.disconnect();
wifiManager.enableNetwork(wifiManager.addNetwork(conf), true);
wifiManager.reconnect();

最佳答案

  string networkSSID = "";
  string networkPass = "somepassword";

  WifiConfiguration wifiConfig = new WifiConfiguration();
  wifiConfig.Ssid = string.Format("\"{0}\"", networkSSID);
  wifiConfig.PreSharedKey = string.Format("\"{0}\"", networkPass);

  WifiManager wifiManager = (WifiManager)Application.Context.GetSystemService(Context.WifiService);

  // Use ID
  int netId = wifiManager.AddNetwork(wifiConfig);
  wifiManager.Disconnect();
  wifiManager.EnableNetwork(netId, true);
  wifiManager.Reconnect();

关于java - 以编程方式添加并连接到Android上的非广播Wifi网络,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29827238/

10-10 07:09