I’m trying to scan some access points with class WifiManager (StartScan), this scan occur in a touch event but it just makes one scan in each touch. The problem is that I need make this process 10, 20 or the number that I want times; however I don’t know how I can do this. Because I thought that with one for cycle was enough but this method doesn’t work to me.
This is my onTouch method and I need that every time that I touch the screen it repeats 10 times
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
WifiManager w = (WifiManager) getSystemService(Context.WIFI_SERVICE);
texto.setLength(0);
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
texto.append("down"; posx:(double) event.getX(); posy:(double) event.getY();
w.startScan();
break;
}
return false;
}
I tried with the next for cycle but didn’t work me
for(int i=1;i <= 10;i++){
w.startScan();
}
You need to request the scan and then wait for the results in a BroadcastReceiver , something like this:
When the Scan has finished you can then request a scan again (in the BroadcastReceiver) keeping a counter to make sure you only do it ten times.
Your current code is requesting 10 scans within the time it takes to complete the initial scan so all subsequent scan requests are ignored.