我编写了一个代码来获取网络使用情况,但是 queryDetailsForUid(int networkType, StringsubscriberId,long startTime, long endTime, int uid) 这个方法总是返回旧数据。如何使用NetworkstatsManager
API 获取更新的数据?
try {
NetworkStats networkStats = networkStatsManager.queryDetailsForUid(
ConnectivityManager.TYPE_WIFI,
"",
0, System.currentTimeMillis()
,
packageUid);
NetworkStats.Bucket bucket = new NetworkStats.Bucket();
networkStats.getNextBucket(bucket);
Log.d("RX "+packageUid," "+bucket.getRxBytes());
Log.d("TX "+packageUid," "+bucket.getTxBytes());
} catch(Exception e){
}