DHCP for HTC Android hotspot Configuration

Source: Internet
Author: User
Tags bssid

Recently, we have been studying the establishment of mobile phone hotspots. HTC mobile phones are more difficult. First, they cannot modify the SSID, bssid,

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

Then I found that the HTC mobile phone hotspot was built, but other mobile phones could not connect to it. Later I found that using static IP addresses could solve this problem, but it was too troublesome.

This article describes how to manually configure a local DHCP configuration in the HTC WiFi hotspot program com. HTC. wifirouter to automatically obtain the IP address.

But how can we implement it with code.

After studying for a long time, I only need to dump all the classes unique to HTC. 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].getName());            }        }                } catch (NoSuchFieldException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IllegalArgumentException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IllegalAccessException e) {// TODO Auto-generated catch blocke.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 --

The member variable dhcpenable was found. It was a Boolean variable at the beginning, but it was wrong. An error occurred during the setting.

Simply print out its type and change the print statement:

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-type variable, and it can be estimated that it is set to enable.

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 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.