我需要检查我的Android应用程序的互联网消费。在我的应用程序中,我调用了大量的web服务API。
我想知道我的应用程序在一个完整的过程中消耗了多少kB/MB互联网。
我怎么才能查到?有什么工具可以检查吗?
发布于 2016-04-19 06:48:46
AndroidStudio2.0在Android Monitor中引入了新的Network部分,可以帮助您解决问题。

Tx == Transmit Bytes Rx == Receive Bytes发布于 2016-04-19 07:13:25
有三种方法..。



发布于 2016-04-19 07:00:13
出于查看的目的,您可以在MD提到的监视器中检查它。
要存储,可以通过编程方式进行。
int UID = android.os.Process.myUid();
rxBytes += getUidRxBytes(UID);
txBytes += getUidTxBytes(UID);
/**
* Read UID Rx Bytes
*
* @param uid
* @return rxBytes
*/
public Long getUidRxBytes(int uid) {
BufferedReader reader;
Long rxBytes = 0L;
try {
reader = new BufferedReader(new FileReader("/proc/uid_stat/" + uid
+ "/tcp_rcv"));
rxBytes = Long.parseLong(reader.readLine());
reader.close();
}
catch (FileNotFoundException e) {
rxBytes = TrafficStats.getUidRxBytes(uid);
//e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return rxBytes;
}
/**
* Read UID Tx Bytes
*
* @param uid
* @return txBytes
*/
public Long getUidTxBytes(int uid) {
BufferedReader reader;
Long txBytes = 0L;
try {
reader = new BufferedReader(new FileReader("/proc/uid_stat/" + uid
+ "/tcp_snd"));
txBytes = Long.parseLong(reader.readLine());
reader.close();
}
catch (FileNotFoundException e) {
txBytes = TrafficStats.getUidTxBytes(uid);
//e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return txBytes;
}
}https://stackoverflow.com/questions/36710484
复制相似问题