androidtelephonymanagerconnectivitysignal-strength

Android: How to calculate speed of the mobile internet(Upload speed) using signal strength by programatically


In Android, I was able to find strength of signal using below code,

   protected int getSignalStrength(SignalStrength signal) {
            String ssignal = signal.toString();
            String[] parts = ssignal.split(" ");

            int dB = -120; // No Signal Measured when returning -120 dB

            // If LTE 
            if (telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_LTE){

                int ltesignal = Integer.parseInt(parts[9]);

                // check to see if it get's the right signal in dB, a signal below -2
                if(ltesignal < -2) {
                    dB = ltesignal;
                }
            }
            // Else 3G
            else {

                if (signal.getGsmSignalStrength() != 99) {

                    int strengthInteger = -113 + 2 * signal.getGsmSignalStrength();
                    dB = strengthInteger;   
                }
            }

            return dB;
        }

How to calculate speed of the mobile internet(Upload speed / download speed) using signal strength by programatically?? this is my quesion?


Solution

  • Facebook released a library for this:

    https://github.com/facebook/network-connection-class

    Library Description:

    Listen to current network traffic in the app and categorize the quality of the network.