1

My app configures and activates an access point:

// Expose the required method
WifiManager wifimanager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
Method setWifiApEnabled = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);

// Set up my configuration
WifiConfiguration myConfig = new WifiConfiguration();
myConfig.SSID = "markhotspot";
myConfig.allowedProtocols = WifiConfiguration.Protocol.RSN;
myConfig.preSharedKey = "markpass";

// Configure and enable the access point
setWifiApEnabled.invoke(wifiManager, myConfig, true);

The hotspot comes up correctly, but with no security - no WPA2, WPA, WEP etc.

How can I make it use WPA2 please?

Mark Smith
  • 880
  • 1
  • 8
  • 25
  • why you dot try with other Protocols ? look this https://github.com/zxing/zxing/blob/master/android/src/com/google/zxing/client/android/wifi/WifiConfigManager.java – Sree Jul 14 '15 at 11:36

1 Answers1

0

You can define key management

Sample Code:

private boolean setWifiApEnabled() 
    { 
        boolean result = false;
        // initialise you 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;
    } 
Sahil Bahl
  • 679
  • 3
  • 11