【问题标题】:Wifi hotspot name not updated on hotspot creation in desireWifi热点名称未在热点创建时更新
【发布时间】: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


【解决方案1】:

我无法让这个工作。一件事是您的 SSID 肯定是错误的。它应该用引号“\”MyWifiAP“\”。祝你好运。

【讨论】:

    猜你喜欢
    • 2013-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    • 2011-03-02
    • 2012-11-14
    • 1970-01-01
    相关资源
    最近更新 更多