HTC Android hotspot hotspot Configuration dhcp

Source: Internet
Author: User

Recently in the study of the establishment of mobile phone hotspots. HTC phone comparison pit dad, first one, is not the usual way to modify the SSID, BSSID,

Search on the Internet, there is a blog to solve this problem, please refer to: http://blog.sina.com.cn/s/blog_adc221ac01011mrs.html

Then found that HTC phone hotspot is built, but other phones to connect it, how can not even, and later found that the use of static IP can solve the problem, but too much trouble.

Researched the next by manually configuring HTC's WiFi Hotspot program Com.htc.WiFiRouter There is a local DHCP configuration, which can be hooked up to automatically get the IP.

But how do you do it in code? This is the pit daddy.

Study for half a day, or only the HTC exclusive class to it all dump out, the code is as follows

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].ge                Tname ());      }}} catch (Nosuchfieldexception e) {//TODO auto-generated catch block    E.printstacktrace ();    } catch (IllegalArgumentException e) {//TODO auto-generated catch block E.printstacktrace (); } catch (ILlegalaccessexception e) {//TODO auto-generated catch block E.printstacktrace ();    } log.e (TAG, "dumphtcwififunction2--"); }


12-28 11:06:29.956:e/mainactivity (3253): dumphtcwififunction2++
12-28 11:06:29.966:e/mainactivity (3253): Found Api:default_dhcp_max_ap_connection
12-28 11:06:29.966:e/mainactivity (3253): Found Api:default_max_ap_connection
12-28 11:06:29.976:e/mainactivity (3253): Found Api:dhcp_max_ap_connection
12-28 11:06:29.976:e/mainactivity (3253): Found Api:max_ap_connection
12-28 11:06:29.976:e/mainactivity (3253): Found Api:open
12-28 11:06:29.976:e/mainactivity (3253): Found API:WEP
12-28 11:06:29.986:e/mainactivity (3253): Found API:WPA
12-28 11:06:29.986:e/mainactivity (3253): Found API:WPA2
12-28 11:06:29.986:e/mainactivity (3253): Found Api:bssid
12-28 11:06:29.996:e/mainactivity (3253): Found Api:ssid
12-28 11:06:29.996:e/mainactivity (3253): Found Api:blocklist
12-28 11:06:29.996:e/mainactivity (3253): Found Api:whitelist
12-28 11:06:29.996:e/mainactivity (3253): Found api:this$0
12-28 11:06:30.006:e/mainactivity (3253): Found API:STARTINGIP
12-28 11:06:30.006:e/mainactivity (3253): Found Api:dhcpsubnetmask
12-28 11:06:30.016:e/mainactivity (3253): Found API:DNSIPADDR1
12-28 11:06:30.016:e/mainactivity (3253): Found API:DNSIPADDR2
12-28 11:06:30.016:e/mainactivity (3253): Found Api:securetype
12-28 11:06:30.016:e/mainactivity (3253): Found Api:key
12-28 11:06:30.016:e/mainactivity (3253): Found api:ipaddress
12-28 11:06:30.016:e/mainactivity (3253): Found Api:hiddenssid
12-28 11:06:30.016:e/mainactivity (3253): Found Api:maxconns
12-28 11:06:30.016:e/mainactivity (3253): Found Api:maxdhcpclients
12-28 11:06:30.026:e/mainactivity (3253): Found Api:enablemacfilter
12-28 11:06:30.026:e/mainactivity (3253): Found Api:sleeppolicy
12-28 11:06:30.026:e/mainactivity (3253): Found api:dhcpenable
12-28 11:06:30.026:e/mainactivity (3253): Found Api:connectionarray
12-28 11:06:30.026:e/mainactivity (3253): Found Api:channel
12-28 11:06:30.026:e/mainactivity (3253): dumphtcwififunction2--

Dhcpenable This member variable is found, just start guessing it is a Boolean variable, but wrong, there will be errors in setting.

Simply print out its type, and print the statement to read:

LOG.E (TAG, "found API:" + fieldlist[i].getname () + "type:" +fieldlist[i].tostring ());

Found api:dhcpenable type:public int android.net.wifi.wificonfiguration$hotspotprofile.dhcpenable

It turns out to be an int variable, and guess it's 1 for enable. After setting, sure enough.

The complete code is as follows:

Private Boolean SETWIFISSIDFORHTC (Wificonfiguration apconfig) {Boolean successed = true;      Wificonfiguration mnetconfig = new Wificonfiguration ();                      Field LocalField1;                          try {localField1 = WifiConfiguration.class.getDeclaredField ("Mwifiapprofile");                          Localfield1.setaccessible (TRUE);                          Object localObject2 = Localfield1.get (apconfig);                          Localfield1.setaccessible (FALSE);                               if (localobject2!=null) {Field localField5 = Localobject2.getclass (). Getdeclaredfield ("SSID");                              Localfield5.setaccessible (TRUE);                              Localfield5.set (LocalObject2, APCONFIG.SSID);//Netconfig.ssid);                              Localfield5.setaccessible (FALSE);                              Field localField4 = Localobject2.getclass (). Getdeclaredfield ("BSSID"); LOcalfield4.setaccessible (TRUE);                              Localfield4.set (LocalObject2, apconfig.bssid);//netconfig.bssid);                                                            Localfield4.setaccessible (FALSE);                                Field localField6 = Localobject2.getclass (). Getdeclaredfield ("dhcpenable"); Localfield6.setaccessible (TRUE);//Localfield6.set (LocalObject2, "true");//netconfig.bssid)                                ;                                Localfield6.setint (LocalObject2, 1);                          Localfield6.setaccessible (FALSE);                      }} catch (Exception e) {e.printstacktrace ();  } return successed; }
    • Related articles recommended:
    • How do I implement a DHCP client using w7100a?
    • How to implement DHCP in W5200
    • Mp4v2 porting and introduction of MP4 video recording library under embedded Linux
    • This article from: Hobby Linux Technology Network
    • This article link: http://www.ahlinux.com/embed/7349.html

HTC Android hotspot hotspot Configuration dhcp

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.