问题描述
我期待找出一个应用程序有多少数据的发送和接收通过亚行/亚行外壳
I am looking to figure out how much data an application is sending and receiving on an android handset running 2.3 through adb/adb shell
我已经发现的最接近线程是这样
The closest thread I have found was this
Tracking应用程序的网络统计(netstats)使用ADB
但它不为我工作。
我非常希望看到网络统计对于一个给定应用程序,也知道如何擦除/如果需要重置这些统计数据。
Ideally I would like to see the network stats for a given application and also know how to wipe/reset these stats if needed.
任何想法?
推荐答案
您可以使用的类来计算的针对不同的应用使用互联网安装在设备中如果使用的亚行/亚行外壳是不是一个必要条件。
You can use trafficStats class to calculate internet usage for different applications installed in the device if using adb/adb shell isn't a necessary requirement
final PackageManager pm = getPackageManager();
// get a list of installed apps.
List<ApplicationInfo> packages = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
// loop through the list of installed packages and see if the selected
// app is in the list
for (ApplicationInfo packageInfo : packages) {
// get the UID for the selected app
UID = packageInfo.uid;
//internet usage for particular app(sent and received)
long recived = TrafficStats.getUidRxBytes(UID);
long send = TrafficStats.getUidTxBytes(UID);
}
互联网使用你的应用程序只:
receivedMbs = (double) TrafficStats.getUidRxBytes(android.os.Process
.myUid()) / (1024 * 1024);
sentMbs = (double) TrafficStats.getUidTxBytes(android.os.Process
.myUid()) / (1024 * 1024);
相关链接:
TrafficStats API的Android和日常数据使用计算
流量统计的例子
希望它帮助。
这篇关于获得通过ADB网络/数据使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!