开发者

PacketManager name not found error

I am trying to display all running apps on my android in a list view, my code is showing all running apps but in some processes it is throwing exception,

cause: Package Manager not found with exception messege android.process.acore and android.process.media.

I am using below code:

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
              }


I am using the given blow code of running task of the device use it:

       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)

    {

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜