【发布时间】:2011-02-10 09:10:41
【问题描述】:
我正在使用以下代码在运行 Android 2.2 的 HTC 中启用 wfi 热点。
接入点(热点)已创建,但接入点名称/热点名称/SSID 不是我在代码中指定的(MyWifiAP)。
有什么帮助吗?
代码:
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);
}
}
}.
【问题讨论】:
-
您找到任何解决方案了吗? :s
-
@dheeps,你能分享完整的源代码吗? :D
标签: android networking wifi