思路步骤:
1、Android提供有获取当前总流量的方法
2、上一秒 减去 下一面的流量差便是网速
3、注意计算
1>计算网速的工具类:
package imcs.cb.com.viewapplication.utils;
import android.content.Context;
import android.net.TrafficStats;
import android.os.Handler;
import android.os.Message;
import java.util.Timer;
import java.util.TimerTask;
/**
* Created by Ricky on 2016/10/13.
*/
public class NetWorkSpeedUtils {
private Context context;
private Handler mHandler;
private long lastTotalRxBytes = 0;
private long lastTimeStamp = 0;
public NetWorkSpeedUtils(Context context, Handler mHandler){
this.context = context;
this.mHandler = mHandler;
}
TimerTask task = new TimerTask() {
@Override