Skip to content

Instantly share code, notes, and snippets.

@arthtilva
Created December 19, 2017 12:18
Show Gist options
  • Save arthtilva/e1740577408543a5920d1854ff0f01c1 to your computer and use it in GitHub Desktop.
Save arthtilva/e1740577408543a5920d1854ff0f01c1 to your computer and use it in GitHub Desktop.
data usage of app
ActivityManager manager = (ActivityManager) activity.getSystemService(activity.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningApps = manager.getRunningAppProcesses();
Log.i("TAG", "onCreate: " + runningApps.size());
for (ActivityManager.RunningAppProcessInfo runningApp : runningApps) {
// Get UID of the selected process
int uid = runningApp.uid;
// Get traffic data
long received = TrafficStats.getUidRxBytes(uid);
long send = TrafficStats.getUidTxBytes(uid);
Log.v("bytes" + uid, "Send :" + send + ", Received :" + received);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment