What is the easiest way to check the network speed in android on both mobile and wifi connection?

553 views Asked by At

What is the easiest way to check the network speed in android on both mobile and wifi connection? Is there a better solution than downloading a file from the network and doing some calculations manually on the basis of that.

1

There are 1 answers

2
Ashish Vora On

You can check that whether internet connectivity is available on WiFi or not. If it is unavailable on WiFi then you can ask user to disable WiFi or change WiFi settings.

Another approach is that you manually get signal strength for WiFi and Mobile Network:

To get WiFi's signal strength:

WifiManager wifiManager = (WifiManager) this
            .getSystemService(Context.WIFI_SERVICE);
        int wifiSpeed = wifiManager.getConnectionInfo().getRssi();
        Log.d("SignalStrength", "wifi" + wifiSpeed);

To get Mobile's signal strength:

MyPhoneStateListener MyListener = new MyPhoneStateListener();
TelephonyManager Tel = (TelephonyManager)  getSystemService(Context.TELEPHONY_SERVICE);
Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

And make a listener for Signal strength change:

private class MyPhoneStateListener extends PhoneStateListener {
    /*
     * Get the Signal strength from the provider, each time there is an
     * update
     */
    @Override
    public void onSignalStrengthsChanged(SignalStrength signalStrength) {
        super.onSignalStrengthsChanged(signalStrength);
    Log.d("SignalStrength", "GSM" + String.valueOf(signalStrength
                                .getGsmSignalStrength());
    }

};

You can get updated signal value and put it in Shared Preference then can compare it with WiFi signal value.

WiFi signal value range from -100 to 0.

0 means good strength and -100 means weak.

Mobile signal strength value is from (0-31,99).

0 means low and 31 means good.

99 not known or not detectable.