You can get the total amount data transferred from you app using TrafficStats
of android.net
package. Then you detect amount of data transferred per second which gives the speed of you network link
trafficStats = new TrafficStats();
uid = android.os.Process.myUid();
if(trafficStats.getUidRxBytes(uid) != trafficStats.UNSUPPORTED) {
initialBytesCount = trafficStats.getUidTxBytes(uid) / 1024;
} else{
uid = -1;
}
startTime = System.currentTimeMillis();
TimerTask task = new TimerTask() {
@Override
public void run() {
linkSpeed = trafficStats.getUidTxBytes(uid) / 1024 - initialBytesCount;
runOnUiThread(new Runnable() {
@Override
public void run() {
transferRate = 0;
long recordedTime = (System.currentTimeMillis() - startTime) / 1000;
try {
transferRate = linkSpeed / recordedTime;
Log.i("TransferRate", transferRate + "");
}catch (Exception e){
}
}
});
}
};
netWorkSpeedTimer = new Timer();
netWorkSpeedTimer.scheduleAtFixedRate(task, 1000, 1000);