Android:列出使用某些资源的所有进程

时间:2014-06-06 08:21:51

标签: android process


我是android编程的新手。 我想列出使用/访问某些资源的所有过程,例如:

  • 档案
  • 互联网等

任何示例代码或建议。

先谢谢... :)

1 个答案:

答案 0 :(得分:0)

您将获得使用互联网的所有应用程序名称,

private ArrayList<String> getInstalledAppsWithSpecificPermission(Context context) {

        ArrayList<String> appsPkgName = new ArrayList<String>();

        PackageManager pm = context.getPackageManager();

        List<PackageInfo> appNamelist = pm.getInstalledPackages(0);
        Iterator<PackageInfo> it = appNamelist.iterator();

        while (it.hasNext()) {
            PackageInfo pk = (PackageInfo) it.next();
            if ((pk.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {

                Log.d("System Application which using internet = ", ""+pk.applicationInfo.loadLabel(pm));

                continue;
            }
            if (PackageManager.PERMISSION_GRANTED == pm
                    .checkPermission(Manifest.permission.INTERNET,
                            pk.packageName))
                results.add("" + pk.applicationInfo.loadLabel(pm));
        }

        Log.v("Application using internet = ", appsPkgName.toString());

        return results;
    }