2014-12-04 43 views
0

嗨,大家好我正在开发一款应用程序来显示状态栏上的数据速率。 enter image description here数据传输速率

我的代码是:

private class DataStatUtil implements Runnable { 

     private long startRX = 0; 
     private long lastRx = 0; 
     private Handler mHandler; 
     private Context context; 
     private Intent actionIntent; 


     public DataStatUtil(Context context ,Handler handler) { 
      this.context = context; 
      mHandler = handler; 
      startRX = TrafficStats.getTotalRxBytes(); 
     } 

     @Override 
     public void run() { 

      long rxBytes = (TrafficStats.getTotalRxBytes()- startRX)/1024; 
      startRX = TrafficStats.getTotalRxBytes(); 

      //my method to display on status bar 
      notifyOnStatusBar(rxBytes); 

      mHandler.postDelayed(this, 1000); 

     } 
    } 

} 

我问的是,这是正确的方式?

回答

0

您应该找到传输的字节,以获得连接中的总带宽使用情况。对上述给定代码的A/C,您只监视总接收字节。

检查此链接以获取更多信息。

How do I programmatically show data usage of all applications?

+0

感谢您的重播。但我只关心接收率。 – 2014-12-04 07:01:18