android - Wait until startScan finish the scan -
i've question using wifimanger in application. code quite simple, i've created service, scans network available wifi:
@override public int onstartcommand(intent intent, int flags, int startid) { mapname = intent.getextras().getstring("mapname"); sendnotification(); mainwifi = (wifimanager) getsystemservice(context.wifi_service); // check wifi disabled if (!mainwifi.iswifienabled()) { // if wifi disabled enable toast.maketext(getapplicationcontext(), "wifi disabled..making enabled", toast.length_long).show(); mainwifi.setwifienabled(true); } mainwifi.startscan(); list<scanresult> scanresults=mainwifi.getscanresults(); readaps=getaps(scanresults); //list of ap received in current position string result=comparerp(); if(!result.isempty()) toast.maketext(this, "localized in rp: "+result, toast.length_long).show(); else toast.maketext(this, "unable localize in map", toast.length_long).show(); homecoming start_not_sticky; } private arraylist<accesspoint> getaps(list<scanresult> scanresults) { arraylist<accesspoint> temp = new arraylist<accesspoint>(); for(scanresult s:scanresults){ temp.add(new accesspoint(s.ssid,s.level,s.frequency)); } homecoming temp; }
how can add together condition: want wait "fresh" wifi list, comes when:
mainwifi.startscan();
method returns.
now service still go on cluster matching algorithm, , don't want it. i've do?
thanks kind of help!
fred
you have utilize broadcastreceiver
within activity.
private final broadcastreceiver mwifiscanreceiver = new broadcastreceiver() { @override public void onreceive(context c, intent intent) { // status not necessary if hear 1 action if (intent.getaction().equals(wifimanager.scan_results_available_action)) { list<scanresult> mscanresults = mwifimanager.getscanresults(); toast.maketext(getapplicationcontext(), "scan results available", toast.length_long).show(); // want } } }; private wifimanager mwifimanager; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mwifimanager = (wifimanager) getsystemservice(context.wifi_service); intentfilter intentfilter = new intentfilter(); intentfilter.addaction(wifimanager.scan_results_available_action); // can add together multiple actions... registerreceiver(mwifiscanreceiver, intentfilter); // ... mwifimanager.startscan(); }
android wifimanager indoor-positioning-system
No comments:
Post a Comment