我正在编写一个Android应用程序,其中purpouse是通过wifi指纹确定用户位置,为了做到这一点,我需要真正频繁(尽可能频繁)扫描现有网络,但我发现这样做的时间限制。
事实上,无论如何,我每秒钟都能得到一次新的扫描,我想知道是否有办法加快速度。
关于该主题的过去的问题(因为这个Android, wifi active scans)并没有真正有用。
这是代码:
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
}
答案 0 :(得分:2)
每单位时间可以获得的扫描数量有限制。接入点大约每100毫秒广播一个信标,因此这是您需要等待以确保检测它的时间。有12个频道,因此您必须花费至少100毫秒* 12 = 1.2秒才能确保您拥有所有接入点。以下任何内容都是不准确的。
答案 1 :(得分:1)
我还尝试通过wifi指纹确定用户位置。
在我的设备(Galaxy S2)上,我可以每六秒钟获得一次扫描结果。 我使用了主动扫描,但两次wifi扫描之间的间隔没有变化。 但是在我朋友的设备(HTC Desire)上,我可以每秒获得一次扫描结果。(使用相同的代码)
我认为扫描速度取决于设备。
如果您经常获得扫描结果,请告诉我。
答案 2 :(得分:0)
此代码可以通过WIFI + GPS找到位置(仅GPS很慢):
Finding current location works when using Wifi, but fails when using GPS
但另一方面,你可以考虑其他选项:
Android : How may ways I can get current location programatically