我正在開發Android應用。我正在使用此代碼獲得無線網絡結果:在Android中查找帶有特定時間間隔的WIFI結果
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)
{
}
}
}
此函數「FindNetworks()」每1000毫秒調用一次。 問題是相同的結果冗餘每3或4次,我認爲應該增加間隔調用到4000毫秒。 但這是我的應用程序的問題。 有沒有辦法立即獲得每1000毫秒新的WIFI讀數?
感謝您的幫助:) – bebosh