更改移动热点的配置



我正在尝试使用新名称和开放可访问性运行热点。

    wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
    wifiConfig.SSID = ""MySSID"";
    wifiConfig.networkId = 1;
    methodNum = getMethodNumber("setWifiApEnabled");
    try {
        wmMethods[methodNum].invoke(wifiManager, wifiConfig, true);
    } catch (IllegalArgumentException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IllegalAccessException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (InvocationTargetException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }        

我得到了正确的方法,似乎它启动了手机上的热点,但配置不会更改。

我尝试使用getWifiApConfiguration获取当前配置数据而且我一无所获,没有SSID,也不是当前的加密。

我正在使用HTC Evo 3d进行调试。

一些htc手机似乎使用HotspotProfile类型的类来保持其配置。因此,在调用setWifiApEnabled之前,您需要以htc的方式设置ssid:

if (isHtc) setHTCSSID(config);
methodNum = getMethodNumber("setWifiApEnabled");
try {
    wmMethods[methodNum].invoke(wifiManager, wifiConfig, true);
    ...

isHTC 可以按如下方式计算:

 try { isHtc = null!=WifiConfiguration.class. getDeclaredField("mWifiApProfile");  }
 catch (java.lang.NoSuchFieldException e) { isHtc = false }

并且设置HTCSSID将是:

public void setHTCSSID(WifiConfiguration config) {
    try {
        Field mWifiApProfileField = WifiConfiguration.class.getDeclaredField("mWifiApProfile");
        mWifiApProfileField.setAccessible(true);
        Object hotSpotProfile = mWifiApProfileField.get(config);
        mWifiApProfileField.setAccessible(false);
        if(hotSpotProfile!=null){
            Field ssidField = hotSpotProfile.getClass().getDeclaredField("SSID");
            ssidField.setAccessible(true);
            ssidField.set(hotSpotProfile, config.SSID);
            ssidField.setAccessible(false);
        }
    } catch(Exception e) {
        e.printStackTrace();
    }
}

我在一些中文博客中找到了这些信息:http://xiaxingwork.iteye.com/blog/1727722 和 http://blog.sina.com.cn/s/blog_53dd443a010109i8.html

这似乎是HTC的问题。我的一些朋友在HTC和其他设备上尝试了类似的代码。没有在HTC上工作,在其他人上工作。

最新更新