WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"rick\"";
wc.preSharedKey = "";
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 );我要连接的SSID为 rick ,没有密码
返回值 res 一直都是 -1
代码是网上搜的 <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
权限都加了为什么还是连不上呢?
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"rick\"";
wc.preSharedKey = "";
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 );我要连接的SSID为 rick ,没有密码
返回值 res 一直都是 -1
代码是网上搜的 <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
权限都加了为什么还是连不上呢?
解决方案 »
- 求救啊,SDK弄不好。真不知道该怎么弄了
- android image crop 非intent 的方式求教
- 新手想学安卓系统开发,应该从什么书开始看呢?
- android 中有没有tree控件
- 通话中输入按键,对方可以收到按的什么键
- 【求助】ecplise出现缓冲区溢出的错误,请教各位大神
- 帮忙解析个简单的json数据,谢谢
- listview下拉刷新问题。谁有这样的demo,要求刚打开页面时自动下拉刷新,而不是要手去拉的时候才下拉。各大软件都有这样的功能
- 微信支付失败
- Android 连接wifi下获取内网ip 获取到10.152.x.x类的 我想获取192.168.x.x类的,怎么做啊 - -.
- 请教谷歌地图离线版
- android SharedPreferences存储问题
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);