有没有一种方法来明确控制WiFi扫描间隔的Andr​​oid? [英] Is there a way to explicitly control WiFi scan intervals in Android?

查看:267
本文介绍了有没有一种方法来明确控制WiFi扫描间隔的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做我的硕士论文在对无线定位的时刻,为了测试我的算法,我需要收集一些数据。

要做到这一点,我已经写了Android的一个短,很简单的程序,它简单地收集RSSI的每个扫描中发现的所有菱接入点,并将它们保存到文件。我已成立了一个的BroadcastReceiver 侦听事件 WifiManager.SCAN_RESULTS_AVAILABLE_ACTION 我用一个定时器,这里叫做恬,启动与 WifiManager ,称无线扫描如下:

  tim.schedule(新的TimerTask(){
        @覆盖
        公共无效的run(){
            wifi.startScan();
        }
},0,1000);
 

现在我遇到的问题是,启动的扫描似乎没有,即使我成功地启动它们,时不时有来自被记录的,以及一些其他的应用程序启动其他扫描发生的每一秒。

有没有简单的方法来扫描一组间隔不接收其他应用程序启动扫描?

在整个应用程序可以在 https://github.com/while/RSSIMiner 发现,如果它有助于以任何方式。

解决方案
  

有没有简单的方法来对一组间隔扫描?

如果这个不顺利,恐怕不行。从我的经验,硬件相关的方法可能无法正常工作完全像他们的定义说。例如,有一次我创建了一个小型应用程序,它会记录你的位置,每隔X分钟。所以,我呼吁 requestLocationUpdates 一些 minTime 参数。但是,我的手机会忽略 minTime 的价值,我也得到更新,从GPS只要他们可用,whcih是不是我想要的。我发布了一个关于它的问题在这里,并得到了这个回答,从中我们了解到,之前果冻豆,设备可以简单地忽略此值...

于是的也可能是类似现在的东西。我想尝试运行在最新的Andr​​oid版本code。我不明白,在无线多​​,而不是1秒过于频繁的间隔扫描?或许,系统不忽略扫描请求(所以它返回),但硬件呢?

  

我们可以忽略一些其他的应用程序启动扫描?

据我所知,这是消极的这里。有没有包含在 SCAN_RESULTS_AVAILABLE_ACTION 广播,所以你可以不知道哪个应用程序启动扫描花絮。

最好的解决方案将是defnie您的要求。您可以使用 ScanResult.timestamp 来确定是否应该使用这个结果还是不行。例如,如果你想获得RSSI为每个接入点的每一秒,你可以比较当前的BSSID为previous的BSSID。如果当前的BSSID被包括在从最后一秒扫描结果,你可以简单地忽略它。然后,它并不重要,你有多少结果得到的。

另外,要简单得多soltuion将创建一个名为布尔 scanInitiated 键,将其设置为启动时扫描。当接收到broacast,使用的数据只有当 scanInitiated ,然后将其设置为。这不是那么可靠的时候,时间间隔很短,但对于长的时间间隔,将工作的伟大。

I am doing my Master thesis at the moment on WiFi positioning and in order to test my algorithms I needed to collect some data.

To do this I have written a short and very simple program for Android which simply collects the RSSI for all availible access points found by each scan and saves them to file. I have set up a BroadcastReceiver that listens on the event WifiManager.SCAN_RESULTS_AVAILABLE_ACTION and I use a Timer, here called tim, to initiate scans with a WifiManager, called wifi as follows:

tim.schedule(new TimerTask(){
        @Override
        public void run(){
            wifi.startScan();
        }
}, 0, 1000);

The problem I am having now is that the initiated scans don't seem to happen every second even if I succeed in initiating them and every now and then there are other scans initiated from some other app that gets recorded as well.

Is there any easy way to scan on a set interval and not receive the scans initiated by some other app?

The whole app can be found on https://github.com/while/RSSIMiner if it helps in any way.

解决方案

Is there any easy way to scan on a set interval?

If this doesn't work well, I'm afraid not. From my experience, "hardware related" methods may not work exactly like their definition says. For example, I once created a small app which records your position every X minutes. So I call requestLocationUpdates with some minTime parameter. But my phone simply ignores the minTime value, and I get updates from the GPS as soon as they're available, whcih is not what I wanted. I posted a question about it here, and got this answer, from which we learn that prior to jelly bean, devices may simply ignore this value...

So it may be something similar now. I'd try to run this code on the latest Android version. And I don't understand that much in Wifi, but isn't 1 second a too frequent interval for scans? Perhaps the system doesn't ignore the scan request (So it returns true) but the hardware does?

Can we ignore the scans initiated by some other app?

As far as I know, it's negative here too. There are no extras contained in the SCAN_RESULTS_AVAILABLE_ACTION broadcast so you can't know which app initiated the scan.

The best solution will be to defnie your requirements. You can use the ScanResult.timestamp to determine if you should use this result or not. For example, if you're trying to get the RSSI for each access point each second, you can compare the current BSSID to previous BSSIDs. If the current BSSID was included in a scan result from the last second, you can simply ignore it. Then, it doesn't matter how many results you get.

Another, much more simple soltuion will be to create a boolean called scanInitiated and set it to true when starting a scan. When receiving the broacast, use the data only if scanInitiated is true, and then set it to false. This isn't so reliable when the intervals are short, but for long intervals it will work great.

这篇关于有没有一种方法来明确控制WiFi扫描间隔的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆