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

后端 未结 19 1826
误落风尘
误落风尘 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:14

    I had a requirement to filter out the system apps which user do not really use(eg. "com.qualcomm.service", "update services", etc). Ultimately I added another condition to filter down the app list. I just checked whether the app has 'launcher intent'.

    So, the resultant code looks like...

    PackageManager pm = getPackageManager();
            List apps = pm.getInstalledApplications(PackageManager.GET_GIDS);
    
            for (ApplicationInfo app : apps) {
                if(pm.getLaunchIntentForPackage(app.packageName) != null) {
                    // apps with launcher intent
                    if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
                        // updated system apps
    
                    } else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                        // system apps
    
                    } else {
                        // user installed apps
    
                    }
                    appsList.add(app);
                }
    
            }
    

提交回复
热议问题