取得已安装应用程序列表与安装日期信息

 

  private void updateInstalledApps(){
    PackageInfoList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
    ArrayList> listItem = new ArrayList>();
    if (PackageInfoList.size() != 0){
      for (PackageInfo info : PackageInfoList){
        HashMap map = new HashMap();
        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();
  }

 

转载于:https://www.cnblogs.com/huangzx/p/4447670.html

你可能感兴趣的:(取得已安装应用程序列表与安装日期信息)