让Android热点使用WPA2 PSK

时间:2015-07-14 11:34:13

标签: android wpa wificonfiguration

我的应用配置并激活接入点:

<li class="treeview">
                        <a href="#">
                             <span>Leave Management</span> <i class="fa fa-angle-left pull-right"></i>
                        </a>
                        <ul class="treeview-menu">
                            <li class="@Html.IsActive("Leave", "Index")">@Html.ActionLink("My leave Information", "Index", "Leave")</li>
                            <li class="@Html.IsActive("Leave", "NewLeaveRequest")">@Html.ActionLink("New Leave Request", "NewLeaveRequest", "Leave")</li>
                            <li class="@Html.IsActive("Leave", "Approve")">@Html.ActionLink("Approvals", "Approve", "Leave")</li>
                            <li class="@Html.IsActive("Leave", "EmpLeaveInfo")">@Html.ActionLink("Employee Leave Information", "EmpLeaveInfo", "Leave")</li>

                        </ul>
                    </li>

热点正确显示,但没有安全性 - 没有WPA2,WPA,WEP等。

我怎样才能使用WPA2?

1 个答案:

答案 0 :(得分: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;
    }