Android Application Management: Package Manager Flags and Package Info (IV)

Android PackageInfo application information

1. Brief introduction
1. Officially interpreted as  
    Overall information about the contents of a package.  This corresponds to all of the information collected from AndroidManifest.xml.
    Get all package information for the application, including information from the manifest file AndroidManifest.xml
2. Getting PackageInfo
2.1. Get PackageInfo for installing all programs on your mobile phone
//Parametric 0 is a filter that passes in different values. It will get different application information. The following will be analyzed in detail. 
List<PackageInfo> installedPackageList = packageManager.getInstalledPackages(0);
2.2. Get PackageInfo for the specified application
//The parameter appPackageName is the package name of the corresponding application that can be obtained through ApplicationInfo
PackageInfo packageInfo = packageManager.getPackageInfo(appPackageName, 0);

Android Package Manager Flags Package Manager Information Description

1. Brief introduction
1. Access Package Manager 
    PackageManager packageManager = this.getPackageManager();
2. Packet Info can be obtained through the package manager
    // Get package information for all applications installed on mobile phones
    List<PackageInfo> installedPackageList = packageManager.getInstalledPackages(0);

    // Get package information for the specified package name application
    PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);

3. The aforementioned input parameter is 0 when acquiring PackageInfo, which is the filtering condition.
   In Package Manager, several filtering conditions are defined. Different filtering conditions are passed in and different application information is obtained.
   For example, the filter condition of the previous operation is 0, which means that only version code (version Name) of the application is included in the Package Info.
2. Overview of PackageManager Flags
2.1 PackageManager.GET_ACTIVITIES
//Source code parsing 
 /**
  * {@link PackageInfo} flag: return information about
  * activities in the package in {@link PackageInfo#activities}.
  */
 public static final int GET_ACTIVITIES              = 0x00000001;

That is to say, when we get PackageInfo, the filter condition is PackageManager.GET_ACTIVITIES, then the PackageInfo we get contains all the activity information under the application tag.

//Gets all activities under the application tag of the specified program
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);


ActivityInfo[] activities = packageInfo.activities;

if (activities != null && activities.length != 0) {
     for (int i = 0; i < activities.length; i++) {
          Log.d("packageInfo -activities", "| " + activities[i]);
     }
}
2.2 PackageManager.GET_CONFIGURATIONS

    /**
     * {@link PackageInfo} flag: return information about
     * hardware preferences in
     * {@link PackageInfo#configPreferences PackageInfo.configPreferences},
     * and requested features in {@link PackageInfo#reqFeatures} and
     * {@link PackageInfo#featureGroups}.
     */
    public static final int GET_CONFIGURATIONS = 0x00004000;

That is, when we get PackageInfo, the filter condition passed in is PackageManager.GET_CONFIGURATIONS, so we get all the configuration information in the manifest file.

List<PackageInfo> list6 = packageManager.getInstalledPackages(PackageManager.GET_CONFIGURATIONS);


for (PackageInfo packageInfo : list6) {
     // Get all Configuration configuration information in the manifest file 
     ConfigurationInfo[] configPreferences = packageInfo.configPreferences;
     if (configPreferences != null) {
          for (int i = 0; i < configPreferences.length; i++) {

               ConfigurationInfo configPreference = configPreferences[i];
                Log.i("ConfigurationInfo-", "ConfigurationInfo: " + configPreference);
          }
     }
}
2.3 PackageManager.GET_CONFIGURATIONS

    /**
     * {@link PackageInfo} flag: return the
     * {@link PackageInfo#gids group ids} that are associated with an
     * application.
     * This applies for any API returning a PackageInfo class, either
     * directly or nested inside of another.
     */
    public static final int GET_GIDS                    = 0x00000100;

That is, when we get PackageInfo, the filter condition is PackageManager.GET_GIDS, so we get all the gid information of the application.

List<PackageInfo> list7 = packageManager.getInstalledPackages(PackageManager.GET_GIDS);

if (list7 != null) {
    for (PackageInfo packageInfo : list7) {
          int[] gids = packageInfo.gids;
          if (gids != null && gids.length != 0) {
               for (int i = 0; i < gids.length; i++) {
                        Log.i("packageInfo-", "gids:" + i + "=" + gids[i]);
                }
          }
     }

}
2.4 PackageManager.GET_CONFIGURATIONS

    /**
     * {@link PackageInfo} flag: return information about
     * instrumentation in the package in
     * {@link PackageInfo#instrumentation}.
     */
    public static final int GET_INSTRUMENTATION         = 0x00000010;

That is, when we get PackageInfo, the filter condition passed in is PackageManager.GET_INSTRUMENTATION, so we get all the Instrumentation information configured in all the lists of the application.

List<PackageInfo> list8 = packageManager.getInstalledPackages(PackageManager.GET_INSTRUMENTATION);
if (list8 != null) {
    for (PackageInfo packageInfo : list8) {

        InstrumentationInfo[] instrumentation = packageInfo.instrumentation;

        if (instrumentation != null) {
            for (InstrumentationInfo instrumentationInfo : instrumentation) {
                Log.i("instrumentationInfo-", "instrumentationInfo " + instrumentationInfo);
            }
        }
    }
}
2.5 PackageManager.GET_INTENT_FILTERS

    /**
     * {@link PackageInfo} flag: return information about the
     * intent filters supported by the activity.
     */
    public static final int GET_INTENT_FILTERS          = 0x00000020;

That is to say, when getting PackageInfo, the filter condition passed in is PackageManager.GET_INTENT_FILTERS, so we can get intent-filter filter filter condition information in the activity prepared under the manifest file.


List<PackageInfo> list9 = packageManager.getInstalledPackages(PackageManager.GET_INTENT_FILTERS);
if (list9 != null) {
    for (PackageInfo packageInfo : list9) {
        FeatureInfo[] reqFeatures = packageInfo.reqFeatures;
        if (reqFeatures != null && reqFeatures.length != 0) {
            for (int i = 0; i < reqFeatures.length; i++) {
                Log.i("packageInfo-", "reqFeatures:" + i + "=" + reqFeatures[i]);
            }
        }
    }
}
2.6 PackageManager.GET_SIGNATURES

/**
 * {@link PackageInfo} flag: return information about the
 * signatures included in the package.
 */
public static final int GET_SIGNATURES          = 0x00000040;

That is, when we get PackageInfo, the filter condition is PackageManager.GET_SIGNATURES, so we can get the signature information of the application.

List<PackageInfo> list10 = packageManager.getInstalledPackages(PackageManager.GET_SIGNATURES);

if (list10 != null) {
    for (PackageInfo packageInfo : list10) {
        Signature[] signatures = packageInfo.signatures;
        if (signatures != null && signatures.length != 0) {
            for (int i = 0; i < signatures.length; i++) {
                Log.i("packageInfo-", "signatures:" + i + "=" + signatures[i]);
            }
        }
    }
}

2.7 PackageManager.GET_META_DATA

/**
 * {@link ComponentInfo} flag: return the {@link ComponentInfo#metaData}
 * data {@link android.os.Bundle}s that are associated with a component.
 * This applies for any API returning a ComponentInfo subclass.
 */
public static final int GET_META_DATA               = 0x00000080;

That is, when we get PackageInfo, the filter condition is PackageManager.GET_META_DATA, so we can get all the meta-data tag information that is configured in the application manifest file.

List<PackageInfo> list10 = packageManager.getInstalledPackages(PackageManager.GET_META_DATA);


2.8 PackageManager.GET_PERMISSIONS

/**
 * {@link PackageInfo} flag: return information about
 * permissions in the package in
 * {@link PackageInfo#permissions}.
 */public static final int GET_PERMISSIONS               = 0x00001000;


That is, when getting PackageInfo, the filter condition passed in is PackageManager.GET_PERMISSIONS, so we can get all the permission information configured in the application's manifest file.

List<PackageInfo> list10 = packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
if (list10 != null) {
    for (PackageInfo packageInfo : list10) {

        String[] requestedPermissions = packageInfo.requestedPermissions;
        if (requestedPermissions != null && requestedPermissions.length != 0) {
            for (int i = 0; i < requestedPermissions.length; i++) {
                Log.i("packageInfo-", "requestedPermissions:" + i + "=" + requestedPermissions[i]);
            }
        }
    }
}

2.9 PackageManager.GET_PROVIDERS

/**
 * {@link PackageInfo} flag: return information about
 * content providers in the package in
 * {@link PackageInfo#providers}.
 */
public static final int GET_PROVIDERS               = 0x00000008;

That is, when we get PackageInfo, the filter condition passed in is PackageManager.GET_PROVIDERS, so we can get all the content providers configured in the application manifest file.

List<PackageInfo> list13 = packageManager.getInstalledPackages(PackageManager.GET_PROVIDERS);
if (list13 != null) {
    for (PackageInfo packageInfo : list13) {

        ProviderInfo[] providers = packageInfo.providers;
        if (providers != null) {
            for (ProviderInfo provider : providers) {

            }
        }
    }
}

2.10 PackageManager.GET_SERVICES

/**
 * {@link PackageInfo} flag: return information about
 * services in the package in {@link PackageInfo#services}.
 */
public static final int GET_SERVICES                = 0x00000004;

That is, when we get PackageInfo, the filter condition passed in is PackageManager.GET_SERVICES, so we can get all the services configured in the application manifest file.

List<PackageInfo> installedPackageList2 = packageManager.getInstalledPackages(PackageManager.GET_SERVICES);
for (PackageInfo packageInfo : installedPackageList2) {
    // Get all services tags under the < Application > tag
    ServiceInfo[] services = packageInfo.services;
    if (services != null && services.length != 0) {
        for (int i = 0; i < services.length; i++) {
            Log.i("packageInfo-services", "services:" + i + "=" + services[i]);
        }
    }
}


2.11 PackageManager.GET_RECEIVERS

/**
 * {@link PackageInfo} flag: return information about
 * intent receivers in the package in
 * {@link PackageInfo#receivers}.
 */
public static final int GET_RECEIVERS               = 0x00000002;

That is, when we get PackageInfo, the filter condition is PackageManager.GET_RECEIVERS, so we can get all the broadcast receivers configured in the application manifest file.

List<PackageInfo> installedPackageList3 = packageManager.getInstalledPackages(PackageManager.GET_RECEIVERS);
for (PackageInfo packageInfo : installedPackageList3) {
    // Get all receive tags under the < Application > tag
    ActivityInfo[] receivers = packageInfo.receivers;
    if (receivers != null && receivers.length != 0) {
        for (int i = 0; i < receivers.length; i++) {
            Log.i("packageInfo-", "receivers:" + i + "=" + receivers[i]);
        }
    }
}


2.12 PackageManager.GET_SHARED_LIBRARY_FILES

/**
 * {@link ApplicationInfo} flag: return the
 * {@link ApplicationInfo#sharedLibraryFiles paths to the shared libraries}
 * that are associated with an application.
 * This applies for any API returning an ApplicationInfo class, either
 * directly or nested inside of another.
 */
public static final int GET_SHARED_LIBRARY_FILES    = 0x00000400;
List<PackageInfo> list = packageManager.getInstalledPackages(PackageManager.GET_SHARED_LIBRARY_FILES);
2.13 PackageManager.GET_SHARED_LIBRARY_FILES

/**
 * {@link ApplicationInfo} flag: return the
 * {@link ApplicationInfo#sharedLibraryFiles paths to the shared libraries}
 * that are associated with an application.
 * This applies for any API returning an ApplicationInfo class, either
 * directly or nested inside of another.
 */
public static final int GET_SHARED_LIBRARY_FILES    = 0x00000400;
List<PackageInfo> list = packageManager.getInstalledPackages(PackageManager.GET_SHARED_LIBRARY_FILES);

Keywords: Android xml Mobile

Added by Davo on Tue, 02 Jul 2019 02:27:33 +0300