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?
-
What's the point in detecting this? You'd better take a good look at the error and figure out a way to fix/handle it. – THelper Dec 14 '11 at 12:52
-
i only want to call webservices if Wifi or GPRS signal strength is strong .if Wifi or GPRS signal strength is weak,then it will give message"Internet connection is low" – Atul Chambyal Dec 14 '11 at 13:04
-
And what if the signal drops right after you have checked it's strength? – THelper Dec 14 '11 at 13:17
1 Answers
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();
Next, when I've received successful results, I used WifiManager.SCAN_RESULTS_AVAILABLE_ACTION
in the IntentFilter.
Then, in the receiver, I use getScanResults()
from the WifiManager object, which also contains the signal strength.
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.
I hope this helps a little.

- 1
- 1

- 19,893
- 17
- 73
- 130