private void updateInstalledApps(){
    PackageInfoList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
    ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
    if (PackageInfoList.size() != 0){
      for (PackageInfo info : PackageInfoList){
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("myListViewTextView1", info.packageName); // 应用包名
        // 有权限 可取得应用的安装目录,没有权限则无法获得
        map.put("myListViewTextView2", info.applicationInfo.publicSourceDir);
        // 第一次安装时间
        map.put("myListViewTextView2", convertDateTime(info.firstInstallTime));
        // 最后一次更行时间
        map.put("myListViewTextView3", convertDateTime(info.lastUpdateTime));
        listItem.add(map);
      }
      SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem, R.layout.list_item_2, new String[] {"myListViewTextView1", "myListViewTextView2", "myListViewTextView3"}, new int[] {R.id.myListViewTextView1,R.id.myListViewTextView2,R.id.myListViewTextView3});
      mListView01.setItemsCanFocus(true);
      mListView01.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
      mListView01.setAdapter(listItemAdapter);
    }
    else{
      mTextView01.setText("No Package Found.");
    }
  }

 

  public String convertDateTime(long timeStamp){
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date(timeStamp));
    StringBuffer strTmp = new StringBuffer();

    strTmp.append(calendar.get(Calendar.YEAR));
    strTmp.append('.');
    strTmp.append(calendar.get(Calendar.MONTH) + 1);
    strTmp.append('.');
    strTmp.append(calendar.get(Calendar.DAY_OF_MONTH));

    strTmp.append(' '); 
    strTmp.append(calendar.get(Calendar.HOUR_OF_DAY));
    strTmp.append(':');
    strTmp.append(calendar.get(Calendar.MINUTE));
    strTmp.append(':');
    strTmp.append(calendar.get(Calendar.SECOND));
    return strTmp.toString();
  }

 

posted on 2015-04-22 15:39  道无涯  阅读(552)  评论(0编辑  收藏  举报