andrioid中获取应用程序的信息

 

PackageManager manager = getPackageManager();

 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);

 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

 final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);

 

 

  private static ApplicationInfo getApplicationInfo(PackageManager manager, Intent intent) {
        final ResolveInfo resolveInfo = manager.resolveActivity(intent, 0);  //根据intent获取activity的信息类

        if (resolveInfo == null) {
            return null;
        }

        final ApplicationInfo info = new ApplicationInfo();
        final ActivityInfo activityInfo = resolveInfo.activityInfo;
        info.icon = activityInfo.loadIcon(manager);
        if (info.title == null || info.title.length() == 0) {
            info.title = activityInfo.loadLabel(manager);
        }
        if (info.title == null) {
            info.title = "";
        }
        return info;
    }
 

你可能感兴趣的:(应用程序)