English | Site Directory

Android - An Open Handset Alliance Project

android.content.pm
public abstract class

android.content.pm.PackageManager

java.lang.Object
android.content.pm.PackageManager

Class for retrieving various kinds of information related to the application packages that are currently installed on the device. You can find this class through getPackageManager().

Nested Classes
PackageManager.NameNotFoundException This exception is thrown when a given package, application, or component name can not be found. 

Summary

Constants

      Value  
int  COMPONENT_ENABLED_STATE_DEFAULT    0x00000000 
int  COMPONENT_ENABLED_STATE_DISABLED    0x00000002 
int  COMPONENT_ENABLED_STATE_ENABLED    0x00000001 
int  GET_ACTIVITIES  PackageInfo flag: return information about activities in the package in activities 0x00000001 
int  GET_INSTRUMENTATION  PackageInfo flag: return information about instrumentation in the package in instrumentation 16  0x00000010 
int  GET_INTENT_FILTERS  PackageInfo flag: return information about the intent filters supported by the activity.  32  0x00000020 
int  GET_META_DATA  ComponentInfo flag: return the metaData data Bundle that is associated with a component.  128  0x00000080 
int  GET_PROVIDERS  PackageInfo flag: return information about content providers in the package in providers 0x00000008 
int  GET_RECEIVERS  PackageInfo flag: return information about intent receivers in the package in receivers 0x00000002 
int  GET_RESOLVED_FILTER  ResolveInfo flag: return the IntentFilter that was matched for a particular ResolveInfo in filter 64  0x00000040 
int  GET_SERVICES  PackageInfo flag: return information about services in the package in services 0x00000004 
int  INCLUDE_DISABLED_COMPONENTS  {@link PackageInfo) flag: include disabled components in the returned info.  256  0x00000100 
int  MATCH_DEFAULT_ONLY  Resolution and querying flag: if set, only filters that support the DEFAULT_CATEGORY will be considered for matching.  65536  0x00010000 
int  PERMISSION_DENIED  Permission check result: this is returned by checkPermission(String, String) if the permission has not been granted to the given package.  -1  0xffffffff 
int  PERMISSION_GRANTED  Permission check result: this is returned by checkPermission(String, String) if the permission has been granted to the given package.  0x00000000 
int  SIGNATURE_FIRST_NOT_SIGNED  Signature check result: this is returned by checkSignatures(String, String) if the first package is not signed, but the second is.  -1  0xffffffff 
int  SIGNATURE_MATCH  Signature check result: this is returned by checkSignatures(String, String) if the two packages have a matching signature.  0x00000000 
int  SIGNATURE_NEITHER_SIGNED  Signature check result: this is returned by checkSignatures(String, String) if neither of the two packages is signed.  0x00000001 
int  SIGNATURE_NO_MATCH  Signature check result: this is returned by checkSignatures(String, String) if both packages are signed but there is no matching signature.  -3  0xfffffffd 
int  SIGNATURE_SECOND_NOT_SIGNED  Signature check result: this is returned by checkSignatures(String, String) if the second package is not signed, but the first is.  -2  0xfffffffe 
int  SIGNATURE_UNKNOWN_PACKAGE  Signature check result: this is returned by checkSignatures(String, String) if either of the given package names are not valid.  -4  0xfffffffc 

Public Constructors

          PackageManager()

Public Methods

abstract        void  addPackageToPreferred(String packageName)
Add a new package to the list of preferred packages.
abstract        int  checkPermission(String permName, String pkgName)
Check whether a particular package has been granted a particular permission.
abstract        int  checkSignatures(String pkg1, String pkg2)
Compare the signatures of two packages to determine if the same signature appears in both of them.
abstract        Drawable  getActivityIcon(ComponentName activityName)
Retrieve the icon associated with an activity.
abstract        Drawable  getActivityIcon(Intent intent)
Retrieve the icon associated with an Intent.
abstract        ActivityInfo  getActivityInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular activity class.
abstract        Drawable  getApplicationIcon(String packageName)
Retrieve the icon associated with an application.
abstract        Drawable  getApplicationIcon(ApplicationInfo info)
Retrieve the icon associated with an application.
abstract        ApplicationInfo  getApplicationInfo(String packageName, int flags)
Retrieve all of the information we know about a particular package/application.
abstract        CharSequence  getApplicationLabel(ApplicationInfo info)
Return the label to use for this application.
abstract        Drawable  getDefaultActivityIcon()
Return the generic icon for an activity that is used when no specific icon is defined.
abstract        Drawable  getDrawable(String packageName, int resid, ApplicationInfo appInfo)
Retrieve an image from a package.
abstract        List  getInstalledApplications(int flags)
Return a List of all application packages that are installed on the device.
abstract        List  getInstalledPackages(int flags)
Return a List of all packages that are installed on the device.
abstract        InstrumentationInfo  getInstrumentationInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular instrumentation class.
abstract        String  getNameForUid(int uid)
Retrieve the official name associated with a user id.
        PackageInfo  getPackageArchiveInfo(String archiveFilePath, int flags)
Retrieve overall information about an application package defined in a package archive file
abstract        PackageInfo  getPackageInfo(String packageName, int flags)
Retrieve overall information about an application package that is installed on the system.
abstract        String[]  getPackagesForUid(int uid)
Retrieve the names of all packages that are associated with a particular user id.
abstract        PermissionInfo  getPermissionInfo(String name, int flags)
Retrieve all of the information we know about a particular permission.
abstract        List  getPreferredPackages(int flags)
Retrieve the list of all currently configured preferred packages.
abstract        ActivityInfo  getReceiverInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular receiver class.
abstract        Resources  getResourcesForActivity(ComponentName activityName)
Retrieve the resources associated with an activity.
abstract        Resources  getResourcesForApplication(ApplicationInfo app)
Retrieve the resources for an application.
abstract        Resources  getResourcesForApplication(String appPackageName)
Retrieve the resources associated with an application.
abstract        ServiceInfo  getServiceInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular service class.
abstract        CharSequence  getText(String packageName, int resid, ApplicationInfo appInfo)
Retrieve text from a package.
abstract        XmlPullParser  getXml(String packageName, int resid, ApplicationInfo appInfo)
Retrieve an XML file from a package.
        void  installPackage(Uri packageURI)
Install a package.
abstract        List  queryContentProviders(String processName, int flags)
Retrieve content provider information.
abstract        List  queryInstrumentation(String targetPackage, int flags)
Retrieve information about available instrumentation code.
abstract        List  queryIntentActivities(Intent intent, int flags)
Retrieve all activities that can be performed for the given intent.
abstract        List  queryIntentActivityOptions(ComponentName caller, Intent[] specifics, Intent intent, int flags)
Retrieve a set of activities that should be presented to the user as similar options.
abstract        List  queryIntentReceivers(Intent intent, int flags)
Retrieve all receivers that can handle a broadcast of the given intent.
abstract        List  queryIntentServices(Intent intent, int flags)
Retrieve all services that can match the given intent.
abstract        void  removePackageFromPreferred(String packageName)
Remove a package from the list of preferred packages.
abstract        ResolveInfo  resolveActivity(Intent intent, int flags)
Determine the best action to perform for a given Intent.
abstract        ProviderInfo  resolveContentProvider(String name, int flags)
Find a single content provider by its base path name.
abstract        ResolveInfo  resolveService(Intent intent, int flags)
Determine the best service to handle for a given Intent.
abstract        void  setApplicationEnabledSetting(String packageName, int newState)
Set the enabled setting for an application This setting will override any enabled state which may have been set by the application in its manifest.
abstract        void  setComponentEnabledSetting(ComponentName componentName, int newState)
Set the enabled setting for a package component (activity, receiver, service, provider).
Methods inherited from class java.lang.Object

Details

Constants

public static final int COMPONENT_ENABLED_STATE_DEFAULT

Constant Value: 0 (0x00000000)

public static final int COMPONENT_ENABLED_STATE_DISABLED

Constant Value: 2 (0x00000002)

public static final int COMPONENT_ENABLED_STATE_ENABLED

Constant Value: 1 (0x00000001)

public static final int GET_ACTIVITIES

PackageInfo flag: return information about activities in the package in activities.
Constant Value: 1 (0x00000001)

public static final int GET_INSTRUMENTATION

PackageInfo flag: return information about instrumentation in the package in instrumentation.
Constant Value: 16 (0x00000010)

public static final int GET_INTENT_FILTERS

PackageInfo flag: return information about the intent filters supported by the activity.
Constant Value: 32 (0x00000020)

public static final int GET_META_DATA

ComponentInfo flag: return the metaData data Bundle that is associated with a component. This applies for any API returning a ComponentInfo subclass.
Constant Value: 128 (0x00000080)

public static final int GET_PROVIDERS

PackageInfo flag: return information about content providers in the package in providers.
Constant Value: 8 (0x00000008)

public static final int GET_RECEIVERS

PackageInfo flag: return information about intent receivers in the package in receivers.
Constant Value: 2 (0x00000002)

public static final int GET_RESOLVED_FILTER

ResolveInfo flag: return the IntentFilter that was matched for a particular ResolveInfo in filter.
Constant Value: 64 (0x00000040)

public static final int GET_SERVICES

PackageInfo flag: return information about services in the package in services.
Constant Value: 4 (0x00000004)

public static final int INCLUDE_DISABLED_COMPONENTS

{@link PackageInfo) flag: include disabled components in the returned info.
Constant Value: 256 (0x00000100)

public static final int MATCH_DEFAULT_ONLY

Resolution and querying flag: if set, only filters that support the DEFAULT_CATEGORY will be considered for matching. This is a synonym for including the DEFAULT_CATEGORY in your supplied Intent.
Constant Value: 65536 (0x00010000)

public static final int PERMISSION_DENIED

Permission check result: this is returned by checkPermission(String, String) if the permission has not been granted to the given package.
Constant Value: -1 (0xffffffff)

public static final int PERMISSION_GRANTED

Permission check result: this is returned by checkPermission(String, String) if the permission has been granted to the given package.
Constant Value: 0 (0x00000000)

public static final int SIGNATURE_FIRST_NOT_SIGNED

Signature check result: this is returned by checkSignatures(String, String) if the first package is not signed, but the second is.
Constant Value: -1 (0xffffffff)

public static final int SIGNATURE_MATCH

Signature check result: this is returned by checkSignatures(String, String) if the two packages have a matching signature.
Constant Value: 0 (0x00000000)

public static final int SIGNATURE_NEITHER_SIGNED

Signature check result: this is returned by checkSignatures(String, String) if neither of the two packages is signed.
Constant Value: 1 (0x00000001)

public static final int SIGNATURE_NO_MATCH

Signature check result: this is returned by checkSignatures(String, String) if both packages are signed but there is no matching signature.
Constant Value: -3 (0xfffffffd)

public static final int SIGNATURE_SECOND_NOT_SIGNED

Signature check result: this is returned by checkSignatures(String, String) if the second package is not signed, but the first is.
Constant Value: -2 (0xfffffffe)

public static final int SIGNATURE_UNKNOWN_PACKAGE

Signature check result: this is returned by checkSignatures(String, String) if either of the given package names are not valid.
Constant Value: -4 (0xfffffffc)

Public Constructors

public PackageManager()

Public Methods

public abstract void addPackageToPreferred(String packageName)

Add a new package to the list of preferred packages. This new package will be added to the front of the list (removed from its current location if already listed), meaning it will now be preferred over all other packages when resolving conflicts.

Parameters

packageName The package name of the new package to make preferred.

public abstract int checkPermission(String permName, String pkgName)

Check whether a particular package has been granted a particular permission.

Parameters

permName The name of the permission you are checking for,
pkgName The name of the package you are checking against.

Returns

  • If the package has the permission, PERMISSION_GRANTED is returned. If it does not have the permission, PERMISSION_DENIED is returned.

public abstract int checkSignatures(String pkg1, String pkg2)

Compare the signatures of two packages to determine if the same signature appears in both of them. If they do contain the same signature, then they are allowed special privileges when working with each other: they can share the same user-id, run instrumentation against each other, etc.

Parameters

pkg1 First package name whose signature will be compared.
pkg2 Second package name whose signature will be compared.

Returns

public abstract Drawable getActivityIcon(ComponentName activityName)

Retrieve the icon associated with an activity. Given the full name of an activity, retrieves the information about it and calls ComponentInfo.loadIcon() to return its icon. If the activity can not be found, NameNotFoundException is thrown.

Parameters

activityName Name of the activity whose icon is to be retrieved.

Returns

  • Drawable Image of the icon.

public abstract Drawable getActivityIcon(Intent intent)

Retrieve the icon associated with an Intent. If intent.getClassName() is set, this simply returns the result of getActivityIcon(intent.getClassName()). Otherwise it resolves the intent's component and returns the icon associated with the resolved component. If intent.getClassName() can not be found or the Intent can not be resolved to a component, NameNotFoundException is thrown.

Parameters

intent The intent for which you would like to retrieve an icon.

Returns

  • A Drawable containing the image of the icon.

public abstract ActivityInfo getActivityInfo(ComponentName className, int flags)

Retrieve all of the information we know about a particular activity class.

Throws PackageManager.NameNotFoundException if an activity with the given class name can not be found on the system.

Parameters

className The full name (i.e. com.google.apps.contacts.ContactsList) of an Activity class.
flags Additional option flags. Usually 0.

Returns

public abstract Drawable getApplicationIcon(String packageName)

Retrieve the icon associated with an application. Given the name of the application's package, retrieves the information about it and calls getApplicationIcon() to return its icon. If the application can not be found, NameNotFoundException is thrown.

Parameters

packageName Name of the package whose application icon is to be retrieved.

Returns

  • Drawable Image of the icon.

public abstract Drawable getApplicationIcon(ApplicationInfo info)

Retrieve the icon associated with an application. If it has not defined an icon, the default app icon is returned.

Parameters

info Information about application being queried.

Returns

  • Drawable Image of the icon.

public abstract ApplicationInfo getApplicationInfo(String packageName, int flags)

Retrieve all of the information we know about a particular package/application.

Throws PackageManager.NameNotFoundException if an application with the given package name can not be found on the system.

Parameters

packageName The full name (i.e. com.google.apps.contacts) of an application.
flags Additional option flags. Currently should always be 0.

Returns

public abstract CharSequence getApplicationLabel(ApplicationInfo info)

Return the label to use for this application.

Parameters

info The application to get the label of

Returns

  • The label associated with this application.

public abstract Drawable getDefaultActivityIcon()

Return the generic icon for an activity that is used when no specific icon is defined.

Returns

  • Drawable Image of the icon.

public abstract Drawable getDrawable(String packageName, int resid, ApplicationInfo appInfo)

Retrieve an image from a package. This is a low-level API used by the various package manager info structures (such as ComponentInfo to implement retrieval of their associated icon.

Parameters

packageName The name of the package that this icon is coming from. Can not be null.
resid The resource identifier of the desired image. Can not be 0.
appInfo Overall information about packageName. This may be null, in which case the application information will be retrieved for you if needed; if you already have this information around, it can be much more efficient to supply it here.

Returns

  • Returns a Drawable holding the requested image. Returns null if an image could not be found for any reason.

public abstract List getInstalledApplications(int flags)

Return a List of all application packages that are installed on the device.

Parameters

flags Additional option flags. Currently should always be 0.

Returns

  • A List of ApplicationInfo objects, one for each application that is installed on the device. In the unlikely case of there being no installed applications, an empty list is returned.

public abstract List getInstalledPackages(int flags)

Return a List of all packages that are installed on the device.

Parameters

flags Optional flags to control what information is returned. If 0, none of the optional information is returned.

Returns

  • A List of PackageInfo objects, one for each package that is installed on the device. In the unlikely case of there being no installed packages, an empty list is returned.

public abstract InstrumentationInfo getInstrumentationInfo(ComponentName className, int flags)

Retrieve all of the information we know about a particular instrumentation class.

Throws PackageManager.NameNotFoundException if instrumentation with the given class name can not be found on the system.

Parameters

className The full name (i.e. com.google.apps.contacts.InstrumentList) of an Instrumentation class.
flags Additional option flags. Currently should always be 0.

Returns

  • InstrumentationInfo containing information about the instrumentation.

public abstract String getNameForUid(int uid)

Retrieve the official name associated with a user id. This name is guaranteed to never change, though it is possibly for the underlying user id to be changed. That is, if you are storing information about user ids in persistent storage, you should use the string returned by this function instead of the raw user-id.

Parameters

uid The user id for which you would like to retrieve a name.

Returns

  • Returns a unique name for the given user id, or null if the user id is not currently assigned.

public PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags)

Retrieve overall information about an application package defined in a package archive file

Parameters

archiveFilePath The path to the archive file
flags Optional flags to control what information is returned. If 0, none of the optional information is returned.

Returns

  • PackageInfo containing information about the package. Returns null if the package could not be successfully parsed.

public abstract PackageInfo getPackageInfo(String packageName, int flags)

Retrieve overall information about an application package that is installed on the system.

Throws PackageManager.NameNotFoundException if apackage with the given name can not be found on the system.

Parameters

packageName The full name (i.e. com.google.apps.contacts) of the desired package.
flags Optional flags to control what information is returned. If 0, none of the optional information is returned.

Returns

  • PackageInfo containing information about the package.

public abstract String[] getPackagesForUid(int uid)

Retrieve the names of all packages that are associated with a particular user id. In most cases, this will be a single package name, the package that has been assigned that user id. Where there are multiple packages sharing the same user id through the "sharedUserId" mechanism, all packages with that id will be returned.

Parameters

uid The user id for which you would like to retrieve the associated packages.

Returns

  • Returns an array of one or more packages assigned to the user id, or null if there are no known packages with the given id.

public abstract PermissionInfo getPermissionInfo(String name, int flags)

Retrieve all of the information we know about a particular permission.

Throws PackageManager.NameNotFoundException if an permission with the given name can not be found on the system.

Parameters

name The fullly qualified name (i.e. com.google.permission.LOGIN) of the permission you are interested in.
flags Additional option flags. Currently should always be 0.

Returns

public abstract List getPreferredPackages(int flags)

Retrieve the list of all currently configured preferred packages. The first package on the list is the most preferred, the last is the least preferred.

Parameters

flags Optional flags to control what information is returned. If 0, none of the optional information is returned.

Returns

  • Returns a list of PackageInfo objects describing each preferred application, in order of preference.

public abstract ActivityInfo getReceiverInfo(ComponentName className, int flags)

Retrieve all of the information we know about a particular receiver class.

Throws PackageManager.NameNotFoundException if a receiver with the given class name can not be found on the system.

Parameters

className The full name (i.e. com.google.apps.contacts.CalendarAlarm) of a Receiver class.
flags Additional option flags. Usually 0.

Returns

public abstract Resources getResourcesForActivity(ComponentName activityName)

Retrieve the resources associated with an activity. Given the full name of an activity, retrieves the information about it and calls getResources() to return its application's resources. If the activity can not be found, NameNotFoundException is thrown.

Parameters

activityName Name of the activity whose resources are to be retrieved.

Returns

  • Resources The application's Resources.

public abstract Resources getResourcesForApplication(ApplicationInfo app)

Retrieve the resources for an application.

Parameters

app Information about the desired application.

Returns

  • Resources The application's Resources.

public abstract Resources getResourcesForApplication(String appPackageName)

Retrieve the resources associated with an application. Given the full package name of an application, retrieves the information about it and calls getResources() to return its application's resources. If the aookucatuib can not be found, NameNotFoundException is thrown.

Parameters

appPackageName Package name of the application whose resources are to be retrieved.

Returns

  • Resources The application's Resources.

public abstract ServiceInfo getServiceInfo(ComponentName className, int flags)

Retrieve all of the information we know about a particular service class.

Throws PackageManager.NameNotFoundException if a service with the given class name can not be found on the system.

Parameters

className The full name (i.e. com.google.apps.media.BackgroundPlayback) of a Service class.
flags Additional option flags. Currently should always be 0.

Returns

  • ServiceInfo containing information about the service.

public abstract CharSequence getText(String packageName, int resid, ApplicationInfo appInfo)

Retrieve text from a package. This is a low-level API used by the various package manager info structures (such as ComponentInfo to implement retrieval of their associated labels and other text.

Parameters

packageName The name of the package that this text is coming from. Can not be null.
resid The resource identifier of the desired text. Can not be 0.
appInfo Overall information about packageName. This may be null, in which case the application information will be retrieved for you if needed; if you already have this information around, it can be much more efficient to supply it here.

Returns

  • Returns a CharSequence holding the requested text. Returns null if the text could not be found for any reason.

public abstract XmlPullParser getXml(String packageName, int resid, ApplicationInfo appInfo)

Retrieve an XML file from a package. This is a low-level API used to retrieve XML meta data.

Parameters

packageName The name of the package that this xml is coming from. Can not be null.
resid The resource identifier of the desired xml. Can not be 0.
appInfo Overall information about packageName. This may be null, in which case the application information will be retrieved for you if needed; if you already have this information around, it can be much more efficient to supply it here.

Returns

  • Returns an XmlPullParser allowing you to parse out the XML data. Returns null if the xml resource could not be found for any reason.

public void installPackage(Uri packageURI)

Install a package.

Parameters

packageURI The location of the package file to install

public abstract List queryContentProviders(String processName, int flags)

Retrieve content provider information.

Note: unlike most other methods, an empty result set is indicated by a null return instead of an empty list.

Parameters

processName If non-null, limits the returned providers to only those that are hosted by the given process. If null, all content providers are returned.
flags Additional option flags. Currently should always be 0.

Returns

  • A List containing one entry for each content provider either patching processName or, if processName is null, all known content providers. If there are no matching providers, null is returned.

public abstract List queryInstrumentation(String targetPackage, int flags)

Retrieve information about available instrumentation code. May be used to retrieve either all instrumentation code, or only the code targeting a particular package.

Parameters

targetPackage If null, all instrumentation is returned; only the instrumentation targeting this package name is returned.
flags Additional option flags. Currently should always be 0.

Returns

  • A List containing one entry for each matching available Instrumentation. Returns an empty list if there is no instrumentation available for the given package.

public abstract List queryIntentActivities(Intent intent, int flags)

Retrieve all activities that can be performed for the given intent.

Parameters

intent The desired intent as per resolveActivity().
flags Additional option flags. The most important is MATCH_DEFAULT_ONLY, to limit the resolution to only those activities that support the DEFAULT_CATEGORY.

Returns

  • A List containing one entry for each matching Activity. These are ordered from best to worst match -- that is, the first item in the list is what is returned by resolveActivity(). If there are no matching activities, an empty list is returned.

public abstract