Application data usage issue

Put your problem here if it does not fit any of the other categories.

Application data usage issue

Postby Chitra » Wed Sep 14, 2011 8:40 am

Hi,

I want to get each application data usage values by using UID.

But The kernel user-ID that has been assigned to this application; currently this is not a unique ID (multiple applications can have the same uid).

So, I cant get exact data usage for each application.

Any idea??
Thanks,
Chitra
User avatar
Chitra
Master Developer
Master Developer
 
Posts: 213
Joined: Mon Mar 01, 2010 7:59 am
Location: Now in Chennai

Top

Re: Application data usage issue

Postby Chitra » Thu Sep 15, 2011 8:28 am

Here is the code::
Code: Select all
Log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~START");
      PackageManager pm = mContext.getPackageManager();
      Intent intent = new Intent(Intent.ACTION_MAIN, null);
      intent.addCategory(Intent.CATEGORY_LAUNCHER);
      List<ResolveInfo> list = pm.queryIntentActivities(intent,
            PackageManager.PERMISSION_GRANTED);
      for (ResolveInfo rInfo : list) {
         int uid = rInfo.activityInfo.applicationInfo.uid;
         String appName = rInfo.activityInfo.applicationInfo.loadLabel(pm)
               .toString();
         try {
            long recv = Reflection.getUidRxBytes(uid);
            long sent = Reflection.getUidTxBytes(uid);
            long pSent = 0, pRecvd = 0;
            if (sent > 0 || recv > 0) {
               Log("UID:" + uid + " App name:" + appName + " Cur recv:"
                     + recv + " Cur Send:" + sent);
               Vector<AppDataUsage> prevDataValue = new Vector<AppDataUsage>();
               prevDataValue = dbDtl.getAppdataUsage(appName);
               if (prevDataValue.size() > 0) {
                  long bSent = prevDataValue.get(0).getByteSent();
                  long bRcvd = prevDataValue.get(0).getByteRcvd();
                  Log("DBr recvd:" + bRcvd + " DB Send:" + bSent);
                  if (sent > bSent) {
                     pSent = sent - bSent;
                  }
                  if (recv > bRcvd) {
                     pRecvd = recv - bRcvd;
                  }
                  Log("~~Sent::" + pSent + " ~~Recvd::" + pRecvd);
                  if (pSent > 0 || pRecvd > 0) {
                     dbDtl.insertAppUsage(appName, pSent, pRecvd,
                           timestamp);
                  }
               }
               dbDtl.insUpdateAppUsage(appName, sent, recv);
            }
         } catch (Exception e) {
            Log.e(TAG, "app datausage ex." + e.getMessage());
         }
      }
Log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~END ");
Thanks,
Chitra
User avatar
Chitra
Master Developer
Master Developer
 
Posts: 213
Joined: Mon Mar 01, 2010 7:59 am
Location: Now in Chennai

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 21 guests