I am developing wifi indoor positioning app for my research study. I get the attached wifi scan service and the broadcast receiver from https://github.com/Talentica/WifiIndoorPositioning to get the wifi scan result and use it to get indoor location. My problem is the wifi scan results do not udate with moving from place to other with time, it seems give the privous scan result not new list. how can I edit it to get actual updated scan results with time
public class WifiService extends Service {
private final String TAG = "WifiService";
WifiConfiguration wifiConfiguration = new WifiConfiguration();
private WifiManager mWifiManager;
private ScheduledFuture<?> scheduleReaderHandle;
private ScheduledExecutorService mScheduler;
private WifiData mWifiData;
private long initialDelay = 0;
private long periodReader = AppContants.FETCH_INTERVAL;
List<ScanResult> mResults;
/**
* It creates a new Thread that it is executed periodically reading the last
* scanning of WiFi networks (if WiFi is available).
*/
@Override
public void onCreate() {
Log.d(TAG, "WifiService onCreate");
mWifiData = new WifiData();
mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
mScheduler = Executors.newScheduledThreadPool(1);
scheduleReaderHandle = mScheduler.scheduleAtFixedRate(new ScheduleReader(), initialDelay, periodReader,
TimeUnit.MILLISECONDS);
mResults = new ArrayList<ScanResult>() {};
}
/**
* Kills the periodical Thread before destroying the service
*/
@Override
public void onDestroy() {
// stop read thread
scheduleReaderHandle.cancel(true);
mScheduler.shutdown();
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
/**
* Performs a periodical read of the WiFi scan result, then it creates a new
* {@link WifiData ()} object containing the list of networks and finally it
* sends it to the main activity for being displayed.
*/
class ScheduleReader implements Runnable {
@Override
public void run() {
if (mWifiManager.isWifiEnabled()) {
mResults = mWifiManager.getScanResults();
Log.d(TAG, "New scan result: (" + mResults.size() + ") networks found");
// store networks
mWifiData.addNetworks(mResults);
// send data to UI
Intent intent = new Intent(AppContants.INTENT_FILTER);
intent.putExtra(AppContants.WIFI_DATA, mWifiData);
LocalBroadcastManager.getInstance(WifiService.this).sendBroadcast(intent);
mResults.clear();
}
}
}
}
public class MainActivityReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NumberFormat formatter = new DecimalFormat("#0.0000");
mWifiData = (WifiData) intent.getParcelableExtra(AppContants.WIFI_DATA);
if (mWifiData.getNetworks().size() != 0) {
List<WifiDataNetwork> latestScanList = mWifiData.getNetworks();
LocationWithNearbyPlaces loc = AlgorithmTxtDb.processingAlgorithms(fingerprintRefPointsList, routersList, latestScanList, 2);
}
}
public class MainActivityReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NumberFormat formatter = new DecimalFormat("#0.0000");
mWifiData = (WifiData) intent.getParcelableExtra(AppContants.WIFI_DATA);
if (mWifiData.getNetworks().size() != 0) {
List<WifiDataNetwork> latestScanList = mWifiData.getNetworks();
LocationWithNearbyPlaces loc = AlgorithmTxtDb.processingAlgorithms(fingerprintRefPointsList, routersList, latestScanList, 2);
}
}
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWifiData = null;
// set receiver
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter(AppContants.INTENT_FILTER));
// launch WiFi service
wifiServiceIntent = new Intent(this, WifiService.class);
startService(wifiServiceIntent);
// recover retained object
mWifiData = (WifiData) getLastNonConfigurationInstance();
}
The problem comes from android 9.0 The latest version of android (android 9 (Pie)) had a new restrictions and limitations for WIFI scanning, as it is documented by android. They add throttling for the scan intervals for both of foreground and background scenarios to save the power consumption. Android 9 and later: Each foreground app can scan four times in a 2-minute period. This allows for a burst of scans in a short time. All background apps combined can scan one time in a 30-minute period. android wifi scan The following links represent the response of this throttling: links represent the response of this throttling, link 2, link 3, link 4