Search code examples
androidwifiwifimanager

Android Wifi Distance


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


Solution

  • 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!