How to scan wifi networks in android programming? -


this question has answer here:

i want know how scan wifi networks in android programming. i'm beginner.

public class wifidemo extends activity implements onclicklistener  {           wifimanager wifi;            listview lv;     textview textstatus;     button buttonscan;     int size = 0;     list<scanresult> results;      string item_key = "key";     arraylist<hashmap<string, string>> arraylist = new arraylist<hashmap<string, string>>();     simpleadapter adapter;      /* called when activity first created. */     @override     public void oncreate(bundle savedinstancestate)      {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          textstatus = (textview) findviewbyid(r.id.textstatus);         buttonscan = (button) findviewbyid(r.id.buttonscan);         buttonscan.setonclicklistener(this);         lv = (listview)findviewbyid(r.id.list);          wifi = (wifimanager) getsystemservice(context.wifi_service);         if (wifi.iswifienabled() == false)         {             toast.maketext(getapplicationcontext(), "wifi disabled..making enabled", toast.length_long).show();             wifi.setwifienabled(true);         }            this.adapter = new simpleadapter(wifidemo.this, arraylist, r.layout.row, new string[] { item_key }, new int[] { r.id.list_value });         lv.setadapter(this.adapter);          registerreceiver(new broadcastreceiver()         {             @override             public void onreceive(context c, intent intent)              {                results = wifi.getscanresults();                size = results.size();             }         }, new intentfilter(wifimanager.scan_results_available_action));                         }      public void onclick(view view)      {         arraylist.clear();                   wifi.startscan();          toast.maketext(this, "scanning...." + size, toast.length_short).show();         try          {             size = size - 1;             while (size >= 0)              {                    hashmap<string, string> item = new hashmap<string, string>();                                        item.put(item_key, results.get(size).ssid + "  " + results.get(size).capabilities);                  arraylist.add(item);                 size--;                 adapter.notifydatasetchanged();                              }          }         catch (exception e)         { }              }     } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -