Change Configuration of mobile Hotspot

后端 未结 2 1040
终归单人心
终归单人心 2021-01-16 01:07

I\'m trying to run a hotspot with a new name and open accessibility.

    wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
    wifi         


        
相关标签:
2条回答
  • 2021-01-16 01:45

    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.

    0 讨论(0)
  • 2021-01-16 01:48

    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:

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

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

    0 讨论(0)
提交回复
热议问题