Search code examples
android-studiowifi3g

How can I calculate the signal strength of my wifi and 3g using android SDK?


I try to make an application that will calculate the signal strenth of my wifi, or 3g and let the user know about his distance from that access point. For instance, I have here a sample of my code that will calculate the distance, in kilometers, between device and a wifi access point:

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);
}

but, when i call the function in android studio, I don't know how to calculate the signalLevelInDb (=dbm) and freqInMhz (=mHz) so I can send them to the function to display my distance. How can I make android studio give me these 2 values? Can I use the same function for the 3g and how?


Solution

  • Please find this information in the offical documentation of the Android SDK: Android SDK API documentation, SignalStrength.

    With this class you have the methods

    int getCdmaDbm()
    

    Get the CDMA RSSI value in dBm

    or:

    int getEvdoDbm()
    

    Get the EVDO RSSI value in dBm

    As an alternative you could have a look at the TelephonyManager class which is supported since API level 1. With this at your side you can find out in which network state (public int getNetworkType ()) your mobile device is at the moment (2G, 3G,...) and thus find out or at least translate to a corresponding "frequency".

    Hope this helps you for your distance calculation.