List of Android apps that connect to the Internet

I want to implement a list showing Android applications using them on the Internet. First of all, I have to list all the applications, I did this with the PackageManager, for example:

  packageManager = getPackageManager();
    List<PackageInfo> packageList = packageManager
            .getInstalledPackages(PackageManager.GET_META_DATA);

apkList = (ListView) findViewById(R.id.applist);
    apkList.setAdapter(new ApkAdapter(this, packageList, packageManager));

But this code lists all system applications, as well as: Android Sytem, โ€‹โ€‹Calculator, Calender, Status Bar, Live Wallpapers, etc., which are not suitable. I tried filtering system applications using:

 /*To filter out System apps*/
    for(PackageInfo pi : packageList) {
        boolean b = isSystemPackage(pi);
        if(!b) {
            packageList1.add(pi);
        }
    }

But then the code only displays installed applications, such as whatsapp, tango, foursquare, etc. It does not show applications such as gmail, facebook, browser, maps. Can anyone suggest how I write code that only displays a list of applications that actually use the Internet. Thanks in advance!

+4
2

, Android . - , , ,

( , , , ) - TrafficStats, (TCP, UDP), . UID ( UID).

, , , , , " ".

, :

List<Application> collection = new ArrayList<Application>();
Application app = null; // some custom object is good approach
PackageManager pm = getActivity().getPackageManager();
for (ApplicationInfo info: pm.getInstalledApplications(
                                                PackageManager.GET_META_DATA)) {

   // received data by application
   long downloaded = TrafficStats.getUidRxBytes(info.uid);

   // transmitted data by application
   long uploaded = TrafficStats.getUidTxBytes(info.uid);

   // filter system applications only
   if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {

      // check if application has network usage
      if (downloaded > 0 || uploaded > 0) {

         // it application you want
      }
   }
   // non-system application
   else {
      if (downloaded > 0 || uploaded > 0) {

         // it application you want
      }
   }
}

, TrafficStats API 8, JELLY_BEAN_MR2, , . .

: , , , (), , , ( ) ( , ).

, .

+4

, , , PackageInfo.permission

0

All Articles