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).
If Wifi is connected, I can get the Wifi signal strength of the current connection using this code.
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 5);
OR
wifiInfo.getLinkSpeed();
If the mobile internet is connected, I was able to get the singal strength using the listener class
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
int obj = signalStrength.getGsmSignalStrength();
int dBm = (2 * obj) -113;
}
The above codes gets the signal strength, not the speed. So, how do I get the current speed of the connected network?
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.
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.
So, is there any alternative way to check the speed of the current internet connection that can be done real-time?
Any leads could be helpful.
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.