Android + phonegap +package manager

非 Y 不嫁゛ 提交于 2019-12-06 06:23:28

This helper function retrieves all installed apps with the application name, package name, version-number and -code as well as the icons. The method getPackages() returns an ArrayList with all the apps.

class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
    Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
 }
private ArrayList<PInfo> getPackages() {
    ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
   final int max = apps.size();
    for (int i=0; i<max; i++) {
       apps.get(i).prettyPrint();
   }
  return apps;
   }       

private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
      ArrayList<PInfo> res = new ArrayList<PInfo>();        
     List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
      for(int i=0;i<packs.size();i++) {
             PackageInfo p = packs.get(i);
             if ((!getSysPackages) && (p.versionName == null)) {
              continue ;
       }
    PInfo newInfo = new PInfo();
    newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
    newInfo.pname = p.packageName;
    newInfo.versionName = p.versionName;
    newInfo.versionCode = p.versionCode;
    newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
    res.add(newInfo);
}
return res; 
 }

I hope it will help you.

Thanks

You can write plugin for the Package Manager by extending PhoneGap's Plugin class and add package Info class there in Plugin and implement logic to get installed applications.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!