Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. private void WPA(String networkSSID, String networkPass, WifiManager wifiManager, String command) {
  2. WifiConfiguration wc = new WifiConfiguration();
  3. wc.SSID = """ + networkSSID + """;
  4. wc.preSharedKey = """ + networkPass + """;
  5. wc.status = WifiConfiguration.Status.ENABLED;
  6. wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
  7. wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
  8. wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
  9. wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
  10. wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
  11. wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
  12. if (command.equals(ADD)) {
  13. addNetwork(wifiManager, wc);
  14. } else if (command.equals(REMOVE)) {
  15. removeNetwork(wifiManager, wc);
  16. }
  17.  
  18. }
  19.  
  20. private void addNetwork(WifiManager wifiManager, WifiConfiguration wc) {
  21. if (!wifiManager.isWifiEnabled()) enableWifi();
  22. int id = wifiManager.addNetwork(wc);
  23. if (id > -1) {
  24. wifiManager.disconnect();
  25. wifiManager.enableNetwork(id, true);
  26. wifiManager.reconnect();
  27. wifiManager.saveConfiguration();
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement