Search code examples
androidandroid-wifiwifimanager

Reducing delay between two wifi scans


I'm writing an android application which purpouse is to determine the user position via a wifi fingerprint, and in order to do that i need to get really frequent (as frequent as possible) scansions of present networks but I've found time limitations to do that.

In fact, no matter what, I can get a new scan roughtly every second and I was wondering if there could be a way to speed things up.

Past questions on the topic (as this one Android, wifi active scans) were not really useful.

here's the code:

public class WiFiScanReceiver extends BroadcastReceiver {
    private static final String TAG = "WiFiScanReceiver";
    private Main parent;
    private ScanResult storedBest;
    private String actualFileName;
    private int nOfScans;
    private long initialTime;
    private FileSaver fs;

    public WiFiScanReceiver(Main wifiDemo) {
        super();
        this.parent = wifiDemo;
        storedBest = null;
        actualFileName ="";
        nOfScans = 0;
        fs = new FileSaver(parent);
    }

    @Override
    public void onReceive(Context c, Intent intent) {
        List<ScanResult> results = parent.getWifiManager().getScanResults();
        ScanResult bestSignal = null;
        if(parent.isRecording()&& actualFileName!=""){

        //Getting the fingerprint
        }

        if (parent.isRecording()) nOfScans ++;
        parent.getWifiManager().startScan();
        Log.d(TAG, "onReceive() message: " + message);
    }
    //VARIOUS GETTERs AND SETTERs

}

Solution

  • There is a limit on how many scans you can get per unit of time. An access point broadcasts a beacon roughly every 100 ms, so that is the time you need to wait to be sure to detect it. There are 12 frequency channels so you have to spend at least 100ms*12 = 1.2s in order to be sure that you have all the access points. Anything below that will be inaccurate.