Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to identify the network usage of your particular application in android?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 402
    Comment on it

    If you wanted to monitor the data usage of your particular application than you need to know the pakage name of that application which you want to monitor. So just add the method getDataUsage given below in your utility class and pass the context and the pakage name of the particular app and you will get the data usage detail of that application.

    public static String getDataUsage(Context context,String pakageName)
    {       
        final PackageManager pm = context.getPackageManager();
        //get a list of installed apps.
        List<ApplicationInfo> 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";
    }
    

    Hope you find it helpful. Thanks :)

 0 Comment(s)

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: