2.3開始android提供了一個流量統計類, android.net.TrafficStats,通過使用這個類提供的方法,就可以獲取裝置流量。
下面為該類中的常用方法,歡迎大家完善補充

static long getMobileRxBytes() //獲取通過Mobile連線收到的位元組總數,不包含WiFi
static long getMobileRxPackets() //獲取Mobile連線收到的資料包總數
static long getMobileTxBytes() //Mobile傳送的總位元組數
static long getMobileTxPackets() //Mobile傳送的總資料包數
static long getTotalRxBytes() //獲取總的接受位元組數,包含Mobile和WiFi等
static long getTotalRxPackets() //總的接受資料包數,包含Mobile和WiFi等
static long getTotalTxBytes() //總的傳送位元組數,包含Mobile和WiFi等
static long getTotalTxPackets() //傳送的總資料包數,包含Mobile和WiFi等 
static long getUidRxBytes(int uid) //獲取某個網路UID的接受位元組數,某一個程序的總接收量
static long getUidTxBytes(int uid) //獲取某個網路UID的傳送位元組數,某一個程序的總髮送量

實現方法

        var TrafficStats;  //TrafficStats類例項物件
var total_data; //總共接收到的流量
var traffic_data; //一定時間內接收到的流量
var intervalId; //定時器的返回值,用於控制計時器的停止
document.addEventListener('plusready', function(){
//console.log("所有plus api都應該在此事件發生後呼叫,否則會出現plus is undefined。"
TrafficStats = plus.android.importClass("android.net.TrafficStats");
total_data = TrafficStats.getTotalRxBytes();
intervalId = window.setInterval("getNetSpeed()", 1000);
}); /**
* 核心方法
*/
function getNetSpeed(){
traffic_data = TrafficStats.getTotalRxBytes() - total_data;
total_data = TrafficStats.getTotalRxBytes();
document.getElementById("net").value = bytesToSize(traffic_data);
console.log(bytesToSize(traffic_data));
} //將byte自動轉換為其他單位
function bytesToSize(bytes) {
if (bytes === 0) return '0 B/s';
var k = 1000, // or 1024
sizes = ['B/s', 'KB/s', 'MB/s', 'GB/s', 'TB/s', 'PB/s', 'EB/s', 'ZB/s', 'YB/s'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
}

  原文連線: http://ask.dcloud.net.cn/article/773