【问题标题】:Android : List all process which uses certain resourcesAndroid:列出所有使用某些资源的进程
【发布时间】:2014-06-06 08:21:51
【问题描述】:


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

  • 文件
  • 互联网等

任何示例代码或建议。

在此先感谢...:)

【问题讨论】:

  • 太宽泛,不清楚...
  • 我的意思是我能得到所有正在访问互联网的进程的名称,即浏览器、YouTube 播放器等
  • 你也应该编辑你的问题..

标签: android process


【解决方案1】:

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

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;
    }

【讨论】:

  • 它会给我当前正在使用 Internet 的进程列表?
  • 当前正在使用 Internet 的所有应用程序列表。
猜你喜欢
  • 1970-01-01
  • 2013-09-04
  • 1970-01-01
  • 2011-06-29
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多