<span id="Label3"> </p>1. How to get the WiFi object and operate the WiFi device, you need to get context.getsystemservice (context.wifi_service) to get the Wifimanager object, and use this object to manage WiFi devices. addnetwork (wificonfiguration Config) Adds a config description of the WiFi network, by default, This wifi network is disable State. Calculatesignallevel (int rssi, int Numlevels) calculates the Signal's rank comparesignallevel (int rssia, int Rssib) Compare the signal strength of network A and network B createwifilock (int lockType, String tag) to create a WiFi lock, lock the current WiFi connection disablenetwork (int netId) Make a network connection fail disconnect () Disconnect the current WiFi connection enablenetwork (int netId, Boolean disableothers) connected to the WiFi network referred to by netId, and other networks are disabled Getconfigurednetworks () gets the status of the network connection Getconnectioninfo () Gets the current connection information getdhcpinfo () get DHCP information getscanresulats () Get the results of a scan test getwifistate () Gets the status of the current WiFi device iswifienabled () determine if the WiFi device is turned on pingsupplicant () ping, and the ping operation of the PC is the same ressociate () Reconnect the WiFi network, even if the network is already connected to the reconnect () reconnect a non-connected wifi network removenetwork () remove a network saveconfiguration () Leave a configuration message setwifienabled () to have a connection active Startscan () start scanning updatenetwork (wificonfiguration Config) to update a network connection 2. Common WiFi status Wifi_ State_disabled WiFi nic is not available wifi_state_disabling WiFi nic is shutting down &NBSp Wifi_state_enabled WiFi network card available wifi_state_enabling WiFi card is open wifi_state_unknown WiFi NIC status not known 3. List view WiFi hotspot with connected signal Scanresult object is a property used to represent a nearby WiFi hotspot, you can return a scanresult list by Wifimanager.getscanresults (). I enclose the important properties of Demo,scanresult to view nearby WiFi hotspots There are a few: BSSID access point address SSID network name, unique difference wifi network name capabilities Network access Performance frequency The WiFi network signal strength found in the frequency (MHz) level of the hotspot near the current WiFi device 4. Connect WiFi hotspot via Wifimanager.getconfigurednetworks () method returns a list of Wificonfiguration objects and then calls the Wifimanager.enablenetwork () method to connect to the specified Hotspot. 5. View WiFi information that is already connected Wifiinfo is an object that is designed to represent a connection, and this object can be obtained through Wifimanager.getconnectioninfo (). The wifiinfo contains information about the current Connection. getbssid () Gets the Bssid property getdetailedstateof () Gets the connectivity of the client Gethiddenssid () gets whether the SSID is hidden getipaddress () gets the IP Address Getlinkspeed () Gets the speed of the connection getmacaddress () gets the MAC address Getrssi () gets the signal of the 802.11n network Getssid () get ssidgetsupplicanstate () Get information about the status of specific clients the classes and methods that are commonly used in WiFi operations are as follows, and a list showing the demo of WiFi hotspots is given BELOW. 1.activity layout is very simple is a listview,activity_wifi_list.xml content as follows: [html] <relativelayout xmlns:android= " Http://schemas.android.com/apk/res/android "&NBSP;&NBsp xmlns:tools= "http://schemas.android.com/tools" android:layout_width= "match_parent" android:layout_height= "match_parent" android:paddingbottom= "@dimen/activity _vertical_margin " android:paddingleft=" @dimen/activity_horizontal_margin " android:paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_ Vertical_margin " tools:context=". Wifilistactivity "> <listview android:id=" @+id/ ListView android:layout_width= "match_parent" android:layout_height= "wrap_content" > </ListView> </ Relativelayout> 2.listview's Item Layout file Item_wifi_list.xml content is as Follows: [html] <?xml version= "1.0" encoding= " Utf-8 "?> <relativelayout xmlns: android= "http://schemas.android.com/apk/res/android" android:layout_width= "match_parent" android:layout_height= "match_parent" > <imageview android:id= "@+id/imageview" android:layout_width= "WRAP_ Content " android:layout_height=" wrap_content " android:layout_alignparentleft= "true" android:layout_alignparenttop= "true" android:src= "@drawable/ic_launcher"/> <textview android:id= "@+id/textview" android:layout_width= " Wrap_content " android:layout_height=" wrap_content " android:layout_alignbottom= "@+id/imageview" Android:layout_marginbottom= "14dp" android:layout_torightof= "@+id/imageview" android:text= "TextView"/> <textview & nbsp android:id= "@+id/signal_strenth" android:layout_width= "wrap_content" & nbsp; android:layout_height= "wrap_content" Android:layout_ alignbaseline= "@+id/textview" android:layout_alignbottom= "@+id/textview" android:layout_alignparentright= "true" android:text= " TextView "/> </RelativeLayout> 3. here's The code for the activity, you need to customize the list yourself. [java] public class Wifilistactivity extends Activity { private Wifimanager Wifiman ager; list<scanresult> List; @OverrIDE protected void onCreate (Bundle Savedinstancestate) { Super.oncre Ate (savedinstancestate); Setcontentview (r.layout.activity_wifi_list); Init (); } private void init () { Wifimanager = (wifimanager) Getsystemservice (context.wifi_service); Openwifi (); list = Wifimanager.getscanresults (); ListView listview = (ListView) Findviewbyid (r.id.listview); if (list = = Null) { Toast.maketext (this, "wifi is not turned on!" ", toast.length_long). Show (); }else { Listview.setadapter (new myadapte R (this,list)); } &NBSP;&NBsp } /** &nbs p;* Open wifi */ private void Openwifi () { &NBS P;if (!wifimanager.iswifienabled ()) { wifimanager.setwifienabled (true); } } public class Myadapter extends Baseadapter { Layoutinflater inflater;   ; List<scanresult> List; public myadapter (context context, list<scanresult> List) { &NB Sp //TODO auto-generated constructor stubs This.inflater = Layoutinflater.from (context); this.list = lisT } @Override &NB Sp public int GetCount () { //TODO auto-generated method stub &N Bsp return list.size (); } @Override &NB Sp Public Object GetItem (int Position) { //TODO auto-generated method Stub & nbsp; return position; } @Override &NB Sp Public long Getitemid (int Position) { //TODO auto-generated method stubs & nbsp; return position; } &nbsP @Override public View getView (int position, View convertview, viewgroup Parent) { //TODO auto-generated method stubs &NBS P View view = null; view = Inflater.inflate (r.layout.item_wifi_list, null); Scanresult Scanresult = List.get (position); TextView TextView = (TextView) View.findviewbyid (r.id.textview); Textview.settext (scanresult.ssid); TextView signalstrenth = (TextView) View.findviewbyid (r.id.signal_ strenth); Signalstrenth.settext (string.valueof (math.abs (scanresult.level)); ImageView ImageView = (ImageView) View.findvieWbyid (r.id.imageview); //determine signal strength, display the corresponding indicator icon if (Mat H.abs (scanresult.level) >) { Imageview.setimagedrawab Le (getresources (). getdrawable (r.drawable.stat_sys_wifi_signal_0)); } else if (math.abs (scanresult.level) >) { &NBSP ; imageview.setimagedrawable (getresources (). getdrawable (r.drawable.stat_sys_wifi_ signal_1)); } else if (math.abs (scanresult.level) >) { &NBSP ; imageview.setimagedrawable (getresources (). getdrawable (r.drawable.stat_sys_wifi_ signal_1)); } else if (math.abs (scanresult.level) >) { &NBSP ; ImageviEw.setimagedrawable (getresources (). getdrawable (r.drawable.stat_sys_wifi_signal_2)); } else if (math.abs (scanresult.level) >) { &NBSP ; imageview.setimagedrawable (getresources (). getdrawable (r.drawable.stat_sys_wifi_ signal_3)); } else { IMA Geview.setimagedrawable (getresources (). getdrawable (r.drawable.stat_sys_wifi_signal_4)); } return view; } } the program runs as Follows:<br> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Android WiFi tutorial WiFi list display</p></p></span>
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