Get Signal Strength of Scanned Wifi Networks. I'm working with fragments here, so you can change if you want for Activity accordingly.
WifiManager mWifiManager; WifiReceiver mWifiReceiver; List wifiList; @Override public void onAttach(Activity activity) < super.onAttach(activity); mWifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); if (!mWifiManager.isWifiEnabled()) < // If wifi disabled then enable it Toast.makeText(getActivity(), "wifi is disabled..making it enabled", Toast.LENGTH_LONG).show(); mWifiManager.setWifiEnabled(true); >mWifiReceiver = new WifiReceiver(); IntentFilter mIntentFilter = new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); mIntentFilter.addAction(WifiManager.RSSI_CHANGED_ACTION); getActivity().registerReceiver(mWifiReceiver, mIntentFilter); mWifiManager.startScan(); > public void onPause() < getActivity().unregisterReceiver(mWifiReceiver); super.onPause(); >public void onResume() < getActivity().registerReceiver(mWifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); super.onResume(); >class WifiReceiver extends BroadcastReceiver < // This method call when number of wifi connections changed public void onReceive(Context c, Intent intent) < int state = mWifiManager.getWifiState(); int maxLevel = 5; if (state == WifiManager.WIFI_STATE_ENABLED) < // Get Scanned results in an array List wifiList = mWifiManager.getScanResults(); // Iterate on the list for (ScanResult result : wifiList) < //The level of each wifiNetwork from 0-5 int level = WifiManager.calculateSignalLevel( result.level,maxLevel); String SSID = result.SSID; String capabilities = result.capabilities; // TODO add your own code. >> > >
You need to add permissions
Linked
Hot Network Questions
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник
Getting WiFi signal strength in Android
It gives negative value. When we see the default system WiFi setting and clicked on the connected WiFi network, it gives "Good" or "Bad" as signal strength. What is the range that we can filter those negative vales as "Good" signal strength or "Bad" signal strength?
Yes, that is true. What I need is a standard range that I can apply for my own WiFi handling Android app. When I click on the connected WiFi network on a real device, it gives me "Good" as Signal strength. I want to know how they measure it as a "Good" strength. Thanks for the reply.
7 Answers 7
its an old post but this might help someone.
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int numberOfLevels = 5; WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
Please check how dBm values for received Wireless Signal power are represented.
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); // Level of a Scan Result List wifiList = wifiManager.getScanResults(); for (ScanResult scanResult : wifiList) < int level = WifiManager.calculateSignalLevel(scanResult.level, 5); System.out.println("Level is " + level + " out of 5"); >// Level of current connection int rssi = wifiManager.getConnectionInfo().getRssi(); int level = WifiManager.calculateSignalLevel(rssi, 5); System.out.println("Level is " + level + " out of 5");
Hi @se_bastiaan the max level is 4 & min level is 0 (therefore 5 levels). Your log will never read "5 out of 5".
Yes, exactly. This is how dBm values for received signal power are represented. Here are some details at Wikipedia.
-100 means lowest value (no signal at all), and 0 means extremely good signal (100%)
@Thomas what a nonsense. Did you even check linked Wikipedia page or try to research it yourself before making this statement?
Unlinke you I seem to know a little bit more about wireless system it seems, otherwise you wouldn't have written "non-sense". Your Wikipedia link only lists the transmit power of radio stations and so on. Also -100 isn't the lowest value . GSM for example still works below -100 dBm.
I downvoted this now because this answer about the received signal strength (RSSI) is totally wrong. Please do some research. This answer here: stackoverflow.com/a/33689523/1392778 is correct.
RSSI = -100 does NOT mean no signal. It means received signal power is 100 dB below 1 mW. Yes, this may mean practically a useless signal. No, this does NOT mean "no signal". Similarly, extremely good signal does not mean 100%. There is no defined 100% signal. 100 % of what? Four bars out of four is just a GUI, but does not mean "100%". This answer is not useful. -1
Источник
Android: How to monitor WiFi signal strength
I would receive notifications when signal strength changes. I tried to create the following method and call it in the onCreate():
private void initializeWiFiListener() < Log.i(TAG, "executing initializeWiFiListener"); String connectivity_context = Context.WIFI_SERVICE; final WifiManager wifi = (WifiManager)getSystemService(connectivity_context); if(!wifi.isWifiEnabled())< if(wifi.getWifiState() != WifiManager.WIFI_STATE_ENABLING)< wifi.setWifiEnabled(true); >> registerReceiver(new BroadcastReceiver() < @Override public void onReceive(Context context, Intent intent) < WifiInfo info = wifi.getConnectionInfo(); //TODO: implement methods for action handling >>, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION)); >
I would appreciate if anyone could check if the method is written correctly. I tried to run the app, but haven't received any notifications and am not sure whether it is because the signal strength might be constant in the place I run debug or it is because something is missing. Thanks!
2 Answers 2
First, make sure you have 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:
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.
Источник
How to get the connection strength of Wifi access points?
I am building an application reading the signal strength of each available Wifi access point. I've written code like:
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); // Get WiFi status WifiInfo info = wifi.getConnectionInfo(); textStatus.append("\n\nWiFi Status: " + info.toString()); // List available networks List configs = wifi.getConfiguredNetworks();
- In debugging, configs only contains one connection. However, I can see that there are several APs available in the system's wifi setting. I.e. configs is an incomplete list.
- I don't know how to get the signal strength in WifiConfiguration .
btw, I am using HTC Hero and Android 1.5.
5 Answers 5
According to the Android API documentation WifiManager.getConfiguredNetworks() does not fill the signal strength paramters. This data only represents the remembered access point settings, not the visible ones.
To get actually visible networks you must call WifiManager.startScan() to initiate WiFi radio scanning and WifiManager.getScanResults() after a while to get the scanning results.
It's usually 2-10 seconds (but no restrictions are implied really). But keep in mind, you may miss some visible access points if you scan for too short. Wi-Fi access points are detected by special broadcast packets (so called "beacons") which are emitted periodically. Scanning for access points actually means listening for the beacons and collecting them. wi-fiplanet.com/tutorials/article.php/1492071
There is no synchronous function for the whole process. Though you may just call getScanResults() to get results of a previous scan performed by the system. Maybe that results are fresh enough for your purpose. However I won't expect it to be good if you have an active WiFi connection - I think the Android system components don't run scans when a good connection is present. There is just no reason to do that.
Thanks for the replies, I am actually writing a simple app to record wifi perception around the site. So, user has a single button and as he/she presses the button wifi access point perceptions are recorded into a database. With such a mechanism, on every button press the user should stand still for a few seconds.
Calling a synchronous function isn't a good solution anyway. Android will show the ANR (Application Not Responding) warnings for your application if you block for too long in the UI thread. Consider disabling the button during a scan process, that fits the event-based UI model better.
Источник