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
Post a Comment