给我写一个android11用给定的ssid和password连接wifi的代码,用java实现
时间: 2023-03-12 17:40:03 浏览: 101
android Wifi连接代码
public class WifiConnection {
public static void main(String[] args) {
String ssid = "yourSSID";
String password = "yourPassword";
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = String.format("\"%s\"", ssid);
wifiConfig.preSharedKey = String.format("\"%s\"", password);
WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
//remember id
int netId = wifiManager.addNetwork(wifiConfig);
wifiManager.enableNetwork(netId, true);
}
}
阅读全文