Android 获取已经安装的程序

fmms 13年前

import java.util.ArrayList;  import java.util.Iterator;  import java.util.List;    import Allappinfo.AllAppInfo;  import android.app.Activity;  import android.content.pm.PackageInfo;  import android.os.Bundle;    public class AllAppActivity extends Activity {      /** Called when the activity is first created. */      @Override      public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.main);          //  Get();          ArrayList<AllAppInfo> list=Get();          for (Iterator iterator = list.iterator(); iterator.hasNext();) {     AllAppInfo allAppInfo = (AllAppInfo) iterator.next();     System.out.println(allAppInfo.getAppname()+" |"+allAppInfo.getPackagename()+"| "+allAppInfo.getVersionCode()+"|"+allAppInfo.getLastInstal()+"|"+allAppInfo.getInstalPath());    }      }      private ArrayList<AllAppInfo> Get(){      ArrayList<AllAppInfo> appList = new ArrayList<AllAppInfo>();         List<PackageInfo> packageInfos=getPackageManager().getInstalledPackages(0);      for (int i = 0; i < packageInfos.size(); i++) {    PackageInfo pInfo=packageInfos.get(i);    AllAppInfo allAppInfo=new AllAppInfo();    allAppInfo.setAppname(pInfo.applicationInfo.loadLabel(getPackageManager()).toString());//应用程序的名称    allAppInfo.setPackagename(pInfo.packageName);//应用程序的包    allAppInfo.setVersionCode(pInfo.versionCode);//版本号    allAppInfo.setLastInstal(pInfo.firstInstallTime);    //allAppInfo.setProvider(pInfo.providers);    allAppInfo.setInstalPath(pInfo.applicationInfo.sourceDir);    allAppInfo.setAppicon(pInfo.applicationInfo.loadIcon(getPackageManager()));    appList.add(allAppInfo);   }      return appList;      }  }
import android.content.pm.ProviderInfo;  import android.graphics.drawable.Drawable;    public class AllAppInfo {     private int versionCode = 0;  //版本号          private String appname = "";// 程序名称        private String packagename = "";    //包名称        private Drawable appicon = null;//图标        private long lastInstal;//最后一次安装时间        private ProviderInfo[] provider;//供应商        private String InstalPath;//安装路径      public int getVersionCode() {    return versionCode;   }      public void setVersionCode(int versionCode) {    this.versionCode = versionCode;   }      public String getAppname() {    return appname;   }      public void setAppname(String appname) {    this.appname = appname;   }      public String getPackagename() {    return packagename;   }      public void setPackagename(String packagename) {    this.packagename = packagename;   }            public Drawable getAppicon() {    return appicon;   }      public void setAppicon(Drawable appicon) {    this.appicon = appicon;   }     /**    * @return the lastInstal    */   public long getLastInstal() {    return lastInstal;   }     /**    * @param firstInstallTime the lastInstal to set    */   public void setLastInstal(long firstInstallTime) {    this.lastInstal = firstInstallTime;   }     /**    * @return the provider    */   public ProviderInfo[] getProvider() {    return provider;   }     /**    * @param providers the provider to set    */   public void setProvider(ProviderInfo[] providers) {    this.provider = providers;   }     /**    * @return the instalPath    */   public String getInstalPath() {    return InstalPath;   }     /**    * @param instalPath the instalPath to set    */   public void setInstalPath(String instalPath) {    InstalPath = instalPath;   }   }
0_13204936507fzz.gif

来自:http://blog.csdn.net/rwyz1314/article/details/6939137