Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

 2 Answer(s)

  • 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.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: