android 存储WiFi信息
时间: 2023-08-02 12:25:30 浏览: 264
android对Wifi进行操作详解
Android可以通过WifiManager获取当前连接的WiFi信息,也可以通过WifiConfiguration类来存储WiFi信息。下面是存储WiFi信息的代码示例:
1. 获取WifiManager对象
```
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
```
2. 创建WifiConfiguration对象
```
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = "\"SSID_NAME\"";
wifiConfig.preSharedKey = "\"PASSWORD\"";
```
3. 添加Network
```
int networkId = wifiManager.addNetwork(wifiConfig);
```
4. 启用Network
```
wifiManager.enableNetwork(networkId, true);
```
注意:添加Network需要在系统具有修改WiFi配置的权限下才能进行。
阅读全文