0

I'm wondering if it's possible to check if an application is shipped with Android, for example: Gallery, Contacts, Downloads, Email, etc. all these kind applications are the ones I would like to exclude from a list I'm creating, but don't want to hardcode the names.

This is the code I'm using to grab application names:

    final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    final List pkgList = getApplicationContext().getPackageManager().queryIntentActivities(mainIntent, 0);

pkgList contains ResolveInfo objects.

Edit:

One way to check if application is part of Android OS is to check if ResolveInfo.activityInfo.applicationInfo.packageName contains "com.android" char seq., but I'm still interested in a more elegant solution.

1 Answers1

1

See this answer.

Basically, this:

PackageManager pm = getPackageManager();

//Gets the info for all installed applications
List<ApplicationInfo> apps = pm.getInstalledApplications(0);

for(ApplicationInfo app : apps) {
    if((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
        //It's a pre-installed app
    } else if ((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
        //It's a pre-installed app with a market update installed
    }
}
Community
  • 1
  • 1
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274