Get the current speed of internet (mobile & Wifi) using Android
<p>I have an app that has to work in offline and online mode. Application has to make requests to the app server based on the internet speed of the current network connection (Wifi or Data).</p>

<p>If Wifi is connected, I can get the Wifi signal strength of the current connection using this code.</p>

<pre><code>WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 5);
</code></pre>

<p>OR</p>

<pre><code>wifiInfo.getLinkSpeed();
</code></pre>

<p>If the mobile internet is connected, I was able to get the singal strength using the listener class</p>

<pre><code>@Override
    public void onSignalStrengthsChanged(SignalStrength signalStrength) {
        super.onSignalStrengthsChanged(signalStrength);
        int obj  = signalStrength.getGsmSignalStrength();
        int dBm = (2 * obj) -113;
 }
</code></pre>

<p>The above codes gets the signal strength, not the speed. So, how do I get the current speed of the connected network?</p>

<p>Normally, the speed test apps found in the stores or websites check the speed by sending or downloading a specific file or pinging a remote server and then calculating the speed using the time elapsed.</p>

<p>This upload/download or pinging feature is not supported by the app server with which I am communicating, so I am not able to use that.</p>

<p>So, is there any alternative way to check the speed of the current internet connection that can be done real-time?</p>

<p>Any leads could be helpful.</p>

<p>PS: This link has the code for checking the connectivity type of the current network. But there are cases in which I have a LTE signal with full strength but no/very slow internet connection. So, this too, wont be an accurate solution for me.</p>

<p><a href="https://gist.github.com/emil2k/5130324" rel="nofollow noreferrer">https://gist.github.com/emil2k/5130324</a></p>