希望大家能够给个评论,支持下新人,感激不尽。

本文第一篇CSDN博客,欢迎大家关注,如有错误,欢迎批评指正。

本人在做WIFI室内定位时发现Android扫描WIFI的时延不小。在此先附上我扫描wifi的代码,然后分析扫描时延和原因。

package com.upc.xin.rssi.methods;import android.content.Context;import android.net.wifi.ScanResult;import android.net.wifi.WifiInfo;import android.net.wifi.WifiManager;import com.upc.xin.rssi.data.DataRepertory;import java.util.List;import android.os.Handler;/** * Created by xin on 2017/11/27. *///wifi扫描线程public class RssiScanfer extends Thread {    private WifiManager wifiManager;    private WifiInfo wifiInfo;    private List wifiList;    private Boolean Flag = true;    private Handler ui_Handler;    /*构造函数,获取activity的context和UI刷新handler*/    public RssiScanfer(Context context, Handler handler) {        Flag = true;        wifiManager = (WifiManager) context                .getSystemService(Context.WIFI_SERVICE);        wifiInfo = wifiManager.getConnectionInfo();        ui_Handler = handler;    }    /*扫面wifi进程,每1秒扫一次*/    public void run() {        while (Flag) {            wifiManager.startScan();            wifiList = wifiManager.getScanResults();            String txtContent = "";            DataRepertory.infoString = "info:时间-" + FunctionMethods.GetTime() + "," + DataRepertory.FilePath + "\r\n";            for (ScanResult sr : wifiList) {                DataRepertory.infoString += sr.BSSID + "," + sr.frequency + "," + sr.level + "\r\n";                txtContent += sr.BSSID + "," + sr.frequency + "," + sr.level + "\r\n";            }            txtContent += "%\r\n";            FunctionMethods.AddStringIntoText(txtContent, DataRepertory.RssiTextFile);            try {                ui_Handler.sendEmptyMessage(0x123);                Thread.sleep(1000);            } catch (InterruptedException e) {                e.printStackTrace();            }        }    }    public void Finish() {        Flag = false;    }}

代码中扫描时间间隔为1s。(记得Android 4.0的时候貌似还获取不到WIFI的频率等信息,本人用的小米5x,现在Android7.0就可以获取到频率等更多信息了。)

https://stackoverflow.com/questions/7969174/reducing-delay-between-two-wifi-scans

这是stackoverflow中的一个时延问题,评论有一大神回答的很好。

There is a limit on how many scans you can get per unit of time. An access point broadcasts a beacon roughly every 100 ms, so that is the time you need to wait to be sure to detect it. There are 12 frequency channels so you have to spend at least 100ms*12 = 1.2s in order to be sure that you have all the access points. Anything below that will be inaccurate.(每个单位时间扫描的次数是有限制的,每个接入点即WIFI广播信标周期大约为100毫秒,所以你得等待100毫秒去检测。当有12个个频率信道,你需要花费100ms*12=1.2s的时间去扫描所有接入点。如果扫面周期小于1.2s,则扫描结果是不准确的。)

由于美国和中国的WIFI 信号不同,

美洲(FCC)

2.412 ~ 2.462 GHz:11个信道

5.15 ~ 5.35 GHz,5.725 ~ 5.825 GHz;12个信道

中国

2.412 ~ 2.472 GHz:13个信道

5.725 ~ 5.825 GHz:4个信道

小米5X是支持频段的,所以最小周期应该是100ms*17=1.7s。

本人用小米5x进行下测试,单位秒:3,10,10,6,10,9,13,10,10,12,13。

可见扫描时延不是固定的,但是在10s左右,运气好有可能3秒就会扫描到。

更多相关文章

  1. android手机刷机教程
  2. 【Android】 桌面图标右上角显示数字(角标)
  3. 开发技术前线 第六期
  4. Android周学习Step By Step(9)--Intent之广播(完)
  5. Android开发之蓝牙(Bluetooth)操作(二)--修改本机蓝牙设备的可见
  6. 【转】【Android游戏开发十五】关于Android(安卓)游戏开发中 OnT
  7. Android使用枚举单例实现Toast快速刷新(自定义吐司)
  8. wifi 架构
  9. 在 Kindle Fire 小米2 上调试 android 应用 mac os 下

随机推荐

  1. 虚拟机安装Linux复盘
  2. SpringBoot配置加载原理全面解析
  3. 学习第三周
  4. 干货 | 万字详解整个数据仓库设计体系
  5. 内部类
  6. Volatile原理概述
  7. HTML中表格和表单的应用实例
  8. RPC实战与核心原理
  9. 分布式数据库30讲
  10. CSS选择器优先级+模块化+伪类选择器