如何在 WifiManager 中定期使用 StartScan() 以便在可用后立即捕获 WIFI 点?

How to periodically use StartScan() in WifiManager so that I can catch a WIFI spot immediately after it is available?

我希望能够检测附近是否有WIFI热点。我使用 WifiManager.startScan() 方法,我可以发出 SCAN_RESULTS_AVAILABLE_ACTION 意图开火,并且我可以通过 WifiManager.getScanResults() 获得 Wifi 点结果,但这种情况只会发生一次。例如,附近有名为 A、B、C 的 wifi 点。我打电话给 WifiManager.startScan(),我找到了 wifi 点 A、B、C。但是,在这之后,如果附近出现另一个名为 D 的 wifi 点,我将看不到它。在这种情况下,我怎样才能捕捉到 wifi 点 D?我在下面相关的代码。我将不胜感激你的帮助。

    tManager.startScan();
if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action)) {
            Log.i("WiFiDirectBrdcastRcvr", "FOUND WIFI SPOT");
            List<ScanResult> wifiScanList = tManager.getScanResults();
            wifis = new String[wifiScanList.size()];
            Log.i("WiFiDirectBrdcastRcvr", "Device found " + wifiScanList.size()+" WIFI spots");
            for(int i = 0; i < wifiScanList.size(); i++){
                wifis[i] = ((wifiScanList.get(i)).toString());
                Log.i("WiFiDirectBrdcastRcvr", "Spot" + i + " is: " + wifis[i]);
            }
        }

将您的开始扫描码放入处理程序

private Handler handler = new Handler() 
{ 
   @Override public void handleMessage(Message message) 
   { 

   } 
} ); 
Handler h=new Handler();
h.postDelayed(new Runnable() {
    @Override
    public void run() {
        WifiManager.startScan();  
    }
},20000);