2011-12-07 30 views
2

我需要Android設備的當前移動連接速度。我知道如何獲得wifi連接的速度鏈接,但不知道移動連接。計算Android中當前的移動連接速度?

myWifiInfo.getLinkSpeed()); 

一直在讀TrafficStats類,但不知道用給定的信息計算什麼。例如:

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指「接收」,TX指「傳送」。

+0

http://stackoverflow.com/questions/4429605/how-to-get-link-speed-programmatically – Craigy

+0

上面的帖子並沒有說明如何處理可用的字節和數據包來確定速度。我正在尋找這個答案。 – worked

+0

我不認爲有可能做你想做的事。你有沒有閱讀[文檔](http://developer.android.com/reference/android/net/TrafficStats.html)這些是什麼意思?它們只是通過移動網絡接口或所有網絡接口的總字節數。我看不出這對你有什麼幫助 – Craigy

回答

3

注意在存儲總接收字節數之前需要等待10到20秒,然後再次記錄總接收字節數。現在找到字節的差異,並用等待的秒數除以它。結果將是您的速度,以每秒字節數爲單位。