未找到PacketManager名称错误

时间:2011-07-06 13:17:08

标签: android

我试图在列表视图中显示我的android上所有正在运行的应用程序,我的代码显示所有正在运行的应用程序,但在某些进程中它会抛出异常,

原因:找不到包管理器,但发现异常消息android.process.acore and android.process.media.

我正在使用以下代码:

while(i.hasNext())
        {
ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());

              try {
                CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));

                Process[j] =  c.toString();
                ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Process);

                ListView ProcessList = (ListView) findViewById(R.id.list); 
                ProcessList.setAdapter(adapter);  


                  }
              catch(Exception e)
              {
                  System.err.println("Caught Exception: "
                            + e.getMessage());

                //Name Not FOund Exception
              }

1 个答案:

答案 0 :(得分:0)

我正在使用设备运行任务的给定打击代码使用它。

       void getRunningTask() {
    ActivityManager activityManager;
    try {
        activityManager = (ActivityManager) this
                .getSystemService(ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> mRunningTasks = activityManager
                .getRunningTasks(30);
        for (RunningTaskInfo amTask : mRunningTasks) {
            Log.d("TaskInfo", amTask.baseActivity.getClassName() + "("
                    + amTask.id + ")");
            // arylistTask.add(amTask.baseActivity.getClassName()+"("+amTask.id+")");
        }
        List<RunningServiceInfo> mserviceTasks = activityManager
                .getRunningServices(30);
        for (RunningServiceInfo serinfo : mserviceTasks) {
            Log.d("TaskServerInfo", serinfo.process + "(" + serinfo.pid
                    + ")");
            arylistTask.add(serinfo.process + "(" + serinfo.pid
                    + ")".toString());
        }
    }

    catch (Exception e)

    {

    }
}

我希望这对你有所帮助。