I have been trying to create an android application that will give me the signal strength of my home access point from a wireless device e.g. laptop, mobile phone. I have been pulling my hair out with it the last few days and been getting no where. Can someone please give a hand with this because it is really getting on my nerves :( all I want it to do at the minute is display the strength in the console for me, it sounded pretty simple and I have read countless articles and have got nowhere at all :(
You can get the dbm value using WifiManager.
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if(wifiManager.isWifiEnabled()) {
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if(wifiInfo != null) {
int dbm = wifiInfo.getRssi();
}
}
In addition to dbm, if you wish to get the percentage about the signal strength:
int strengthInPercentage = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 100);
Related
How can I get the direction and the strength of all the nearby Wifi ?
Till now I have been able to get Wifi Strength in Level but only of connected wifi using following code
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
int numberOfLevels = 5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
I am trying to do something like this
Play Store App Link
This app gives nearby wifi plot on campas
Can anyone guide my how this is possible?
Short answer "not possible".
Long answer is that the phone gives just the strength of the incoming signal, which can come from any direction. You can not even estimate the distance to the WiFi access point until you know its signal strength with your phone for some known distance. You can however estimate the direction of where the WiFi access point is from movement of your phone and the differences of the WiFi signal strength changes.
The app you linked to tells you to start scanning and then slowly rotate. That is needed for recording the device orientation and the signal strength changes. Then based on the orientation of the device and the signal strength for that orientation it can estimated where the WiFi access point is. I am not connected with that app in any way, nor I have used it. All this information is based on the app's screenshots and general knowledge of how WiFi works.
Then there are other funny things like WiFi access points which can send a stronger signal in a specific direction when it detects a device with low signal.
To find distance you can try:
public double calculateDistance(double signalLevelInDb, double freqInMHz) {
double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(signalLevelInDb)) / 20.0;
return Math.pow(10.0, exp);
}
Recently I found a seemingly cool way to communicate between devices using Google Nearby API. Skimming through the documentation didn't answer my question - is it possible to measure the connection signal strength in real time, or should I invent some kludges e.g. measuring time of sending and receiving data or something else?
Thank you.
As a developer of Nearby API stated in thread Google Nearby Messages - Cancel initial link between devices :
Today, Nearby doesn't expose distance directly
He suggests to use BLE RSII instead
You can get a rough approximation of distance by measuring BLE RSSI if one of the devices is capable of BLE advertising. This will be sensitive to how the device is held, antenna gain and environmental factors but better than random.
There's not a straight-forward "tape measure" API, though.
If your question really is about "Nearby Connection API" and not "Nearby Messages API", you could simply check the Wifi-Signal Strength:
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int numberOfLevels = 5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
I am trying to create a help wizard to recover from bad network connections in the app. One test case I hope to handle is the case where an end user has WiFi turned off, WiFi is available, and the mobile network is slower than the WiFi network. In this event, I want to be able to (1) discover the available WiFi network s, (2) find the WiFi network speed, (3) Compare its speed to the mobile network speed, (4) digest the user changes to the faster network.
For this to work, I need to know how to programmatically get information on available connections. Is that something we can do? If so, how can we tell what connections are available? Thanks in advance.
Task-1: Discover the available WiFi network
This can be done by getting WifiManager's instance from the System.
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.getScanResults();
// The above is an async call and will results are available System will broadcast `SCAN_RESULTS_AVAILABLE` intent and you need to set a `BroadCastReceiver` for it.
// And get the results like this
List<ScanResult> results = wifiManager.getScanResults();
Task-2&3: find the network speed
This link gives an answer to your question about how to get network speeds of wifi and mobile network
Wifi:
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();
In case of mobile it should work:
TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
CellInfoGsm cellinfogsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
cellSignalStrengthGsm.getDbm();
Then You should compare this signal levels and if WIFI signal is better keep it turn on, but if mobile is better disconnect wifi
Task-4: Switching to the option with higher speed
In Android by default, if wifi is on and connected then your mobile network won't be used. Hence to use mobile data you must either disconnect from all available wifi-networks or switch off the wifi.
I will also suggest you to read link this, this and this for getting more information on how to get connection speed.
Requirement in my application is to show Wifi signal strength on wifi signal change.
For a first time i am calculating the Signal strength by following code.
int numberOfLevels=5;
WifiManager wifiManager = (WifiManager)getActivity().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level=WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
I want to update UI frequently if wifi signal is change.
Is there any broadcast available which notify me once signal strength is changed.
Do you any idea How can i achieve this functionality?
Apparently, yes: the broadcast action is "android.net.wifi.RSSI_CHANGED". See WifiManager.RSSI_CHANGED_ACTION
Have never used it personally though.
I am working on developing a settings kind of application in android where i need to retrieve the details of the device
I am having difficulty in finding the following
Signal Strength,
Service State
and Up time.
How to find these 3 current values?
Where can i get the sample settings application?
Up-time:
http://developer.android.com/reference/android/os/SystemClock.html#uptimeMillis()
Service State:
http://developer.android.com/reference/android/telephony/ServiceState.html
Signal Strength:
http://developer.android.com/reference/android/telephony/SignalStrength.html#getGsmSignalStrength()
And here's a link to the platform setting:
https://github.com/android/platform_packages_apps_settings/blob/master/src/com/android/settings/deviceinfo/Status.java
public void onReceive(WifiManager wifiManager) {
int numberOfLevels=5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level=WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
System.out.println("Bars =" +level);
}
This may Provide you the Signal Strength there is a refrence Below
How to get signal strength of connected WiFi android?
May be this will help you