Lalit B
Jun 27, 2017
9:23 am

App Network Traffic Usage using NetworkStats

Hi,

 To get  the App Network Traffic  I'm using NetworkStats as below,

 EnterpriseDeviceManager edm = (EnterpriseDeviceManager) getSystemService
      (EnterpriseDeviceManager.ENTERPRISE_POLICY_SERVICE);
 ApplicationPolicy appPolicy = edm.getApplicationPolicy();
 try {
     List list = appPolicy.getApplicationNetworkStats();
     if (null == list) {
         //return;
     }
     for (NetworkStats netUsage : list) {
         Log.d(TAG, "uid :" + netUsage.uid + " bytes received in wi-fi"
                 + netUsage.wifiRxBytes + " bytes sent in wi-fi"
                 + netUsage.wifiTxBytes + " bytes sent in mobile"
                 + netUsage.mobileTxBytes + " bytes sent in mobile"
                 + netUsage.mobileTxBytes);
     }
 } catch (SecurityException e) {
     Log.w(TAG, "SecurityException: " + e);
 }

So here what is the duration period of data usage. i.e do it give the total  data usage or from specific period for uid?