我正在使用以下代码在运行 Android 2.2 的 HTC desire 中启用 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);
}
}
}.
最佳答案
我一直无法使它正常工作。一件事是您的 SSID 肯定是错误的。它应该用引号“\”MyWifiAP“\”。祝你好运。
关于android - Wifi 热点名称未在热点创建时更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4955151/