getting network/data usage via adb
10,009
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);
}
Internet Usage for your application only :
receivedMbs = (double) TrafficStats.getUidRxBytes(android.os.Process
.myUid()) / (1024 * 1024);
sentMbs = (double) TrafficStats.getUidTxBytes(android.os.Process
.myUid()) / (1024 * 1024);
Related links :
TrafficStats Api android and calculation of daily data usage
Hope it helps .
Author by
chatlow
Updated on June 04, 2022Comments
-
chatlow about 2 years
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 an application's network statistics (netstats) using ADB
but it doesn't work for me.
Ideally I would like to see the network stats for a given application and also know how to wipe/reset these stats if needed.
Any ideas?