Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 高級開發 >> 設置 Android wifi連接的例子 samples

設置 Android wifi連接的例子 samples

編輯:高級開發

原文地址: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 );

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved