Skip to content Skip to sidebar Skip to footer

Change Configuration Of Mobile Hotspot

I'm trying to run a hotspot with a new name and open accessibility. wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); wifiConfig.SSID = '\'MySSID\

Solution 1:

Some htc phones seems to use a class of type HotspotProfile to keep its configuration. So, before calling setWifiApEnabled, you need set the ssid in htc's way:

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

isHtc can be calculated like:

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

and setHTCSSID would be:

publicvoidsetHTCSSID(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();
    }
}

I found this information in some chinese blogs: http://xiaxingwork.iteye.com/blog/1727722 and http://blog.sina.com.cn/s/blog_53dd443a010109i8.html

Solution 2:

It seems like its a problem with HTC. Some of my friends tried similar code on HTC and other devices. Didnt work on HTC, worked on the others.

Post a Comment for "Change Configuration Of Mobile Hotspot"