android获取正在运行的应用程序
2012-12-18 13:59:24 来源:WEB开发网核心提示: //如果是非系统应用程序以及一些常用的应用程序就加到list中 if((pInfo.getInfo(runningTasks.get(i).processName).flags&pInfo.getInfo(runningTasks.get(i).processName).FLAG_SYSTEM)==0
//如果是非系统应用程序以及一些常用的应用程序就加到list中
if((pInfo.getInfo(runningTasks.get(i).processName).flags&pInfo.getInfo(runningTasks.get(i).processName).FLAG_SYSTEM)==0
||(runningTasks.get(i).processName).equals("com.android.contacts")
||(runningTasks.get(i).processName).equals("com.android.email")
||(runningTasks.get(i).processName).equals("com.android.settings")
||(runningTasks.get(i).processName).equals("com.android.music")
||(runningTasks.get(i).processName).equals("com.android.calendar")
||(runningTasks.get(i).processName).equals("com.android.calculator2")
||(runningTasks.get(i).processName).equals("com.android.browser")
||(runningTasks.get(i).processName).equals("com.android.camera")
||(runningTasks.get(i).processName).equals("com.cooliris.media")
||(runningTasks.get(i).processName).equals("com.android.bluetooth")
||(runningTasks.get(i).processName).equals("com.android.mms"))
{
String dir = pInfo.getInfo(runningTasks.get(i).processName).publicSourceDir;
Float size=Float.valueOf((float) ((new File(dir).length()*1.0)));//获得应用程序的大小如果size大于一M就用M为单位,否则用KB
//long date = new Date(new File(dir).lastModified()).getTime();
//System.out.println(pInfo.getInfo(runningTasks.get(i).processName).loadIcon(pm));
HashMap<String, Object> map=new HashMap<String, Object>();
map.put("icon", pInfo.getInfo(runningTasks.get(i).processName).loadIcon(pm));
map.put("name", pInfo.getInfo(runningTasks.get(i).processName).loadLabel(pm));
if(size>1024*1024)
map.put("info", size/1024/1024+" MB");
else
map.put("info", size/1024+" KB");
map.put("packagename", runningTasks.get(i).processName.toString());//获得包名给后面用
list.add(map);
}
}
}catch(Exception ex)
{}
SimpleAdapter listadapter=new SimpleAdapter(this, list, R.layout.task_list, new String[]{"icon","name","info"}, new int []{R.id.icon,R.id.name,R.id.info});
listView.setAdapter(listadapter);//listview加载识别器
if((pInfo.getInfo(runningTasks.get(i).processName).flags&pInfo.getInfo(runningTasks.get(i).processName).FLAG_SYSTEM)==0
||(runningTasks.get(i).processName).equals("com.android.contacts")
||(runningTasks.get(i).processName).equals("com.android.email")
||(runningTasks.get(i).processName).equals("com.android.settings")
||(runningTasks.get(i).processName).equals("com.android.music")
||(runningTasks.get(i).processName).equals("com.android.calendar")
||(runningTasks.get(i).processName).equals("com.android.calculator2")
||(runningTasks.get(i).processName).equals("com.android.browser")
||(runningTasks.get(i).processName).equals("com.android.camera")
||(runningTasks.get(i).processName).equals("com.cooliris.media")
||(runningTasks.get(i).processName).equals("com.android.bluetooth")
||(runningTasks.get(i).processName).equals("com.android.mms"))
{
String dir = pInfo.getInfo(runningTasks.get(i).processName).publicSourceDir;
Float size=Float.valueOf((float) ((new File(dir).length()*1.0)));//获得应用程序的大小如果size大于一M就用M为单位,否则用KB
//long date = new Date(new File(dir).lastModified()).getTime();
//System.out.println(pInfo.getInfo(runningTasks.get(i).processName).loadIcon(pm));
HashMap<String, Object> map=new HashMap<String, Object>();
map.put("icon", pInfo.getInfo(runningTasks.get(i).processName).loadIcon(pm));
map.put("name", pInfo.getInfo(runningTasks.get(i).processName).loadLabel(pm));
if(size>1024*1024)
map.put("info", size/1024/1024+" MB");
else
map.put("info", size/1024+" KB");
map.put("packagename", runningTasks.get(i).processName.toString());//获得包名给后面用
list.add(map);
}
}
}catch(Exception ex)
{}
SimpleAdapter listadapter=new SimpleAdapter(this, list, R.layout.task_list, new String[]{"icon","name","info"}, new int []{R.id.icon,R.id.name,R.id.info});
listView.setAdapter(listadapter);//listview加载识别器
更多精彩
赞助商链接