Reputation: 3189
Is there any method that can help me track internet usage by application? I need to find out which app is using Internet at the moment.
I've managed to get all applications with INTERNET permission but I don't know how to get only those applications that are connected to internet.
for(int i=0; i<applications.size(); i++){
ApplicationInfo info = applications.get(i);
if(PackageManager.PERMISSION_GRANTED==packageManager.checkPermission(Manifest.permission.INTERNET, info.packageName)){
netApplications.add(info);
}
}
Upvotes: 1
Views: 2538
Reputation: 1006654
You have no way of determining "which app is using Internet at the moment".
However, using TrafficStats
, you can determine which apps are using the Internet over a period of time. Here is a sample application showing the use of TrafficStats
for this purpose.
Also, on Android 4.0+, the Settings application can show you bandwidth consumption, but typically over a significant period of time.
Upvotes: 2