I want to detect if a phone has a slow internet connection or high-speed internet.
Now they have deprecated NetworkInfo and suggesting that we should use ConnectivityManager#getNetworkCapabilities using this I am able to get the signal strength but not able to figure out how to use integer value returned by networkCapabilities.getSignalStrength()
It is returning an Integer value I am getting these values (-39, -71, -31). My question is how should we define that signal strength is good/poor.
Here is my code to get Signal Strength:
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
Network activeNetwork = cm.getActiveNetwork();
NetworkCapabilities networkCapabilities = cm.getNetworkCapabilities(activeNetwork);
int signalStrength = networkCapabilities.getSignalStrength();
First this is a directive approach rather than being a direct answer to the question.
Doc:
This means that
signalStrengthholds a value that is relevant to the signal bearer; for instance if the bearer is WiFi, then thesignalStrengthwill reflect the same WiFi RSSI units.So, you need to map those units to some quality gauge to know whether the signal is weak/strong. This is communication/signal dependent rather than a programming point of view... This thread and also this one may help you for that in case of WiFi bearer.
But you need to customize this quality level for other types of signal bearers the same-wise according to their RSSI units.
GSM signal for instance you may use CellSignalStrengthGsm which has
getRssi()CellSignalStrengthLteis for LTE and so on.You may also get the level of signal strength from the android.telephony API's
SignalStrengthclass... there is agetLevel()method which returns an integer from 0 to 4 representing the general signal quality. Here you can find a listener to that.