Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to determine Network speed in android programmatically

How to show a slow internet connection to the user when the network is connected Note: Not a network type (2G,3G,4G, WIFI)

like image 605
Mind_Control Avatar asked Mar 14 '19 09:03

Mind_Control


People also ask

How can I check my Internet speed in Android?

Go to your Android device's settings, find the Notification panel & status bar option, and tap on it. Step 2. Once inside the Notification panel & status bar settings, enable the Display network speed option. And that's it now you will be able to see internet speed on the status bar whenever you are using the internet.

How can I check my network speed in mobile?

Mobile applications You can use applications like Speedtest to check both broadband and cellular data on both Android and iOS. The application also shows a real time graph presenting the connection consistency. You can see how stable your network is using this particular feature.


1 Answers

Determining your Network Speed - (Slow Internet Speed)

Using NetworkInfo class, ConnectivityManager and TelephonyManager to determine your Network Type.

Download any file from the internet & calculate how long it took vs number of bytes in the file. ( Only possible way to determine Speed Check )

I have tried the below Logic for my projects, You have also look into this, Hope it helps you.

ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    //should check null because in airplane mode it will be null
    NetworkCapabilities nc = cm.getNetworkCapabilities(cm.getActiveNetwork());
    int downSpeed = nc.getLinkDownstreamBandwidthKbps();
    int upSpeed = nc.getLinkUpstreamBandwidthKbps();
like image 136
Rajiv Reddy Avatar answered Nov 08 '22 10:11

Rajiv Reddy