wpa - Make Android hotspot use WPA2 PSK -


my app configures , activates access point:

// expose required method wifimanager wifimanager = (wifimanager)context.getsystemservice(context.wifi_service); method setwifiapenabled = wifimanager.getclass().getmethod("setwifiapenabled", wificonfiguration.class, boolean.class);  // set configuration wificonfiguration myconfig = new wificonfiguration(); myconfig.ssid = "markhotspot"; myconfig.allowedprotocols = wificonfiguration.protocol.rsn; myconfig.presharedkey = "markpass";  // configure , enable access point setwifiapenabled.invoke(wifimanager, myconfig, true); 

the hotspot comes correctly, no security - no wpa2, wpa, wep etc.

how can make use wpa2 please?

you can define key management

sample code:

private boolean setwifiapenabled()      {          boolean result = false;         // initialise wifimanager first           wifimanager.setwifienabled(false);          method enablewifi;         try {              enablewifi = wifimanager.getclass().getmethod("setwifiapenabled", wificonfiguration.class, boolean.class);         } catch (nosuchmethodexception e) {             logger.e(tag,e.tostring());             return result;         }           wificonfiguration  myconfig =  new wificonfiguration();         myconfig.ssid = "your ssid";         myconfig.presharedkey  = "your pass";         myconfig.status =   wificonfiguration.status.enabled;         myconfig.allowedkeymanagement.set(wificonfiguration.keymgmt.wpa_psk);         myconfig.allowedprotocols.set(wificonfiguration.protocol.rsn);         myconfig.allowedprotocols.set(wificonfiguration.protocol.wpa);         myconfig.allowedgroupciphers.set(wificonfiguration.groupcipher.tkip);          myconfig.allowedgroupciphers.set(wificonfiguration.groupcipher.ccmp);          myconfig.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.tkip);          myconfig.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.ccmp);         try {              result = (boolean) enablewifi.invoke(wifimanager, myconfig,status);         } catch (illegalaccessexception | illegalargumentexception                 | invocationtargetexception e) {             logger.e(tag,e.tostring());             return result;         }           return result;     }  

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -