2

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?

Ryan Vincent
  • 4,483
  • 7
  • 22
  • 31
Anthony
  • 19
  • 4
  • this got nothing to do with Android "Studio" but with the OS or platform that code is executed, here: 'Android' - Please consider the title of your question. – MWiesner Apr 18 '15 at 16:46

1 Answers1

1

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.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
  • Dude, thank you so much for your answer. I will try all of this.. I saw the site you sent me and I am sure it will be a huge help. You are a life saviour! :) – Anthony Apr 19 '15 at 02:47
  • i tried but it wont let me. it says I need more reputation in order to upvote answers – Anthony Apr 26 '15 at 01:33