1

我的应用程序配置并激活了一个接入点:

// 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);

热点正确出现,但没有安全性 - 没有 WPA2、WPA、WEP 等。

请问我怎样才能让它使用WPA2?

4

1 回答 1

0

您可以定义密钥管理

示例代码:

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;
    } 
于 2015-07-15T06:14:03.410 回答