Example #1
0
 private void getAllGameApp() {
   List<PackageInfo> apps = new ArrayList<PackageInfo>();
   PackageManager pManager = getPackageManager();
   // 获取手机内所有应用
   List<PackageInfo> packlist = pManager.getInstalledPackages(0);
   for (int i = 0; i < packlist.size(); i++) {
     PackageInfo pak = packlist.get(i);
     // if()里的值如果==0则为自己装的程序,否则为系统工程自带
     if ((pak.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
       // 添加自己已经安装的应用程序
       apps.add(pak);
       String appName = pManager.getApplicationLabel(pak.applicationInfo).toString();
       if (MyApp.gnList.contains(appName)) {
         AppsItemInfo aii = new AppsItemInfo();
         aii.setIcon(pManager.getApplicationIcon(pak.applicationInfo));
         aii.setLabel(pManager.getApplicationLabel(pak.applicationInfo).toString());
         aii.setPackageName(pak.applicationInfo.packageName);
         String filePath = pak.applicationInfo.publicSourceDir;
         aii.setSize(
             Util.round(new File(filePath).length() * 1.0 / (1024 * 1024), 2, BigDecimal.ROUND_UP)
                 + "MB");
         appList.add(aii);
       }
     }
   }
 }
Example #2
0
    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
      // TODO Auto-generated method stub
      ViewHolder holder;
      if (convertView == null) {
        holder = new ViewHolder();
        convertView = mInflater.inflate(R.layout.item_download, null, false);
        holder.iv = (ImageView) convertView.findViewById(R.id.item_download_icon);
        holder.tv_name = (TextView) convertView.findViewById(R.id.item_download_name);
        holder.tv_size = (TextView) convertView.findViewById(R.id.item_download_size);
        holder.startBtn = (Button) convertView.findViewById(R.id.item_download_start);
        convertView.setTag(holder);
      } else {
        holder = (ViewHolder) convertView.getTag();
      }
      final AppsItemInfo gi = appList.get(position);
      if (gi != null) {
        holder.iv.setImageDrawable(gi.getIcon());
        holder.tv_name.setText(gi.getLabel());
        holder.tv_size.setText(gi.getSize());
        holder.startBtn.setText("启动");
        final String pName = gi.getPackageName();
        holder.startBtn.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                Util.startAppByPname(UserDownloadActivity.this, pName);
              }
            });
      }

      return convertView;
    }