Android APIs
public class

MockPackageManager

extends PackageManager
java.lang.Object
   ↳ android.content.pm.PackageManager
     ↳ android.test.mock.MockPackageManager

Class Overview

A mock PackageManager class. All methods are non-functional and throw UnsupportedOperationException. Override it to provide the operations that you need.

Summary

[Expand]
Inherited Constants
From class android.content.pm.PackageManager
Public Constructors
MockPackageManager()
Public Methods
void addPackageToPreferred(String packageName)
This method is deprecated. This function no longer does anything; it was an old approach to managing preferred activities, which has been superseded by (and conflicts with) the modern activity-based preferences.
boolean addPermission(PermissionInfo info)
Add a new dynamic permission to the system.
boolean addPermissionAsync(PermissionInfo info)
Like addPermission(PermissionInfo) but asynchronously persists the package manager state after returning from the call, allowing it to return quicker and batch a series of adds at the expense of no guarantee the added permission will be retained if the device is rebooted before it is written.
void addPreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity)
This method is deprecated. This is a protected API that should not have been available to third party applications. It is the platform's responsibility for assigning preferred activities and this cannot be directly modified. Add a new preferred activity mapping to the system. This will be used to automatically select the given activity component when Context.startActivity() finds multiple matching activities and also matches the given filter.
String[] canonicalToCurrentPackageNames(String[] names)
Map from a packages canonical name to the current name in use on the device.
int checkPermission(String permName, String pkgName)
Check whether a particular package has been granted a particular permission.
int checkSignatures(int uid1, int uid2)
Like checkSignatures(String, String), but takes UIDs of the two packages to be checked.
int checkSignatures(String pkg1, String pkg2)
Compare the signatures of two packages to determine if the same signature appears in both of them.
void clearPackagePreferredActivities(String packageName)
Remove all preferred activity mappings, previously added with addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName), from the system whose activities are implemented in the given package name.
String[] currentToCanonicalPackageNames(String[] names)
Map from the current package names in use on the device to whatever the current canonical name of that package is.
void extendVerificationTimeout(int id, int verificationCodeAtTimeout, long millisecondsToDelay)
Allows a package listening to the package verification broadcast to extend the default timeout for a response and declare what action to perform after the timeout occurs.
Drawable getActivityBanner(Intent intent)
Retrieve the banner associated with an Intent.
Drawable getActivityBanner(ComponentName activityName)
Retrieve the banner associated with an activity.
Drawable getActivityIcon(Intent intent)
Retrieve the icon associated with an Intent.
Drawable getActivityIcon(ComponentName activityName)
Retrieve the icon associated with an activity.
ActivityInfo getActivityInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular activity class.
Drawable getActivityLogo(Intent intent)
Retrieve the logo associated with an Intent.
Drawable getActivityLogo(ComponentName activityName)
Retrieve the logo associated with an activity.
List<PermissionGroupInfo> getAllPermissionGroups(int flags)
Retrieve all of the known permission groups in the system.
Drawable getApplicationBanner(ApplicationInfo info)
Retrieve the banner associated with an application.
Drawable getApplicationBanner(String packageName)
Retrieve the banner associated with an application.
int getApplicationEnabledSetting(String packageName)
Return the the enabled setting for an application.
Drawable getApplicationIcon(String packageName)
Retrieve the icon associated with an application.
Drawable getApplicationIcon(ApplicationInfo info)
Retrieve the icon associated with an application.
ApplicationInfo getApplicationInfo(String packageName, int flags)
Retrieve all of the information we know about a particular package/application.
CharSequence getApplicationLabel(ApplicationInfo info)
Return the label to use for this application.
Drawable getApplicationLogo(String packageName)
Retrieve the logo associated with an application.
Drawable getApplicationLogo(ApplicationInfo info)
Retrieve the logo associated with an application.
int getComponentEnabledSetting(ComponentName componentName)
Return the the enabled setting for a package component (activity, receiver, service, provider).
Drawable getDefaultActivityIcon()
Return the generic icon for an activity that is used when no specific icon is defined.
Drawable getDrawable(String packageName, int resid, ApplicationInfo appInfo)
Retrieve an image from a package.
List<ApplicationInfo> getInstalledApplications(int flags)
Return a List of all application packages that are installed on the device.
List<PackageInfo> getInstalledPackages(int flags)
Return a List of all packages that are installed on the device.
String getInstallerPackageName(String packageName)
Retrieve the package name of the application that installed a package.
InstrumentationInfo getInstrumentationInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular instrumentation class.
Intent getLaunchIntentForPackage(String packageName)
Return a "good" intent to launch a front-door activity in a package, for use for example to implement an "open" button when browsing through packages.
Intent getLeanbackLaunchIntentForPackage(String packageName)
Return a "good" intent to launch a front-door Leanback activity in a package, for use for example to implement an "open" button when browsing through packages.
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
int[] getPackageGids(String packageName)
Return an array of all of the secondary group-ids that have been assigned to a package.
PackageInfo getPackageInfo(String packageName, int flags)
Retrieve overall information about an application package that is installed on the system.
String[] getPackagesForUid(int uid)
Retrieve the names of all packages that are associated with a particular user id.
List<PackageInfo> getPackagesHoldingPermissions(String[] permissions, int flags)
Return a List of all installed packages that are currently holding any of the given permissions.
PermissionGroupInfo getPermissionGroupInfo(String name, int flags)
Retrieve all of the information we know about a particular group of permissions.
PermissionInfo getPermissionInfo(String name, int flags)
Retrieve all of the information we know about a particular permission.
int getPreferredActivities(List<IntentFilter> outFilters, List<ComponentName> outActivities, String packageName)
Retrieve all preferred activities, previously added with addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName), that are currently registered with the system.
List<PackageInfo> getPreferredPackages(int flags)
Retrieve the list of all currently configured preferred packages.
ProviderInfo getProviderInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular content provider class.
ActivityInfo getReceiverInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular receiver class.
Resources getResourcesForActivity(ComponentName activityName)
Retrieve the resources associated with an activity.
Resources getResourcesForApplication(String appPackageName)
Retrieve the resources associated with an application.
Resources getResourcesForApplication(ApplicationInfo app)
Retrieve the resources for an application.
ServiceInfo getServiceInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular service class.
FeatureInfo[] getSystemAvailableFeatures()
Get a list of features that are available on the system.
String[] getSystemSharedLibraryNames()
Get a list of shared libraries that are available on the system.
CharSequence getText(String packageName, int resid, ApplicationInfo appInfo)
Retrieve text from a package.
XmlResourceParser getXml(String packageName, int resid, ApplicationInfo appInfo)
Retrieve an XML file from a package.
boolean hasSystemFeature(String name)
Check whether the given feature name is one of the available features as returned by getSystemAvailableFeatures().
boolean isSafeMode()
Return whether the device has been booted into safe mode.
List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags)
Retrieve all receivers that can handle a broadcast of the given intent.
List<ProviderInfo> queryContentProviders(String processName, int uid, int flags)
Retrieve content provider information.
List<InstrumentationInfo> queryInstrumentation(String targetPackage, int flags)
Retrieve information about available instrumentation code.
List<ResolveInfo> queryIntentActivities(Intent intent, int flags)
Retrieve all activities that can be performed for the given intent.
List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, Intent[] specifics, Intent intent, int flags)
Retrieve a set of activities that should be presented to the user as similar options.
List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags)
Retrieve all providers that can match the given intent.
List<ResolveInfo> queryIntentServices(Intent intent, int flags)
Retrieve all services that can match the given intent.
List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
Query for all of the permissions associated with a particular group.
void removePackageFromPreferred(String packageName)
This method is deprecated. This function no longer does anything; it was an old approach to managing preferred activities, which has been superseded by (and conflicts with) the modern activity-based preferences.
void removePermission(String name)
Removes a permission that was previously added with addPermission(PermissionInfo).
ResolveInfo resolveActivity(Intent intent, int flags)
Determine the best action to perform for a given Intent.
ProviderInfo resolveContentProvider(String name, int flags)
Find a single content provider by its base path name.
ResolveInfo resolveService(Intent intent, int flags)
Determine the best service to handle for a given Intent.
void setApplicationEnabledSetting(String packageName, int newState, int flags)
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.
void setComponentEnabledSetting(ComponentName componentName, int newState, int flags)
Set the enabled setting for a package component (activity, receiver, service, provider).
void setInstallerPackageName(String targetPackage, String installerPackageName)
Change the installer associated with a given package.
void verifyPendingInstall(int id, int verificationCode)
Allows a package listening to the package verification broadcast to respond to the package manager.
[Expand]
Inherited Methods
From class android.content.pm.PackageManager
From class java.lang.Object

Public Constructors

public MockPackageManager ()

Added in API level 1

Public Methods

public void addPackageToPreferred (String packageName)

Added in API level 1

This method is deprecated.
This function no longer does anything; it was an old approach to managing preferred activities, which has been superseded by (and conflicts with) the modern activity-based preferences.

public boolean addPermission (PermissionInfo info)

Added in API level 1

Add a new dynamic permission to the system. For this to work, your package must have defined a permission tree through the <permission-tree> tag in its manifest. A package can only add permissions to trees that were defined by either its own package or another with the same user id; a permission is in a tree if it matches the name of the permission tree + ".": for example, "com.foo.bar" is a member of the permission tree "com.foo".

It is good to make your permission tree name descriptive, because you are taking possession of that entire set of permission names. Thus, it must be under a domain you control, with a suffix that will not match any normal permissions that may be declared in any applications that are part of that domain.

New permissions must be added before any .apks are installed that use those permissions. Permissions you add through this method are remembered across reboots of the device. If the given permission already exists, the info you supply here will be used to update it.

Parameters
info Description of the permission to be added.
Returns
  • Returns true if a new permission was created, false if an existing one was updated.

public boolean addPermissionAsync (PermissionInfo info)

Added in API level 8

Like addPermission(PermissionInfo) but asynchronously persists the package manager state after returning from the call, allowing it to return quicker and batch a series of adds at the expense of no guarantee the added permission will be retained if the device is rebooted before it is written.

public void addPreferredActivity (IntentFilter filter, int match, ComponentName[] set, ComponentName activity)

Added in API level 1

This method is deprecated.
This is a protected API that should not have been available to third party applications. It is the platform's responsibility for assigning preferred activities and this cannot be directly modified. Add a new preferred activity mapping to the system. This will be used to automatically select the given activity component when Context.startActivity() finds multiple matching activities and also matches the given filter.

Parameters
filter The set of intents under which this activity will be made preferred.
match The IntentFilter match category that this preference applies to.
set The set of activities that the user was picking from when this preference was made.
activity The component name of the activity that is to be preferred.

public String[] canonicalToCurrentPackageNames (String[] names)

Added in API level 8

Map from a packages canonical name to the current name in use on the device.

Parameters
names Array of new names to be mapped.
Returns
  • Returns an array of the same size as the original, containing the current name for each package.

public int checkPermission (String permName, String pkgName)

Added in API level 1

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 int checkSignatures (int uid1, int uid2)

Added in API level 5

Like checkSignatures(String, String), but takes UIDs of the two packages to be checked. This can be useful, for example, when doing the check in an IPC, where the UID is the only identity available. It is functionally identical to determining the package associated with the UIDs and checking their signatures.

Parameters
uid1 First UID whose signature will be compared.
uid2 Second UID whose signature will be compared.
Returns

public int checkSignatures (String pkg1, String pkg2)

Added in API level 1

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 void clearPackagePreferredActivities (String packageName)

Added in API level 1

Remove all preferred activity mappings, previously added with addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName), from the system whose activities are implemented in the given package name. An application can only clear its own package(s).

Parameters
packageName The name of the package whose preferred activity mappings are to be removed.

public String[] currentToCanonicalPackageNames (String[] names)

Added in API level 8

Map from the current package names in use on the device to whatever the current canonical name of that package is.

Parameters
names Array of current names to be mapped.
Returns
  • Returns an array of the same size as the original, containing the canonical name for each package.

public void extendVerificationTimeout (int id, int verificationCodeAtTimeout, long millisecondsToDelay)

Added in API level 17

Allows a package listening to the package verification broadcast to extend the default timeout for a response and declare what action to perform after the timeout occurs. The response must include the verificationCodeAtTimeout which is one of VERIFICATION_ALLOW or VERIFICATION_REJECT. This method may only be called once per package id. Additional calls will have no effect.

Parameters
id pending package identifier as passed via the EXTRA_VERIFICATION_ID Intent extra.
verificationCodeAtTimeout either VERIFICATION_ALLOW or VERIFICATION_REJECT. If verificationCodeAtTimeout is neither VERIFICATION_ALLOW or VERIFICATION_REJECT, then verificationCodeAtTimeout will default to VERIFICATION_REJECT.
millisecondsToDelay the amount of time requested for the timeout. Must be positive and less than MAXIMUM_VERIFICATION_TIMEOUT. If millisecondsToDelay is out of bounds, millisecondsToDelay will be set to the closest in bounds value; namely, 0 or MAXIMUM_VERIFICATION_TIMEOUT.

public Drawable getActivityBanner (Intent intent)

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

Parameters
intent The intent for which you would like to retrieve a banner.
Returns
  • Returns the image of the banner, or null if the activity has no banner specified.

public Drawable getActivityBanner (ComponentName activityName)

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

Parameters
activityName Name of the activity whose banner is to be retrieved.
Returns
  • Returns the image of the banner, or null if the activity has no banner specified.

public Drawable getActivityIcon (Intent intent)

Added in API level 1

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() cannot be found or the Intent cannot be resolved to a component, NameNotFoundException is thrown.

Parameters
intent The intent for which you would like to retrieve an icon.
Returns
  • Returns the image of the icon, or the default activity icon if it could not be found. Does not return null.

public Drawable getActivityIcon (ComponentName activityName)

Added in API level 1

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 cannot be found, NameNotFoundException is thrown.

Parameters
activityName Name of the activity whose icon is to be retrieved.
Returns
  • Returns the image of the icon, or the default activity icon if it could not be found. Does not return null.

public ActivityInfo getActivityInfo (ComponentName className, int flags)

Added in API level 1

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

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

Parameters
className The full component name (i.e. com.google.apps.contacts/com.google.apps.contacts.ContactsList) of an Activity class.
flags Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, to modify the data (in ApplicationInfo) returned.
Returns

public Drawable getActivityLogo (Intent intent)

Added in API level 9

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

Parameters
intent The intent for which you would like to retrieve a logo.
Returns
  • Returns the image of the logo, or null if the activity has no logo specified.

public Drawable getActivityLogo (ComponentName activityName)

Added in API level 9

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

Parameters
activityName Name of the activity whose logo is to be retrieved.
Returns
  • Returns the image of the logo or null if the activity has no logo specified.

public List<PermissionGroupInfo> getAllPermissionGroups (int flags)

Added in API level 1

Retrieve all of the known permission groups in the system.

Parameters
flags Additional option flags. Use GET_META_DATA to retrieve any meta-data associated with the permission group.
Returns
  • Returns a list of PermissionGroupInfo containing information about all of the known permission groups.

public Drawable getApplicationBanner (ApplicationInfo info)

Retrieve the banner associated with an application.

Parameters
info Information about application being queried.
Returns
  • Returns the image of the banner or null if the application has no banner specified.

public Drawable getApplicationBanner (String packageName)

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

Parameters
packageName Name of the package whose application banner is to be retrieved.
Returns
  • Returns the image of the banner or null if the application has no banner specified.

public int getApplicationEnabledSetting (String packageName)

Added in API level 1

Return the the enabled setting for an application. This returns the last value set by setApplicationEnabledSetting(String, int, int); in most cases this value will be COMPONENT_ENABLED_STATE_DEFAULT since the value originally specified in the manifest has not been modified.

Parameters
packageName The component to retrieve.
Returns

public Drawable getApplicationIcon (String packageName)

Added in API level 1

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 cannot be found, NameNotFoundException is thrown.

Parameters
packageName Name of the package whose application icon is to be retrieved.
Returns
  • Returns the image of the icon, or the default application icon if it could not be found. Does not return null.

public Drawable getApplicationIcon (ApplicationInfo info)

Added in API level 1

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

Parameters
info Information about application being queried.
Returns
  • Returns the image of the icon, or the default application icon if it could not be found.

public ApplicationInfo getApplicationInfo (String packageName, int flags)

Added in API level 1

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

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

Parameters
packageName The full name (i.e. com.google.apps.contacts) of an application.
flags Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, GET_UNINSTALLED_PACKAGES to modify the data returned.
Returns
  • ApplicationInfo Returns ApplicationInfo object containing information about the package. If flag GET_UNINSTALLED_PACKAGES is set and if the package is not found in the list of installed applications, the application information is retrieved from the list of uninstalled applications(which includes installed applications as well as applications with data directory ie applications which had been deleted with DONT_DELETE_DATA flag set).

public CharSequence getApplicationLabel (ApplicationInfo info)

Added in API level 1

Return the label to use for this application.

Parameters
info The application to get the label of.
Returns
  • Returns the label associated with this application, or null if it could not be found for any reason.

public Drawable getApplicationLogo (String packageName)

Added in API level 9

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

Parameters
packageName Name of the package whose application logo is to be retrieved.
Returns
  • Returns the image of the logo, or null if no application logo has been specified.

public Drawable getApplicationLogo (ApplicationInfo info)

Added in API level 9

Retrieve the logo associated with an application. If it has not specified a logo, this method returns null.

Parameters
info Information about application being queried.
Returns
  • Returns the image of the logo, or null if no logo is specified by the application.

public int getComponentEnabledSetting (ComponentName componentName)

Added in API level 1

Return the the enabled setting for a package component (activity, receiver, service, provider). This returns the last value set by setComponentEnabledSetting(ComponentName, int, int); in most cases this value will be COMPONENT_ENABLED_STATE_DEFAULT since the value originally specified in the manifest has not been modified.

Parameters
componentName The component to retrieve.
Returns

public Drawable getDefaultActivityIcon ()

Added in API level 1

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

Returns
  • Drawable Image of the icon.

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

Added in API level 1

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. Cannot be null.
resid The resource identifier of the desired image. Cannot 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 List<ApplicationInfo> getInstalledApplications (int flags)

Added in API level 1

Return a List of all application packages that are installed on the device. If flag GET_UNINSTALLED_PACKAGES has been set, a list of all applications including those deleted with DONT_DELETE_DATA (partially installed apps with data directory) will be returned.

Parameters
flags Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, GET_UNINSTALLED_PACKAGES to modify the data returned.
Returns
  • 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. If flag GET_UNINSTALLED_PACKAGES is set, a list of all applications including those deleted with DONT_DELETE_DATA (partially installed apps with data directory) will be returned.

public List<PackageInfo> getInstalledPackages (int flags)

Added in API level 1

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

Parameters
flags Additional option flags. Use any combination of GET_ACTIVITIES, GET_GIDS, GET_CONFIGURATIONS, GET_INSTRUMENTATION, GET_PERMISSIONS, GET_PROVIDERS, GET_RECEIVERS, GET_SERVICES, GET_SIGNATURES, GET_UNINSTALLED_PACKAGES to modify the data 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. If flag GET_UNINSTALLED_PACKAGES is set, a list of all applications including those deleted with DONT_DELETE_DATA (partially installed apps with data directory) will be returned.

public String getInstallerPackageName (String packageName)

Added in API level 5

Retrieve the package name of the application that installed a package. This identifies which market the package came from.

Parameters
packageName The name of the package to query

public InstrumentationInfo getInstrumentationInfo (ComponentName className, int flags)

Added in API level 1

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

Throws PackageManager.NameNotFoundException if instrumentation with the given class name cannot 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 Intent getLaunchIntentForPackage (String packageName)

Added in API level 3

Return a "good" intent to launch a front-door activity in a package, for use for example to implement an "open" button when browsing through packages. The current implementation will look first for a main activity in the category CATEGORY_INFO, next for a main activity in the category CATEGORY_LAUNCHER, or return null if neither are found.

Throws PackageManager.NameNotFoundException if a package with the given name cannot be found on the system.

Parameters
packageName The name of the package to inspect.
Returns
  • Returns either a fully-qualified Intent that can be used to launch the main activity in the package, or null if the package does not contain such an activity.

public Intent getLeanbackLaunchIntentForPackage (String packageName)

Return a "good" intent to launch a front-door Leanback activity in a package, for use for example to implement an "open" button when browsing through packages. The current implementation will look for a main activity in the category CATEGORY_LEANBACK_LAUNCHER, or return null if no main leanback activities are found.

Throws PackageManager.NameNotFoundException if a package with the given name cannot be found on the system.

Parameters
packageName The name of the package to inspect.
Returns
  • Returns either a fully-qualified Intent that can be used to launch the main Leanback activity in the package, or null if the package does not contain such an activity.

public String getNameForUid (int uid)

Added in API level 1

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)

Added in API level 1

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

Parameters
archiveFilePath The path to the archive file
flags Additional option flags. Use any combination of GET_ACTIVITIES, GET_GIDS, GET_CONFIGURATIONS, GET_INSTRUMENTATION, GET_PERMISSIONS, GET_PROVIDERS, GET_RECEIVERS, GET_SERVICES, GET_SIGNATURES, to modify the data returned.
Returns
  • Returns the information about the package. Returns null if the package could not be successfully parsed.

public int[] getPackageGids (String packageName)

Added in API level 1

Return an array of all of the secondary group-ids that have been assigned to a package.

Throws PackageManager.NameNotFoundException if a package with the given name cannot be found on the system.

Parameters
packageName The full name (i.e. com.google.apps.contacts) of the desired package.
Returns
  • Returns an int array of the assigned gids, or null if there are none.

public PackageInfo getPackageInfo (String packageName, int flags)

Added in API level 1

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

Throws PackageManager.NameNotFoundException if a package 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 Additional option flags. Use any combination of GET_ACTIVITIES, GET_GIDS, GET_CONFIGURATIONS, GET_INSTRUMENTATION, GET_PERMISSIONS, GET_PROVIDERS, GET_RECEIVERS, GET_SERVICES, GET_SIGNATURES, GET_UNINSTALLED_PACKAGES to modify the data returned.
Returns
  • Returns a PackageInfo object containing information about the package. If flag GET_UNINSTALLED_PACKAGES is set and if the package is not found in the list of installed applications, the package information is retrieved from the list of uninstalled applications (which includes installed applications as well as applications with data directory i.e. applications which had been deleted with DONT_DELETE_DATA flag set).

public String[] getPackagesForUid (int uid)

Added in API level 1

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 List<PackageInfo> getPackagesHoldingPermissions (String[] permissions, int flags)

Added in API level 18

Return a List of all installed packages that are currently holding any of the given permissions.

Parameters
flags Additional option flags. Use any combination of GET_ACTIVITIES, GET_GIDS, GET_CONFIGURATIONS, GET_INSTRUMENTATION, GET_PERMISSIONS, GET_PROVIDERS, GET_RECEIVERS, GET_SERVICES, GET_SIGNATURES, GET_UNINSTALLED_PACKAGES to modify the data returned.
Returns
  • Returns a List of PackageInfo objects, one for each installed application that is holding any of the permissions that were provided.

public PermissionGroupInfo getPermissionGroupInfo (String name, int flags)

Added in API level 1

Retrieve all of the information we know about a particular group of permissions.

Throws PackageManager.NameNotFoundException if a permission group with the given name cannot be found on the system.

Parameters
name The fully qualified name (i.e. com.google.permission_group.APPS) of the permission you are interested in.
flags Additional option flags. Use GET_META_DATA to retrieve any meta-data associated with the permission group.
Returns

public PermissionInfo getPermissionInfo (String name, int flags)

Added in API level 1

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

Throws PackageManager.NameNotFoundException if a permission with the given name cannot be found on the system.

Parameters
name The fully qualified name (i.e. com.google.permission.LOGIN) of the permission you are interested in.
flags Additional option flags. Use GET_META_DATA to retrieve any meta-data associated with the permission.
Returns
  • Returns a PermissionInfo containing information about the permission.

public int getPreferredActivities (List<IntentFilter> outFilters, List<ComponentName> outActivities, String packageName)

Added in API level 1

Retrieve all preferred activities, previously added with addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName), that are currently registered with the system.

Parameters
outFilters A list in which to place the filters of all of the preferred activities, or null for none.
outActivities A list in which to place the component names of all of the preferred activities, or null for none.
packageName An option package in which you would like to limit the list. If null, all activities will be returned; if non-null, only those activities in the given package are returned.
Returns
  • Returns the total number of registered preferred activities (the number of distinct IntentFilter records, not the number of unique activity components) that were found.

public List<PackageInfo> getPreferredPackages (int flags)

Added in API level 1

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 Additional option flags. Use any combination of GET_ACTIVITIES, GET_GIDS, GET_CONFIGURATIONS, GET_INSTRUMENTATION, GET_PERMISSIONS, GET_PROVIDERS, GET_RECEIVERS, GET_SERVICES, GET_SIGNATURES, to modify the data returned.
Returns
  • Returns a list of PackageInfo objects describing each preferred application, in order of preference.

public ProviderInfo getProviderInfo (ComponentName className, int flags)

Added in API level 9

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

Throws PackageManager.NameNotFoundException if a provider with the given class name cannot be found on the system.

Parameters
className The full component name (i.e. com.google.providers.media/com.google.providers.media.MediaProvider) of a ContentProvider class.
flags Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, to modify the data returned.
Returns
  • ProviderInfo containing information about the service.

public ActivityInfo getReceiverInfo (ComponentName className, int flags)

Added in API level 1

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

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

Parameters
className The full component name (i.e. com.google.apps.calendar/com.google.apps.calendar.CalendarAlarm) of a Receiver class.
flags Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, to modify the data returned.
Returns

public Resources getResourcesForActivity (ComponentName activityName)

Added in API level 1

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 cannot be found, NameNotFoundException is thrown.

Parameters
activityName Name of the activity whose resources are to be retrieved.
Returns
  • Returns the application's Resources.

public Resources getResourcesForApplication (String appPackageName)

Added in API level 1

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 appPackageName cannot be found, NameNotFoundException is thrown.

Parameters
appPackageName Package name of the application whose resources are to be retrieved.
Returns
  • Returns the application's Resources.

public Resources getResourcesForApplication (ApplicationInfo app)

Added in API level 1

Retrieve the resources for an application. Throws NameNotFoundException if the package is no longer installed.

Parameters
app Information about the desired application.
Returns
  • Returns the application's Resources.

public ServiceInfo getServiceInfo (ComponentName className, int flags)

Added in API level 1

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

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

Parameters
className The full component name (i.e. com.google.apps.media/com.google.apps.media.BackgroundPlayback) of a Service class.
flags Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, to modify the data returned.
Returns
  • ServiceInfo containing information about the service.

public FeatureInfo[] getSystemAvailableFeatures ()

Added in API level 5

Get a list of features that are available on the system.

Returns
  • An array of FeatureInfo classes describing the features that are available on the system, or null if there are none(!!).

public String[] getSystemSharedLibraryNames ()

Added in API level 3

Get a list of shared libraries that are available on the system.

Returns
  • An array of shared library names that are available on the system, or null if none are installed.

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

Added in API level 1

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. Cannot be null.
resid The resource identifier of the desired text. Cannot 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 XmlResourceParser getXml (String packageName, int resid, ApplicationInfo appInfo)

Added in API level 1

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. Cannot be null.
resid The resource identifier of the desired xml. Cannot 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 boolean hasSystemFeature (String name)

Added in API level 5

Check whether the given feature name is one of the available features as returned by getSystemAvailableFeatures().

Returns
  • Returns true if the devices supports the feature, else false.

public boolean isSafeMode ()

Added in API level 3

Return whether the device has been booted into safe mode.

public List<ResolveInfo> queryBroadcastReceivers (Intent intent, int flags)

Added in API level 1

Retrieve all receivers that can handle a broadcast of the given intent.

Parameters
intent The desired intent as per resolveActivity().
flags Additional option flags.
Returns
  • A List<ResolveInfo> containing one entry for each matching Receiver. These are ordered from first to last in priority. If there are no matching receivers, an empty list is returned.

public List<ProviderInfo> queryContentProviders (String processName, int uid, int flags)

Added in API level 1

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.
uid If processName is non-null, this is the required uid owning the requested content providers.
flags Additional option flags. Currently should always be 0.
Returns
  • A List<ContentProviderInfo> 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 List<InstrumentationInfo> queryInstrumentation (String targetPackage, int flags)

Added in API level 1

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<InstrumentationInfo> containing one entry for each matching available Instrumentation. Returns an empty list if there is no instrumentation available for the given package.

public List<ResolveInfo> queryIntentActivities (Intent intent, int flags)

Added in API level 1

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 CATEGORY_DEFAULT.
Returns
  • A List<ResolveInfo> 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(Intent, int). If there are no matching activities, an empty list is returned.

public List<ResolveInfo> queryIntentActivityOptions (ComponentName caller, Intent[] specifics, Intent intent, int flags)

Added in API level 1

Retrieve a set of activities that should be presented to the user as similar options. This is like queryIntentActivities(Intent, int), except it also allows you to supply a list of more explicit Intents that you would like to resolve to particular options, and takes care of returning the final ResolveInfo list in a reasonable order, with no duplicates, based on those inputs.

Parameters
caller The class name of the activity that is making the request. This activity will never appear in the output list. Can be null.
specifics An array of Intents that should be resolved to the first specific results. Can be null.
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 CATEGORY_DEFAULT.
Returns
  • A List<ResolveInfo> containing one entry for each matching Activity. These are ordered first by all of the intents resolved in specifics and then any additional activities that can handle intent but did not get included by one of the specifics intents. If there are no matching activities, an empty list is returned.

public List<ResolveInfo> queryIntentContentProviders (Intent intent, int flags)

Added in API level 19

Retrieve all providers that can match the given intent.

Parameters
intent An intent containing all of the desired specification (action, data, type, category, and/or component).
flags Additional option flags.
Returns
  • A List<ResolveInfo> containing one entry for each matching ProviderInfo. These are ordered from best to worst match. If there are no matching providers, an empty list is returned.

public List<ResolveInfo> queryIntentServices (Intent intent, int flags)

Added in API level 1

Retrieve all services that can match the given intent.

Parameters
intent The desired intent as per resolveService().
flags Additional option flags.
Returns
  • A List<ResolveInfo> containing one entry for each matching ServiceInfo. These are ordered from best to worst match -- that is, the first item in the list is what is returned by resolveService(). If there are no matching services, an empty list is returned.

public List<PermissionInfo> queryPermissionsByGroup (String group, int flags)

Added in API level 1

Query for all of the permissions associated with a particular group.

Throws PackageManager.NameNotFoundException if the given group does not exist.

Parameters
group The fully qualified name (i.e. com.google.permission.LOGIN) of the permission group you are interested in. Use null to find all of the permissions not associated with a group.
flags Additional option flags. Use GET_META_DATA to retrieve any meta-data associated with the permissions.
Returns
  • Returns a list of PermissionInfo containing information about all of the permissions in the given group.

public void removePackageFromPreferred (String packageName)

Added in API level 1

This method is deprecated.
This function no longer does anything; it was an old approach to managing preferred activities, which has been superseded by (and conflicts with) the modern activity-based preferences.

public void removePermission (String name)

Added in API level 1

Removes a permission that was previously added with addPermission(PermissionInfo). The same ownership rules apply -- you are only allowed to remove permissions that you are allowed to add.

Parameters
name The name of the permission to remove.

public ResolveInfo resolveActivity (Intent intent, int flags)

Added in API level 1

Determine the best action to perform for a given Intent. This is how resolveActivity(PackageManager) finds an activity if a class has not been explicitly specified.

Note: if using an implicit Intent (without an explicit ComponentName specified), be sure to consider whether to set the MATCH_DEFAULT_ONLY only flag. You need to do so to resolve the activity in the same way that startActivity(Intent) and Intent.resolveActivity(PackageManager) do.

Parameters
intent An intent containing all of the desired specification (action, data, type, category, and/or component).
flags Additional option flags. The most important is MATCH_DEFAULT_ONLY, to limit the resolution to only those activities that support the CATEGORY_DEFAULT.
Returns
  • Returns a ResolveInfo containing the final activity intent that was determined to be the best action. Returns null if no matching activity was found. If multiple matching activities are found and there is no default set, returns a ResolveInfo containing something else, such as the activity resolver.

public ProviderInfo resolveContentProvider (String name, int flags)

Added in API level 1

Find a single content provider by its base path name.

Parameters
name The name of the provider to find.
flags Additional option flags. Currently should always be 0.
Returns
  • ContentProviderInfo Information about the provider, if found, else null.

public ResolveInfo resolveService (Intent intent, int flags)

Added in API level 1

Determine the best service to handle for a given Intent.

Parameters
intent An intent containing all of the desired specification (action, data, type, category, and/or component).
flags Additional option flags.
Returns
  • Returns a ResolveInfo containing the final service intent that was determined to be the best action. Returns null if no matching service was found.

public void setApplicationEnabledSetting (String packageName, int newState, int flags)

Added in API level 1

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. It also overrides the enabled state set in the manifest for any of the application's components. It does not override any enabled state set by setComponentEnabledSetting(ComponentName, int, int) for any of the application's components.

Parameters
packageName The package name of the application to enable
newState The new enabled state for the component. The legal values for this state are: COMPONENT_ENABLED_STATE_ENABLED, COMPONENT_ENABLED_STATE_DISABLED and COMPONENT_ENABLED_STATE_DEFAULT The last one removes the setting, thereby restoring the applications's state to whatever was set in its manifest (or enabled, by default).
flags Optional behavior flags: DONT_KILL_APP or 0.

public void setComponentEnabledSetting (ComponentName componentName, int newState, int flags)

Added in API level 1

Set the enabled setting for a package component (activity, receiver, service, provider). This setting will override any enabled state which may have been set by the component in its manifest.

Parameters
componentName The component to enable
newState The new enabled state for the component. The legal values for this state are: COMPONENT_ENABLED_STATE_ENABLED, COMPONENT_ENABLED_STATE_DISABLED and COMPONENT_ENABLED_STATE_DEFAULT The last one removes the setting, thereby restoring the component's state to whatever was set in it's manifest (or enabled, by default).
flags Optional behavior flags: DONT_KILL_APP or 0.

public void setInstallerPackageName (String targetPackage, String installerPackageName)

Added in API level 11

Change the installer associated with a given package. There are limitations on how the installer package can be changed; in particular:

  • A SecurityException will be thrown if installerPackageName is not signed with the same certificate as the calling application.
  • A SecurityException will be thrown if targetPackage already has an installer package, and that installer package is not signed with the same certificate as the calling application.

Parameters
targetPackage The installed package whose installer will be changed.
installerPackageName The package name of the new installer. May be null to clear the association.

public void verifyPendingInstall (int id, int verificationCode)

Added in API level 14

Allows a package listening to the package verification broadcast to respond to the package manager. The response must include the verificationCode which is one of VERIFICATION_ALLOW or VERIFICATION_REJECT.

Parameters
id pending package identifier as passed via the EXTRA_VERIFICATION_ID Intent extra.
verificationCode either VERIFICATION_ALLOW or VERIFICATION_REJECT.