我正在使用以下代码在运行Android 2.2的HTC欲望中启用wfi热点。
创建了接入点(Hotspot),但接入点名称/热点名称/ SSID不是我在代码中指定的(MyWifiAP)。
Anyhelp on this?
代码:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
Log.d(TAG, "enableMobileAP methods " + wmMethods.length);
for(Method method: wmMethods){
Log.d(TAG, "enableMobileAP method.getName() " + method.getName());
if(method.getName().equals("setWifiApEnabled")) {
WifiConfiguration netConfig = new WifiConfiguration();
netConfig.SSID = "MyWifiAP";
netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
try {
Log.d(TAG, "enableMobileAP try: ");
method.invoke(wifi, netConfig, enabled);
if (netConfig.wepKeys!=null && netConfig.wepKeys.length>=1)
Log.d(TAG, "enableMobileAP key : " + netConfig.wepKeys[0]);
Log.d(TAG, "enableMobileAP enabled: ");
mIsWifiEnabled = enabled;
} catch (Exception e) {
Log.e(TAG, "enableMobileAP failed: ", e);
}
}
}.
答案 0 :(得分:1)
我无法让这个工作。有一件事是你的SSID肯定是错的。它应该在引号“\”MyWifiAP“\”中。祝你好运。