如何在android中设置安全热点(带密码)

时间:2015-05-09 04:34:36

标签: android android-wifi

我想设置热点,配置ssidpassword因为我想与某些设备共享热点。 我在下面使用的代码对我来说很好,但我无法设置热点的密码。

if (wm.isWifiEnabled()) {
                    wm.setWifiEnabled(false);
                }
                WifiConfiguration wifiCon = new WifiConfiguration();
                wifiCon.SSID = "UsmanAp";
                wifiCon.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
                wifiCon.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
                wifiCon.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
                wifiCon.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
                try{
                    Method setWifiApMethod = wm.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
                    boolean apstatus=(Boolean) setWifiApMethod.invoke(wm, wifiCon,true);
                    Method isWifiApEnabledmethod = wm.getClass().getMethod("isWifiApEnabled"); 
                    while(!(Boolean)isWifiApEnabledmethod.invoke(wm)){};
                    Method getWifiApStateMethod = wm.getClass().getMethod("getWifiApState"); 
                    int apstate=(Integer)getWifiApStateMethod.invoke(wm);
                    Method getWifiApConfigurationMethod = wm.getClass().getMethod("getWifiApConfiguration");
                    wifiCon=(WifiConfiguration)getWifiApConfigurationMethod.invoke(wm);
                } catch (Exception e) {
                    Log.e(this.getClass().toString(), "", e);
                }

在上面的代码中添加了什么来设置热点的密码。

-Usman

0 个答案:

没有答案