broadcastreceiver - Android wait for WiFi scan to finish -
i'm trying wait wifi scan finish in broadcast receiver!.
i have 1 activty (chooseactivity extends activity) , 1 class (scan).
in activity call scan class scan wifi , return boolean (true) when finish, here code.
my purpose separate scan of activity because call scan class in several places.
public class chooseactivity extends activity implements onclicklistener{ private int idmap; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.activity_choose); idmap = this.getintent().getextras().getint("id_map"); ((button)this.findviewbyid(r.id.scan_button)).setonclicklistener(this); } @override public void onclick(view v) { // todo auto-generated method stub switch(v.getid()){ case r.id.scan_button: scan scan = new scan(); toast.maketext(getapplicationcontext(), " "+scan.scanhotspots(idmap), toast.length_short).show(); break; } } }
and here scan class
public boolean scanhotspots(int idmap){ wifimanager = (wifimanager)context.getsystemservice(context.wifi_service); wifimanager.startscan(); receiver = new receiver(); intentfilter intentfilter = new intentfilter(wifimanager.scan_results_available_action); context.registerreceiver(receiver, intentfilter); //here want stop execution wait test vairable change status return test; } public class receiver extends broadcastreceiver{ @override public void onreceive(context context, intent intent) { // todo auto-generated method stub if(intent.getaction().equals(wifimanager.scan_results_available_action)) { test=true; } } } }
thank in advance.
Comments
Post a Comment