Vipul Purohit
Vipul Purohit

Reputation: 9827

Android : How to get internet connection upload speed and latency?

I want to find device network upload speed and latency, I tried FTP file uploading but didn't get success. Can anybody please help me to determine the network upload speed?

Upvotes: 3

Views: 6757

Answers (2)

Vipul Purohit
Vipul Purohit

Reputation: 9827

I followed this link and got the almost correct download speed. And for upload speed I created a PHP api, uploaded it to FTP server and called it from device and uploaded a file. Then I calculate the time before uploading and after uploading to get Upload Speed.

Upvotes: 3

Thkru
Thkru

Reputation: 4199

To get the current network connection type:

TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
int networkType = telephonyManager.getNetworkType();


and for the latency:

String host = "172.16.0.2";
int timeOut = 3000; 
long[] time = new long[5];
Boolean reachable;

for(int i = 0; i < 5; i++)
{
  long BeforeTime = System.currentTimeMillis();
  reachable = InetAddress.getByName(host).isReachable(timeOut);
  long AfterTime = System.currentTimeMillis();
  Long TimeDifference = AfterTime - BeforeTime;
  time[i] = TimeDifference;
}

Upvotes: 10

Related Questions