简体   繁体   中英

Android : How to get the List of Installed apps that use Internet Access - PackageManager

I wonder if it is possible, we get the list of Installed apps by :

    PackageManager pm = AppList.this.getPackageManager();
        Intent intent = new Intent( Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
    List   list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);


        for ( ResolveInfo rInfo : list)
    {
            results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm));


        } 

Can we sort or filter apps that use Internet Access to work?

欢迎您检索与应用程序相对应的PackageInfo ,然后检查其requestedPermissions数组以查看是否有INTERNET权限。

This function will check an activity if it has the internet permission and if that permission is granted. You have to modify it accordingly for a service.

boolean checkIfUsesInet(ResloveInfo rInfo) {
  boolean result = false;
  try {
    PackageInfo packageInfo = getPackageManager().getPackageInfo(rInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
    for(int i=0; i < packageInfo.requestedPermissions.length; i++) {
      String permission = packageInfo.requestedPermission[i];
      int permissionFlag = packageInfo.requestedPermissionFlags[i];
      if(Manifest.permission.INTERNET.equals(permission) && (permissionFlag & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0)
        result = true;
    }
  } catch (NameNotFoundException e) {
    e.printStackTrace();
  }
  return result;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM