How to get a list of installed android applications and pick one to run

后端 未结 19 1885
误落风尘
误落风尘 2020-11-21 06:26

I asked a similar question to this earlier this week but I\'m still not understanding how to get a list of all installed applications and then pick one to run.

I\'v

19条回答
  •  梦谈多话
    2020-11-21 07:10

    I have another solution:

    ArrayList myAppsToUpdate;
    
        // How to get the system and the user apps.
        public ArrayList getAppsToUpdate() {
    
            PackageManager pm = App.getContext().getPackageManager();
            List installedApps = pm.getInstalledApplications(0);
            myAppsToUpdate = new ArrayList();
            for (ApplicationInfo aInfo : installedApps) {
    
                if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    // System apps 
                } else {
                    // Users apps
                    AppInfo appInfo = new AppInfo();
                    appInfo.setAppName(aInfo.loadLabel(pm).toString());
                    appInfo.setPackageName(aInfo.packageName);
                    appInfo.setLaunchActivity(pm.getLaunchIntentForPackage(aInfo.packageName).toString());
                    try {
                        PackageInfo info = pm.getPackageInfo(aInfo.packageName, 0);
                        appInfo.setVersionName(info.versionName.toString());
                        appInfo.setVersionCode("" + info.versionCode);
                        myAppsToUpdate.add(appInfo);
                    } catch (NameNotFoundException e) {
                        Log.e("ERROR", "we could not get the user's apps");
                    }
    
                }
            }
            return myAppsToUpdate;
        }
    

提交回复
热议问题