Guest User

Untitled

a guest
Feb 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. void saveWepConfig()
  2. {
  3. WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
  4. WifiConfiguration wc = new WifiConfiguration();
  5. wc.SSID = "\"SSID_NAME\""; //IMP! This should be in Quotes!!
  6. wc.hiddenSSID = true;
  7. wc.status = WifiConfiguration.Status.DISABLED;
  8. wc.priority = 40;
  9. wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
  10. wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
  11. wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
  12. wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
  13. wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
  14. wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
  15. wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
  16. wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
  17. wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
  18.  
  19. wc.wepKeys[0] = "\"aaabbb1234\""; //This is the WEP Password
  20. wc.wepTxKeyIndex = 0;
  21.  
  22. WifiManager wifiManag = (WifiManager) this.getSystemService(WIFI_SERVICE);
  23. boolean res1 = wifiManag.setWifiEnabled(true);
  24. int res = wifi.addNetwork(wc);
  25. Log.d("WifiPreference", "add Network returned " + res );
  26. boolean es = wifi.saveConfiguration();
  27. Log.d("WifiPreference", "saveConfiguration returned " + es );
  28. boolean b = wifi.enableNetwork(res, true);
  29. Log.d("WifiPreference", "enableNetwork returned " + b );
Add Comment
Please, Sign In to add comment