【问题标题】:How to check if application is shipped with OS?如何检查应用程序是否随操作系统一起提供?
【发布时间】:2012-10-25 16:30:24
【问题描述】:

我想知道是否可以检查应用程序是否随 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”字符序列,但我仍然对更优雅的解决方案感兴趣。

【问题讨论】:

    标签: android android-intent


    【解决方案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
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-15
      • 2012-08-16
      • 2012-02-05
      • 1970-01-01
      • 2010-09-16
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      相关资源
      最近更新 更多