我正在编写一个像任务管理器这样的应用程序。我想知道如何将用户安装的Android应用程序显示到列表视图中,请大家帮帮我
我刚刚做了一些这样的功能来管理Android中的应用程序,代码还可以,但我想添加更多功能
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.appinfo:
final ActivityManager actvityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
for(int i = 0; i < procInfos.size(); i++)
{
tv.setText(tv.getText().toString()+procInfos.get(i).processName+
" " + String.valueOf(procInfos.get(i).processName.length())+"\n");
if(procInfos.get(i).processName.equals("com.android.camera")) {
Toast.makeText(getApplicationContext(), "Camera App is running", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(), "Camera App is not running", Toast.LENGTH_LONG).show();
}
}
break;
case R.id.taskinfo:
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (int i = 0; i < recentTasks.size(); i++)
{
tv.setText("Executed app"+ "Application executed : " +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: "+recentTasks.get(i).id+"");
}
break;
case R.id.serviceinfo:
final String APP_TAG = "tag";
ActivityManager activityManager1 = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo>runningServices = activityManager1.getRunningServices(50);
for (int i = 0;i < runningServices.size();i++){
ActivityManager.RunningServiceInfo runningServiceInfo = runningServices.get(i);
tv.setText(APP_TAG + "Process " + runningServiceInfo.process + " with component " + runningServiceInfo.service.getClassName());
}