-1

How would I get the distance of a router using android wifi manager. I was also wondering how I would know what levels the scan results would be to show that the router is unreachable.

Related: https://developer.android.com/reference/android/net/wifi/ScanResult.html

What I was thinking of using to get the distance if someone can confirm this would work that would be greatly appreciated or: https://en.wikipedia.org/wiki/Free-space_path_loss

Darren
  • 74
  • 1
  • 10

1 Answers1

1

Though there is no way measure actual distance (Like in units such as feet or meters), you can measure signal strength with levels. Here is how you do it:

WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    int Levels = 5;
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int signalLevel = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), Levels);

This code here will measure the signal in 5 level increments (Where 1 is the worst and 5 is the best). To make this more accurate you can change Levels variable

To find the distance refer to this post

Hope this helps!

Sharad Khanna
  • 352
  • 3
  • 11
  • keep in mind that, since this is reporting signal strength and not distance, the strength will depend on whether something gets in between the 2 devices. For example, if you have both devices sitting on a table, but you get people in between on/off, the signal value will vary even if the 2 devices are not moving at all – TooManyEduardos Mar 09 '18 at 04:31
  • True I didn't think about that – Sharad Khanna Mar 09 '18 at 11:50