Code example for WifiConfiguration

0
 
 
    } 
 
    private WifiConfiguration getApConfiguration() {
        WifiConfiguration apConfig = new WifiConfiguration();
        //配置热点的名称 
        apConfig.SSID = "yourId";
        apConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
        apConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
        apConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
        apConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
        //配置热点的密码 
        apConfig.preSharedKey = "yourPassword";
        return apConfig;
    } 
 
    private Boolean getApState(WifiManager wifi) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        Method method = wifi.getClass().getMethod("isWifiApEnabled");
        return (Boolean) method.invoke(wifi);
    }