0

I'm working on Android app. and I'm using this code to get wifi results:

import java.util.ArrayList;
import java.util.List;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.widget.Toast;

public class WirelessNetworks  
{
    private static WifiManager wifi;
    private static List<ScanResult> results;
    private static WifiReceiver receiverWifi;
    private static Context context; 

    public static void Initial(Context cont)
    {
        context=cont;
        wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        receiverWifi=new WifiReceiver();
        context.registerReceiver(receiverWifi, 
                new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
        results=new ArrayList<ScanResult>();
    }

    public static void FindNetworks() 
    {
        wifi.startScan();
        results.clear();
        results=wifi.getScanResults();      
        int size = results.size()-1;
        while (size >= 0) 
        {
            String ssid=results.get(size).SSID;
            String mac=results.get(size).BSSID;
            int rssi=results.get(size).level;
            int band=results.get(size).frequency;           
            Globals.DB.insert(ssid, mac, rssi+"", band+"");
            size--;             
        } 
    }


    public static class WifiReceiver extends BroadcastReceiver
    {
        @Override
        public void onReceive(Context context, Intent intent) 
        {           

        }
    }
}

This function "FindNetworks()" called each 1000 milliseconds. The problem is the same results redundancy every 3 or 4 times, I think should increase the interval calling to 4000 milliseconds. But this is problem for my app. There is way to get new WIFI readings each 1000 milliseconds immediately?

bebosh
  • 806
  • 10
  • 25

1 Answers1

1

Update: From tests in Android 4.4 and 5.0 the interval between sequential WiFi scans seems to be less than a second. If that is the case, then you can use a count down timer to get wifi results as often as you want after you first determine your minimum time needed between each scan. Beware that may be differs from device to device so keep a meaningful time window. You can take a look at my demo for RF measurements using Android device, here:

https://github.com/panosvas/Measurements

It seems that each WiFi measurement takes approximately 5 seconds based on each device. So, by taking quicker results it is almost sure that you will obtain duplicates of the same measurements. In order to obtain measurements each second you have probably to change the driver which I don't know how easy that could be. You can also see my answers in the following posts:

https://stackoverflow.com/questions/25819271/actively-pulling-wifi-power-information/27014012#27014012

Android Getting WiFi signal strength as it changes

Community
  • 1
  • 1
Panos
  • 212
  • 1
  • 12