原文地址:
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 sdk sources sample目录,解压至sdk目录即可
android-7 samples 解压到目录 android-sdk-windows\samples
Android 5.0 samples,api level 21
android4.4 sdk samples(ApiDemos在其legacy目录下) 需要用gradle部署
android sdk 自带 实例(samples)如果资源所需积分不是2积分,可以给我留言,我会修改
Android samples
opencv android source, samples 。
Android,samples samples002
spring-android-samples-master
arcgis runtime samples android master
android-kotlin-samples, Android的一些Kotlin基本示例 android-kotlin-samples Android的一些基本的 Kotlin插件示例示例HttpUrlConnection和 AsyncTask带有BaseAdapter和数据对象的 ListViewOkHttp
Android Architecture Blueprints The Android framework provides a lot of flexibility in deciding how to organize and architect an Android app. While this freedom is very valuable, it can also lead to ...
rxAndroid开发实例,RxJava-Android-Samples-master
android 2.1 samples doc
Google Maps Android API v2 Samples Samples demonstrating how to use Google Maps Android API v2. This repo contains the following samples: ApiDemos: A collection of small demos showing most features ...
android_developer_training_samples
The list below provides a summary of the sample applications that are available with the Android SDK. Using the links on this page, you can view the source files of the sample applications in your ...
android自带samples,全部都有。版本android-8.
android sdk 官方自带的示例程序,绝对是学习android应用开发最好的参考