worked
worked

Reputation: 5880

Calculate current mobile connection speed in Android?

I need the current mobile connectivity speed of an android device. I know how to get the speed link of the wifi connection, but not the mobile connection.

myWifiInfo.getLinkSpeed());

Been reading up on the TrafficStats class, but don't know what to calculate with the information given. For instance:

TrafficStats ts = new TrafficStats();
Log.i("trace", "getMobileRxBytes : " + ts.getMobileRxBytes());
Log.i("trace", "getMobileRxPacets : " + ts.getMobileRxPackets());
Log.i("trace", "getMobileTxBytes : " + ts.getMobileTxBytes());
Log.i("trace", "getMobileTxPackets : " + ts.getMobileTxPackets());

Log.i("trace", "getTotalRxBytes : " + ts.getTotalRxBytes());
Log.i("trace", "getTotalRxPackets : " + ts.getTotalRxPackets());
Log.i("trace", "getTotalTxBytes : " + ts.getTotalTxBytes());
Log.i("trace", "getTotalTxPackets : " + ts.getTotalTxPackets());

Rx refers to "receiving" and TX refers to "transferring".

Upvotes: 2

Views: 1836

Answers (1)

Calvin
Calvin

Reputation: 634

Note time before storing total received bytes, wait for 10 to 20 secs whatever you like then again note total received bytes. Now find the difference in bytes and divide it with the waited number of seconds. The result will be your speed in Bytes per second.

Upvotes: 4

Related Questions