[Android Pro] 获取手机已经安装的应用 和 获取当前正在运行的所有进程(一个uid对应多个pid)

1: 获取PackageManager 获取全部静态已安装的应用

PackageManager pm = getPackageManager(); 
List<PackageInfo> infos = pm.getInstalledPackages(0); 

icon : info.applicationInfo.loadIcon(pm)
appName : info.applicationInfo.loadLabel(pm)

2:获取ActivityManager获取动态所有正在运行的进程

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> infos = am.getRunningAppProcesses();

info.processName + " ; " + info.uid + " ; " + info.pid
类似如下输出: 

10-20 13:43:16.047: I/System.out(28009): com.qihoo360.mobilesafe:FloatWindow ; 10057 ; 27991
10-20 13:43:16.047: I/System.out(28009): com.qihoo360.mobilesafe:GuardService ; 10057 ; 25390
10-20 13:43:16.047: I/System.out(28009): com.qihoo360.mobilesafe:clear ; 10057 ; 27532

 

posted @ 2014-10-20 14:06  demoblog  阅读(6970)  评论(0编辑  收藏  举报