2014-12-04 71 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