仅在2.4Ghz频段中扫描wifi信号 [英] Scanning for wifi signals only in 2.4Ghz band

查看:134
本文介绍了仅在2.4Ghz频段中扫描wifi信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要扫描可用的Wi-Fi信号及其强度.我正在使用 wifiManager.startScan(); 和异步 wifiManager.getScanResult(); .

I need to scan for available Wi-Fi signals and their strengths. I'm using wifiManager.startScan(); and asynchronous wifiManager.getScanResult();.

在不支持5GHz频段的设备上,大约需要500毫秒才能获得结果;在不支持5GHz频段的设备上,大约需要2s的时间,这对我来说太过分了.我想1.5s的延迟是在搜索整个5GHz频段.

On devices without support of 5GHz band it takes about 500ms to get the results, on devices with 5GHz band support it takes about 2s, and that is too much for me. I guess the 1.5s delay is in searching the whole 5GHz band.

我是否可以通过某种方式告诉设备仅在2.4GHz频段内进行扫描,或者可以通过其他方式(例如通过NDK)更快地获得结果?我搜索了整个网络,却一无所获,所以我想这是唯一的方法.

Is there any way I could tell the device to scan only in the 2.4GHz band, or any other way I could get the results faster (for example through NDK)? I searched through the entire web and found nothing, so I guess this is the only way.

谢谢.

推荐答案

注意:这些api已从Android Nogut版本中删除.适用于棉花糖

NOTE: These api's are removed from Android Nogut version. Applicable till Mashmallow

/**
 * Auto settings in the driver. The driver could choose to operate on both
 * 2.4 GHz and 5 GHz or make a dynamic decision on selecting the band.
 * @hide
 */
public static final int WIFI_FREQUENCY_BAND_AUTO = 0;

/**
 * Operation on 5 GHz alone
 * @hide
 */
public static final int WIFI_FREQUENCY_BAND_5GHZ = 1;

/**
 * Operation on 2.4 GHz alone
 * @hide
 */
public static final int WIFI_FREQUENCY_BAND_2GHZ = 2;

使用WifiManager.java的上述常量部分来设置所需的频带.我们可以使用API​​ setFrequencyBand(int mode,booleanpersist)设置频率.这些是隐藏的API.

Use above constants part of WifiManager.java, to set the required frequency bands. And we can set frequency with API setFrequencyBand(int mode, boolean persist). These are hidden API's.

代码段:

WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);

// To scan only 2.4 GHz Frequency band

// true, if this needs to be remembered

wm.setFrequencyBand(2, false);

// Start scan.

wm.startScan();

// To get the frequency band used.

int band = wm.getFrequncyBand();

这篇关于仅在2.4Ghz频段中扫描wifi信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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