如何检查应用程序是否附带OS?

时间:2012-10-25 16:30:24

标签: android android-intent

我想知道是否可以检查Android是否附带了应用程序,例如:图库,联系人,下载,电子邮件等等。所有这些类型的应用程序都是我想从列表中排除的应用程序。创建,但不想对名称进行硬编码。

这是我用来获取应用程序名称的代码:

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

pkgList包含ResolveInfo对象。

修改

检查应用程序是否属于Android操作系统的一种方法是检查ResolveInfo.activityInfo.applicationInfo.packageName是否包含“com.android”char seq。,但我仍然对更优雅的解决方案感兴趣。

1 个答案:

答案 0 :(得分:1)

请参阅this answer

基本上,这个:

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
    }
}