设置 Android(安卓)wifi连接 samples【转】
16lz
2022-03-16
原文地址:
http://stackoverflow.com/questions/2140133/how-and-what-to-set-to-android-wificonfiguration-presharedkey-to-connect-to-the-w
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiConfiguration wc = new WifiConfiguration(); // This is must be quoted according to the documentation // http://developer.android.com/reference/android/net/wifi/WifiConfiguration.html#SSID wc.SSID = "\"SSIDName\""; wc.preSharedKey = "password"; wc.hiddenSSID = true; wc.status = WifiConfiguration.Status.ENABLED; wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN); int res = wifi.addNetwork(wc); Log.d("WifiPreference", "add Network returned " + res ); boolean b = wifi.enableNetwork(res, true); Log.d("WifiPreference", "enableNetwork returned " + b );
更多相关文章
- android rating bar style
- Android(安卓)获取 IP 地址
- ScrollNumber 数字滚动
- Android(安卓)一堆会动的控件
- Android(安卓)开源项目分类汇总
- android 从矢量图SVG获取位图bitmap
- KBinding 使用kotlin实现的Android(安卓)MVVM框架
- Android(安卓)SDK开发包国内下载地址
- Android-TCPDump for Android(抓TCP数据包工具)