How to check slow network connection in android
I need to show a page if the network connection is slow
iam checking network with this code
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info.getType() == ConnectivityManager.TYPE_WIFI) {
Toast.makeText(MainActivity.this,"wifi",Toast.LENGTH_LONG).show();
// do something
} else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
// check NetworkInfo subtype
if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_GPRS) {
Toast.makeText(MainActivity.this,"mobile 100kbps",Toast.LENGTH_LONG).show();
// Bandwidth between 100 kbps and below
} else if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_EDGE) {
Toast.makeText(MainActivity.this,"mobile 50-100kbps",Toast.LENGTH_LONG).show();
// Bandwidth between 50-100 kbps
} else if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_EVDO_0) {
Toast.makeText(MainActivity.this,"mobile 400-1000kbps",Toast.LENGTH_LONG).show();
// Bandwidth between 400-1000 kbps
} else if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_EVDO_A) {
Toast.makeText(MainActivity.this,"mobile 600-1400kbps",Toast.LENGTH_LONG).show();
// Bandwidth between 600-1400 kbps
}
it shows wifi network But i need a code for slow wifi network. Please help me if there is any code to test a slow wifi network.
+3
source to share
2 answers
You can use the following code to test your wifi speed
WifiManager wifiManager = Context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
Integer linkSpeed = wifiInfo.getLinkSpeed(); //measured using WifiInfo.LINK_SPEED_UNITS
}
Hope this helps you.
+1
source to share
Use below method to check wifi level:
public int getWifiLevel()
{
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();
int level = WifiManager.calculateSignalLevel(linkSpeed, 5);
return level;
}
Based on the wifi level or connection speed, you can decide if it has a low connection or a high internet connection.
+1
source to share