如何检测WiFi或GPRS信号强度是强还是弱 [英] How to detect Wifi or GPRS signal strength is strong or weak

查看:313
本文介绍了如何检测WiFi或GPRS信号强度是强还是弱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序中,我称之为web服务。我的问题是,如果我拨打电话到互联网服务和无线或GPRS强度较弱,那么我的应用程序强制关闭。我如何可以检测如果WiFi或GPRS信号强度是强还是弱?

I am developing an android application in which I call a webservices. My problem is that if I make a call to the webservice and the wifi or GPRS strength is weak, then my application force close. How can I detect if the wifi or GPRS signal strength is strong or weak?

推荐答案

首先,确保你有<使用许可权>对于ACCE​​SS_WIFI_STATE 在你的清单。

First, make sure you have <uses-permission> for ACCESS_WIFI_STATE in your manifest.

二,我不知道有关通知的单个连接,但把一切无线电是看到通知,就可以开始扫描:

Second, I'm not sure about notifications for a single connection, but to get notifications of everything the radio is seeing, you can start a scan:

wifi.startScan();

接下来,当我收到了成功的结果,我在IntentFilter的使​​用 WifiManager.SCAN_RESULTS_AVAILABLE_ACTION

然后,在接收器,我使用 getScanResults()从WifiManager对象,其中也包含了信号的强度。

Then, in the receiver, I use getScanResults() from the WifiManager object, which also contains the signal strength.

有关停止这种方式,您只需致电unregisterRecever()(所以你要围绕保持它引用)。我没有测试过自己,看看我的扫描code可以修改为只检查当前的连接,但我知道我有很多的结果 - Wi-Fi信号频繁和迅速改变。我想监视单个连接,您也可以只过滤扫描结果,寻找一个设备当前连接。

For stopping it this way, you simply call to unregisterRecever() (so you'll want to keep it around for referencing). I haven't tested myself to see if my scanning code can be modified to just check the current connection, but I do know I got plenty of results -- Wi-Fi signals change frequently and quickly. I suppose for monitoring a single connection, you can also just filter the scan results and look for the one the device is currently connected to.

我希望这有助于一点。

Android的无线网络的信号强度

<一个href=\"http://stackoverflow.com/questions/1206891/android-how-to-monitor-wifi-signal-strength\">Android:如何监视WiFi信号强度

这篇关于如何检测WiFi或GPRS信号强度是强还是弱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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