HTC Android mobile phones cannot modify Hotspot SSID names and passwords

Source: Internet
Author: User

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

Boolean isHtc = false; try {isHtc = WifiConfiguration. class. getDeclaredField ("mWifiApProfile ")! = Null;} catch (java. lang. noSuchFieldException e) {isHtc = false;} WifiConfiguration apConfig = new WifiConfiguration (); apConfig. SSID = "H3c_xx"; apConfig. preSharedKey = "h3a7ch3c"; apConfig. allowedKeyManagement. set (WifiConfiguration. keyMgmt. WPA_PSK); if (isHtc) {setHTCSSID (apConfig) ;}// sets the hotspot Method through reflection call; method = wifiManager. getClass (). getMethod ("setWifiApEnabled", WifiConfiguration. class, Boolean. TYPE); // return the hotspot open state boolean flag = (Boolean) method. invoke (wifiManager, apConfig, true );

 

Set the SSID and password [java]
    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);                      Field localField3 = hotSpotProfile.getClass().getDeclaredField(                          "key");                  localField3.setAccessible(true);                  localField3.set(hotSpotProfile, config.preSharedKey);                  localField3.setAccessible(false);                      Field localField6 = hotSpotProfile.getClass().getDeclaredField(                          "dhcpEnable");                  localField6.setAccessible(true);                  localField6.setInt(hotSpotProfile, 1);                  localField6.setAccessible(false);              }          } catch (Exception e) {              e.printStackTrace();          }      }  

 

You can view the modifiable values by traversing the attributes: [java]
public void dumpHTCWifiFunction2() {      Log.e(TAG, "dumpHTCWifiFunction2++");      // Method[] classMethods = null;      Field localField1;      Field[] fieldlist;      WifiConfiguration apConfig = new WifiConfiguration();      try {          localField1 = WifiConfiguration.class                  .getDeclaredField("mWifiApProfile");          localField1.setAccessible(true);          Object localObject2 = localField1.get(apConfig);          localField1.setAccessible(false);          if (localObject2 != null) {              fieldlist = localObject2.getClass().getDeclaredFields();              for (int i = 0; i < fieldlist.length; i++) {                  Log.e(TAG, "found api: " + fieldlist[i].getName()                          + " type:" + fieldlist[i].toString());              }          }        } catch (NoSuchFieldException e) {          e.printStackTrace();      } catch (IllegalArgumentException e) {          e.printStackTrace();      } catch (IllegalAccessException e) {          e.printStackTrace();      }        Log.e(TAG, "dumpHTCWifiFunction2--");  }  

 

For example, found api: DEFAULT_DHCP_MAX_AP_CONNECTION type: public static final int android.net. wifi. wifiConfiguration $ HotspotProfile. DEFAULT_DHCP_MAX_AP_CONNECTIONfound api: DEFAULT_MAX_AP_CONNECTION type: public static final int android.net. wifi. wifiConfiguration $ HotspotProfile. DEFAULT_MAX_AP_CONNECTIONfound api: DHCP_MAX_AP_CONNECTION type: public static final int android.net. wifi. wifiConfiguration $ HotspotProfile. DHCP_MAX_AP_CONNECTIONfound api: MAX_AP_CONNECTION type: public static final int android.net. wifi. wifiConfiguration $ HotspotProfile. MAX_AP_CONNECTIONfound api: OPEN type: public static final java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. OPENfound api: WEP type: public static final java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. WEPfound api: WPA type: public static final java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. WPAfound api: WPA2 type: public static final java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. WPA2found api: BSSID type: public java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. BSSIDfound api: SSID type: public java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. SSIDfound api: blocklist type: public [Ljava. lang. string; android.net. wifi. wifiConfiguration $ HotspotProfile. blocklistfound api: whitelist type: public [Ljava. lang. string; android.net. wifi. wifiConfiguration $ HotspotProfile. whitelistfound api: this $0 type: final android.net. wifi. wifiConfiguration android.net. wifi. wifiConfiguration $ HotspotProfile. this $0 found api: startingIP type: public java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. startingIPfound api: dhcpSubnetMask type: public java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. dhcpSubnetMaskfound api: dnsIPAddr1 type: public java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. dnsIPAddr1found api: dnsIPAddr2 type: public java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. dnsIPAddr2found api: secureType: public java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. secureTypefound api: key type: public java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. keyfound api: ipAddress type: public java. lang. string android.net. wifi. wifiConfiguration $ HotspotProfile. ipAddressfound api: hiddenSSID type: public boolean android.net. wifi. wifiConfiguration $ HotspotProfile. hiddenSSIDfound api: maxConns type: public int android.net. wifi. wifiConfiguration $ HotspotProfile. maxConnsfound api: maxDhcpClients type: public int android.net. wifi. wifiConfiguration $ HotspotProfile. maxDhcpClientsfound api: enableMacFilter type: public int android.net. wifi. wifiConfiguration $ HotspotProfile. enableMacFilterfound api: sleepPolicy type: public int android.net. wifi. wifiConfiguration $ HotspotProfile. sleepPolicyfound api: dhcpEnable type: public int android.net. wifi. wifiConfiguration $ HotspotProfile. dhcpEnablefound api: connectionArray type: public int android.net. wifi. wifiConfiguration $ HotspotProfile. connectionArrayfound api: channel type: public int android.net. wifi. wifiConfiguration $ HotspotProfile. channel example: http://t.cn/z83xYFG

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.