-
How to identify the network usage of your particular application in android?
over 9 years ago
-
over 9 years ago
public static String getDataUsage(Context context,String pakageName) { final PackageManager pm = context.getPackageManager(); //get a list of installed apps. List
packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); int uid; //loop through the list of installed packages and see if the selected //app is in the list for (ApplicationInfo packageInfo : packages) { if(packageInfo.packageName.equals(pakageName)){ //get the UID for the selected app uid = packageInfo.uid; long send = 0; long recived = 0; recived = TrafficStats.getUidRxBytes(uid); send = TrafficStats.getUidTxBytes(uid); // Display data....... return "send: " + send/1000 + "kB" + " recived: " + recived/1000 + "kB"; } } return "Application not installed"; } @Sachin Joshi, You can use above code in your utility class and pass the context and the pakage name of that application and you will get the data usage detail.
-
over 9 years ago
Hello Sachin, if need to want to see your app's data uses simple
1 Go to settings 2 Data uses
3 Select the in between dates
3 Scroll down and you see all of the apps including your one, consuming your internet data. -
2 Answer(s)