Most visited

Recently visited

Added in API level 1
Deprecated since API level 24

MockPackageManager

public class MockPackageManager
extends PackageManager

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


此类在API级别24中已被弃用。
使用模拟框架,如Mockito 新的测试应使用Android Testing Support Library编写

模拟PackageManager类。 所有方法都不起作用并抛出UnsupportedOperationException 重写它以提供您需要的操作。

Summary

Inherited constants

From class android.content.pm.PackageManager

Public constructors

MockPackageManager()

Public methods

void addPackageToPreferred(String packageName)

此方法已弃用。 这个功能不再做任何事情; 这是一种管理偏好活动的旧方法,已被现代基于活动的偏好取代(并与之冲突)。

boolean addPermission(PermissionInfo info)

为系统添加一个新的动态权限。

boolean addPermissionAsync(PermissionInfo info)

addPermission(PermissionInfo)一样,但在从调用返回后异步持久化包管理器状态,从而允许它更快地返回并批处理一系列添加,但不保证在写入设备之前重新引导设备时添加的权限将保留。

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

此方法已弃用。 这是一个受保护的API,应该不可用于第三方应用程序。 平台负责分配首选活动,并且不能直接修改。 向系统添加一个新的首选活动映射。 Context.startActivity()找到多个匹配活动并且与给定的过滤器匹配时,这将用于自动选择给定的活动组件。

String[] canonicalToCurrentPackageNames(String[] names)

从软件包规范名称映射到设备上正在使用的当前名称。

int checkPermission(String permName, String pkgName)

检查一个特定的包是否已被授予特定的权限。

int checkSignatures(String pkg1, String pkg2)

比较两个包的签名以确定两个包中是否出现相同的签名。

int checkSignatures(int uid1, int uid2)

checkSignatures(String, String)一样,但需要检查两个软件包的UID。

void clearPackagePreferredActivities(String packageName)

从其活动以给定包名称实现的系统中删除以前与 addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName)添加的所有首选活动映射。

String[] currentToCanonicalPackageNames(String[] names)

从设备上使用的当前软件包名称映射到该软件包当前的规范名称。

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

允许侦听 package verification broadcast的包延长响应的默认超时时间,并声明发生超时后要执行的操作。

Drawable getActivityBanner(Intent intent)

检索与意图关联的横幅。

Drawable getActivityBanner(ComponentName activityName)

检索与活动关联的横幅。

Drawable getActivityIcon(Intent intent)

检索与意图关联的图标。

Drawable getActivityIcon(ComponentName activityName)

检索与活动关联的图标。

ActivityInfo getActivityInfo(ComponentName className, int flags)

检索我们了解的特定活动类的所有信息。

Drawable getActivityLogo(Intent intent)

检索与意图关联的徽标。

Drawable getActivityLogo(ComponentName activityName)

检索与活动关联的徽标。

List<IntentFilter> getAllIntentFilters(String packageName)

获取特定软件包的IntentFilter列表。

List<PermissionGroupInfo> getAllPermissionGroups(int flags)

检索系统中的所有已知权限组。

Drawable getApplicationBanner(ApplicationInfo info)

检索与应用程序关联的横幅。

Drawable getApplicationBanner(String packageName)

检索与应用程序关联的横幅。

int getApplicationEnabledSetting(String packageName)

返回应用程序的启用设置。

Drawable getApplicationIcon(String packageName)

检索与应用程序关联的图标。

Drawable getApplicationIcon(ApplicationInfo info)

检索与应用程序关联的图标。

ApplicationInfo getApplicationInfo(String packageName, int flags)

检索我们所了解的有关特定软件包/应用程序的所有信息。

CharSequence getApplicationLabel(ApplicationInfo info)

返回用于此应用程序的标签。

Drawable getApplicationLogo(String packageName)

检索与应用程序关联的徽标。

Drawable getApplicationLogo(ApplicationInfo info)

检索与应用程序关联的徽标。

int getComponentEnabledSetting(ComponentName componentName)

返回包组件(活动,接收者,服务,提供者)的启用设置。

Drawable getDefaultActivityIcon()

返回未定义特定图标时使用的活动的通用图标。

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

从包中检索图像。

List<ApplicationInfo> getInstalledApplications(int flags)

返回设备上安装的所有应用程序包的列表。

List<PackageInfo> getInstalledPackages(int flags)

返回设备上安装的所有软件包的列表。

String getInstallerPackageName(String packageName)

检索安装软件包的应用程序的软件包名称。

InstrumentationInfo getInstrumentationInfo(ComponentName className, int flags)

检索我们了解的特定仪器类的所有信息。

Intent getLaunchIntentForPackage(String packageName)

返回一个“良好”的意图在包装中发起前门活动。

Intent getLeanbackLaunchIntentForPackage(String packageName)

返回一个“良好”的意图,在包中打开前门Leanback活动,例如在浏览包时使用“打开”按钮。

String getNameForUid(int uid)

检索与用户标识关联的官方名称。

PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags)

检索关于在包归档文件中定义的应用程序包的整体信息

int[] getPackageGids(String packageName)

返回已分配给给定包的所有POSIX辅助组ID的数组。

int[] getPackageGids(String packageName, int flags)

返回已分配给给定包的所有POSIX辅助组ID的数组。

PackageInfo getPackageInfo(String packageName, int flags)

检索有关系统上安装的应用程序包的整体信息。

int getPackageUid(String packageName, int flags)

返回与给定包名称关联的UID。

String[] getPackagesForUid(int uid)

检索与特定用户标识关联的所有软件包的名称。

List<PackageInfo> getPackagesHoldingPermissions(String[] permissions, int flags)

返回当前持有任何给定权限的所有已安装软件包的列表。

PermissionGroupInfo getPermissionGroupInfo(String name, int flags)

检索我们所了解的有关特定权限组的所有信息。

PermissionInfo getPermissionInfo(String name, int flags)

检索我们了解的特定权限的所有信息。

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

检索当前在系统中注册的所有首选活动,以前添加了 addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName)

List<PackageInfo> getPreferredPackages(int flags)

检索当前配置的所有首选软件包列表。

ProviderInfo getProviderInfo(ComponentName className, int flags)

检索我们了解的特定内容提供者类的所有信息。

ActivityInfo getReceiverInfo(ComponentName className, int flags)

检索我们所了解的关于特定接收器类的所有信息。

Resources getResourcesForActivity(ComponentName activityName)

检索与活动关联的资源。

Resources getResourcesForApplication(String appPackageName)

检索与应用程序关联的资源。

Resources getResourcesForApplication(ApplicationInfo app)

检索应用程序的资源。

ServiceInfo getServiceInfo(ComponentName className, int flags)

检索我们了解的特定服务类的所有信息。

FeatureInfo[] getSystemAvailableFeatures()

获取系统中可用功能的列表。

String[] getSystemSharedLibraryNames()

获取系统上可用的共享库列表。

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

从包中检索文本。

Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user, Rect badgeLocation, int badgeDensity)

如果目标用户是主叫用户的托管配置文件,或者主叫方本身是托管配置文件,则会返回给定可绘制副本的标签副本,以便用户将其与原始可绘制区分开来。

Drawable getUserBadgedIcon(Drawable icon, UserHandle user)

如果目标用户是托管配置文件,则会返回给定图标的带有标记的副本,以便将其与原始图标区分开来。

CharSequence getUserBadgedLabel(CharSequence label, UserHandle user)

如果目标用户是主叫用户的托管配置文件,或者主叫方本身是托管配置文件,则会返回该标签的副本,并为可访问性服务(如对讲)制作徽章。

XmlResourceParser getXml(String packageName, int resid, ApplicationInfo appInfo)

从包中检索XML文件。

boolean hasSystemFeature(String name)

检查给定的功能名称是否为 getSystemAvailableFeatures()返回的可用功能 getSystemAvailableFeatures()

boolean hasSystemFeature(String name, int version)

检查给定的功能名称和版本是否为 getSystemAvailableFeatures()返回的可用功能 getSystemAvailableFeatures()

boolean isPermissionRevokedByPolicy(String permName, String pkgName)

检查策略是否已为某个包撤销特定权限。

boolean isSafeMode()

返回设备是否已启动进入安全模式。

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

检索所有可以处理给定意图广播的接收器。

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

检索内容提供商信息。

List<InstrumentationInfo> queryInstrumentation(String targetPackage, int flags)

检索有关可用检测代码的信息。

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

检索可以针对给定意图执行的所有活动。

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

检索一组应该以类似选项呈现给用户的活动。

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

检索可以匹配给定意图的所有提供者。

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

检索可以匹配给定意图的所有服务。

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

查询与特定组关联的所有权限。

void removePackageFromPreferred(String packageName)

此方法已弃用。 这个功能不再做任何事情; 这是一种管理偏好活动的旧方法,已被现代基于活动的偏好取代(并与之冲突)。

void removePermission(String name)

删除以前添加的权限 addPermission(PermissionInfo)

ResolveInfo resolveActivity(Intent intent, int flags)

确定针对给定意图执行的最佳操作。

ProviderInfo resolveContentProvider(String name, int flags)

按其基本路径名称查找单个内容提供者。

ResolveInfo resolveService(Intent intent, int flags)

确定为给定意图处理的最佳服务。

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

设置应用程序的启用设置此设置将覆盖应用程序在其清单中可能已设置的任何启用状态。

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

为包组件(活动,接收者,服务,提供者)设置启用的设置。

void setInstallerPackageName(String targetPackage, String installerPackageName)

更改与给定包关联的安装程序。

void verifyPendingInstall(int id, int verificationCode)

允许侦听 package verification broadcast的软件包响应软件包管理器。

Inherited methods

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

Public constructors

MockPackageManager

Added in API level 1
MockPackageManager ()

Public methods

addPackageToPreferred

Added in API level 1
void addPackageToPreferred (String packageName)

此方法已弃用。
这个功能不再做任何事情; 这是一种管理偏好活动的旧方法,已被现代基于活动的偏好取代(并与之冲突)。

Parameters
packageName String

addPermission

Added in API level 1
boolean addPermission (PermissionInfo info)

为系统添加一个新的动态权限。 为此,您的软件包必须通过清单中的<permission-tree>标记定义权限树。 一个包只能向由自己的包或另一个用相同的用户ID定义的树添加权限; 如果许可树与许可树的名称匹配+“。”,则许可在树中:例如,“com.foo.bar”是许可树“com.foo”的成员。

允许您的权限树名称是描述性的,因为您正在占有整套权限名称。 因此,它必须位于您控制的域下,其后缀不会与可能在属于该域的任何应用程序中声明的任何常规权限相匹配。

在使用这些权限的任何.apks安装之前,必须添加新权限。 通过此方法添加的权限在设备重新启动时会被记住。 如果授予的权限已经存在,则您在此提供的信息将用于更新它。

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

addPermissionAsync

Added in API level 8
boolean addPermissionAsync (PermissionInfo info)

addPermission(PermissionInfo)一样,但在从调用返回后异步持久化包管理器状态,允许它更快地返回并批处理一系列添加,但不保证在写入设备之前重新启动设备时添加的权限将保留。

Parameters
info PermissionInfo
Returns
boolean

addPreferredActivity

Added in API level 1
void addPreferredActivity (IntentFilter filter, 
                int match, 
                ComponentName[] set, 
                ComponentName activity)

此方法已弃用。
这是一个受保护的API,应该不可用于第三方应用程序。 平台负责分配首选活动,并且不能直接修改。 向系统添加一个新的首选活动映射。 Context.startActivity()找到多个匹配活动并且与给定的过滤器匹配时,这将用于自动选择给定的活动组件。

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

canonicalToCurrentPackageNames

Added in API level 8
String[] canonicalToCurrentPackageNames (String[] names)

从软件包规范名称映射到设备上正在使用的当前名称。

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

checkPermission

Added in API level 1
int checkPermission (String permName, 
                String pkgName)

检查一个特定的包是否已被授予特定的权限。

Parameters
permName String: The name of the permission you are checking for.
pkgName String: The name of the package you are checking against.
Returns
int If the package has the permission, PERMISSION_GRANTED is returned. If it does not have the permission, PERMISSION_DENIED is returned.

checkSignatures

Added in API level 1
int checkSignatures (String pkg1, 
                String pkg2)

比较两个包的签名以确定两个包中是否出现相同的签名。 如果它们包含相同的签名,则在彼此协作时允许使用特殊权限:它们可以共享相同的用户标识,相互运行检测等。

Parameters
pkg1 String: First package name whose signature will be compared.
pkg2 String: Second package name whose signature will be compared.
Returns
int Returns an integer indicating whether all signatures on the two packages match. The value is >= 0 (SIGNATURE_MATCH) if all signatures match or < 0 if there is not a match (SIGNATURE_NO_MATCH or SIGNATURE_UNKNOWN_PACKAGE).

checkSignatures

Added in API level 5
int checkSignatures (int uid1, 
                int uid2)

checkSignatures(String, String)一样,但需要检查两个软件包的UID。 例如,在IPC中进行检查时,这可能很有用,其中UID是唯一可用的标识。 它在功能上与确定与UID相关的包并检查其签名的功能相同。

Parameters
uid1 int: First UID whose signature will be compared.
uid2 int: Second UID whose signature will be compared.
Returns
int Returns an integer indicating whether all signatures on the two packages match. The value is >= 0 (SIGNATURE_MATCH) if all signatures match or < 0 if there is not a match (SIGNATURE_NO_MATCH or SIGNATURE_UNKNOWN_PACKAGE).

clearPackagePreferredActivities

Added in API level 1
void clearPackagePreferredActivities (String packageName)

从其活动在给定包名称中实现的系统中删除以前与addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName)添加的所有首选活动映射。 应用程序只能清除自己的包。

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

currentToCanonicalPackageNames

Added in API level 8
String[] currentToCanonicalPackageNames (String[] names)

从设备上使用的当前软件包名称映射到该软件包当前的规范名称。

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

extendVerificationTimeout

Added in API level 17
void extendVerificationTimeout (int id, 
                int verificationCodeAtTimeout, 
                long millisecondsToDelay)

允许侦听package verification broadcast的包延长响应的默认超时时间,并声明发生超时后要执行的操作。 响应必须包含verificationCodeAtTimeout这是一个VERIFICATION_ALLOWVERIFICATION_REJECT 此方法只能在每个包ID中调用一次。 其他呼叫将不起作用。

Parameters
id int: pending package identifier as passed via the EXTRA_VERIFICATION_ID Intent extra.
verificationCodeAtTimeout int: either VERIFICATION_ALLOW or VERIFICATION_REJECT. If verificationCodeAtTimeout is neither VERIFICATION_ALLOW or VERIFICATION_REJECT, then verificationCodeAtTimeout will default to VERIFICATION_REJECT.
millisecondsToDelay long: 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.

getActivityBanner

Added in API level 20
Drawable getActivityBanner (Intent intent)

检索与意图关联的横幅。 如果设置了intent.getClassName(),则只返回getActivityBanner(intent.getClassName())的结果。 否则,它将解析意图的组件并返回与已解析组件关联的横幅。 如果找不到intent.getClassName()或Intent不能解析为组件,则引发NameNotFoundException。

Parameters
intent Intent: The intent for which you would like to retrieve a banner.
Returns
Drawable Returns the image of the banner, or null if the activity has no banner specified.
Throws
PackageManager.NameNotFoundException

getActivityBanner

Added in API level 20
Drawable getActivityBanner (ComponentName activityName)

检索与活动关联的横幅。 给定一个活动的全名,检索关于它的信息并调用ComponentInfo.loadIcon()返回其横幅。 如果找不到该活动,则抛出NameNotFoundException。

Parameters
activityName ComponentName: Name of the activity whose banner is to be retrieved.
Returns
Drawable Returns the image of the banner, or null if the activity has no banner specified.
Throws
PackageManager.NameNotFoundException

getActivityIcon

Added in API level 1
Drawable getActivityIcon (Intent intent)

检索与意图关联的图标。 如果设置了intent.getClassName(),则只返回getActivityIcon(intent.getClassName())的结果。 否则,它会解析意图的组件并返回与解析组件相关联的图标。 如果找不到intent.getClassName()或Intent不能解析为组件,则引发NameNotFoundException。

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

getActivityIcon

Added in API level 1
Drawable getActivityIcon (ComponentName activityName)

检索与活动关联的图标。 给定一个活动的全名,检索关于它的信息并且调用ComponentInfo.loadIcon()返回它的图标。 如果找不到该活动,则抛出NameNotFoundException。

Parameters
activityName ComponentName: Name of the activity whose icon is to be retrieved.
Returns
Drawable Returns the image of the icon, or the default activity icon if it could not be found. Does not return null.
Throws
PackageManager.NameNotFoundException

getActivityInfo

Added in API level 1
ActivityInfo getActivityInfo (ComponentName className, 
                int flags)

检索我们了解的特定活动类的所有信息。

Parameters
className ComponentName: The full component name (i.e. com.google.apps.contacts/com.google.apps.contacts. ContactsList) of an Activity class.
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DEFAULT_ONLY, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
ActivityInfo An ActivityInfo containing information about the activity.
Throws
PackageManager.NameNotFoundException

getActivityLogo

Added in API level 9
Drawable getActivityLogo (Intent intent)

检索与意图关联的徽标。 如果设置了intent.getClassName(),则只返回getActivityLogo(intent.getClassName())的结果。 否则,它会解析意图的组件并返回与已解析组件关联的徽标。 如果找不到intent.getClassName()或Intent不能解析为组件,则引发NameNotFoundException。

Parameters
intent Intent: The intent for which you would like to retrieve a logo.
Returns
Drawable Returns the image of the logo, or null if the activity has no logo specified.
Throws
PackageManager.NameNotFoundException

getActivityLogo

Added in API level 9
Drawable getActivityLogo (ComponentName activityName)

检索与活动关联的徽标。 给定一个活动的全名,检索关于它的信息并且调用ComponentInfo.loadLogo()返回它的标志。 如果找不到该活动,则抛出NameNotFoundException。

Parameters
activityName ComponentName: Name of the activity whose logo is to be retrieved.
Returns
Drawable Returns the image of the logo or null if the activity has no logo specified.
Throws
PackageManager.NameNotFoundException

getAllIntentFilters

Added in API level 23
List<IntentFilter> getAllIntentFilters (String packageName)

获取特定软件包的IntentFilter列表。

Parameters
packageName String: the package name. This parameter is set to a non null value, the list will contain all the IntentFilter for that package. Otherwise, the list will be empty.
Returns
List<IntentFilter> a list of IntentFilter for a specific package.

getAllPermissionGroups

Added in API level 1
List<PermissionGroupInfo> getAllPermissionGroups (int flags)

检索系统中的所有已知权限组。

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

getApplicationBanner

Added in API level 20
Drawable getApplicationBanner (ApplicationInfo info)

检索与应用程序关联的横幅。

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

getApplicationBanner

Added in API level 20
Drawable getApplicationBanner (String packageName)

检索与应用程序关联的横幅。 给定应用程序包的名称,检索关于它的信息并调用getApplicationIcon()返回其横幅。 如果找不到应用程序,则引发NameNotFoundException。

Parameters
packageName String: Name of the package whose application banner is to be retrieved.
Returns
Drawable Returns the image of the banner or null if the application has no banner specified.
Throws
PackageManager.NameNotFoundException

getApplicationEnabledSetting

Added in API level 1
int getApplicationEnabledSetting (String packageName)

返回应用程序的启用设置。 这将返回由setApplicationEnabledSetting(String, int, int)设置的最后一个值; 在大多数情况下,该值将是COMPONENT_ENABLED_STATE_DEFAULT因为清单中最初指定的值未被修改。

Parameters
packageName String: The package name of the application to retrieve.
Returns
int Returns the current enabled state for the application. May be one of COMPONENT_ENABLED_STATE_ENABLED, COMPONENT_ENABLED_STATE_DISABLED, or COMPONENT_ENABLED_STATE_DEFAULT. The last one means the application's enabled state is based on the original information in the manifest as found in ComponentInfo.

getApplicationIcon

Added in API level 1
Drawable getApplicationIcon (String packageName)

检索与应用程序关联的图标。 给定应用程序包的名称,检索关于它的信息并调用getApplicationIcon()返回其图标。 如果找不到应用程序,则引发NameNotFoundException。

Parameters
packageName String: Name of the package whose application icon is to be retrieved.
Returns
Drawable Returns the image of the icon, or the default application icon if it could not be found. Does not return null.
Throws
PackageManager.NameNotFoundException

getApplicationIcon

Added in API level 1
Drawable getApplicationIcon (ApplicationInfo info)

检索与应用程序关联的图标。 如果它没有定义图标,则返回默认的应用程序图标。 不返回null。

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

getApplicationInfo

Added in API level 1
ApplicationInfo getApplicationInfo (String packageName, 
                int flags)

检索我们所了解的有关特定软件包/应用程序的所有信息。

Parameters
packageName String: The full name (i.e. com.google.apps.contacts) of an application.
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, MATCH_SYSTEM_ONLY, MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
ApplicationInfo An ApplicationInfo containing information about the package. If flag MATCH_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 i.e. applications which had been deleted with DONT_DELETE_DATA flag set).
Throws
PackageManager.NameNotFoundException

getApplicationLabel

Added in API level 1
CharSequence getApplicationLabel (ApplicationInfo info)

返回用于此应用程序的标签。

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

getApplicationLogo

Added in API level 9
Drawable getApplicationLogo (String packageName)

检索与应用程序关联的徽标。 鉴于应用程序包的名称,检索有关它的信息并调用getApplicationLogo()返回其徽标。 如果找不到应用程序,则引发NameNotFoundException。

Parameters
packageName String: Name of the package whose application logo is to be retrieved.
Returns
Drawable Returns the image of the logo, or null if no application logo has been specified.
Throws
PackageManager.NameNotFoundException

getApplicationLogo

Added in API level 9
Drawable getApplicationLogo (ApplicationInfo info)

检索与应用程序关联的徽标。 如果它没有指定徽标,则此方法返回null。

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

getComponentEnabledSetting

Added in API level 1
int getComponentEnabledSetting (ComponentName componentName)

返回包组件(活动,接收者,服务,提供者)的启用设置。 这返回由setComponentEnabledSetting(ComponentName, int, int)设置的最后一个值; 在大多数情况下,这个值将是COMPONENT_ENABLED_STATE_DEFAULT因为清单中最初指定的值尚未修改。

Parameters
componentName ComponentName: The component to retrieve.
Returns
int Returns the current enabled state for the component. May be one of COMPONENT_ENABLED_STATE_ENABLED, COMPONENT_ENABLED_STATE_DISABLED, or COMPONENT_ENABLED_STATE_DEFAULT. The last one means the component's enabled state is based on the original information in the manifest as found in ComponentInfo.

getDefaultActivityIcon

Added in API level 1
Drawable getDefaultActivityIcon ()

返回未定义特定图标时使用的活动的通用图标。

Returns
Drawable Drawable Image of the icon.

getDrawable

Added in API level 1
Drawable getDrawable (String packageName, 
                int resid, 
                ApplicationInfo appInfo)

从包中检索图像。 这是各种包管理器信息结构(例如ComponentInfo用于实现其关联图标检索的低级API。

Parameters
packageName String: The name of the package that this icon is coming from. Cannot be null.
resid int: The resource identifier of the desired image. Cannot be 0.
appInfo ApplicationInfo: 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
Drawable Returns a Drawable holding the requested image. Returns null if an image could not be found for any reason.

getInstalledApplications

Added in API level 1
List<ApplicationInfo> getInstalledApplications (int flags)

返回设备上安装的所有应用程序包的列表。 如果已设置标志GET_UNINSTALLED_PACKAGES,则将返回包含使用DONT_DELETE_DATA (部分安装的具有数据目录的应用程序)删除的应用程序的列表。

Parameters
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, MATCH_SYSTEM_ONLY, MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
List<ApplicationInfo> A List of ApplicationInfo objects, one for each installed application. In the unlikely case there are no installed packages, an empty list is returned. If flag MATCH_UNINSTALLED_PACKAGES is set, the application 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).

getInstalledPackages

Added in API level 1
List<PackageInfo> getInstalledPackages (int flags)

返回设备上安装的所有软件包的列表。

Parameters
flags int: Additional option flags. Use any combination of GET_ACTIVITIES, GET_CONFIGURATIONS, GET_GIDS, GET_INSTRUMENTATION, GET_INTENT_FILTERS, GET_META_DATA, GET_PERMISSIONS, GET_PROVIDERS, GET_RECEIVERS, GET_SERVICES, GET_SHARED_LIBRARY_FILES, GET_SIGNATURES, GET_URI_PERMISSION_PATTERNS, GET_UNINSTALLED_PACKAGES, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
List<PackageInfo> A List of PackageInfo objects, one for each installed package, containing information about the package. In the unlikely case there are no installed packages, an empty list is returned. If flag MATCH_UNINSTALLED_PACKAGES is set, 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).

getInstallerPackageName

Added in API level 5
String getInstallerPackageName (String packageName)

检索安装软件包的应用程序的软件包名称。 这标识了该软件包来自哪个市场。

Parameters
packageName String: The name of the package to query
Returns
String

getInstrumentationInfo

Added in API level 1
InstrumentationInfo getInstrumentationInfo (ComponentName className, 
                int flags)

检索我们了解的特定仪器类的所有信息。

Parameters
className ComponentName: The full name (i.e. com.google.apps.contacts.InstrumentList) of an Instrumentation class.
flags int: Additional option flags. Use any combination of GET_META_DATA to modify the data returned.
Returns
InstrumentationInfo An InstrumentationInfo object containing information about the instrumentation.
Throws
PackageManager.NameNotFoundException

getLaunchIntentForPackage

Added in API level 3
Intent getLaunchIntentForPackage (String packageName)

返回一个“良好”的意图在包装中发起前门活动。 例如,这用于在浏览包时实现“打开”按钮。 目前的实现首先查找在类别中的主要活动CATEGORY_INFO ,并在下一类为主要活动CATEGORY_LAUNCHER 如果未找到,则返回null

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

getLeanbackLaunchIntentForPackage

Added in API level 21
Intent getLeanbackLaunchIntentForPackage (String packageName)

返回一个“良好”的意图,在包中打开前门Leanback活动,例如在浏览包时使用“打开”按钮。 当前的实现将在类别CATEGORY_LEANBACK_LAUNCHER查找主要活动,如果未找到主要的回滚活动,则返回null。

Parameters
packageName String: The name of the package to inspect.
Returns
Intent 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.

getNameForUid

Added in API level 1
String getNameForUid (int uid)

检索与用户标识关联的官方名称。 这个名字保证永远不会改变,尽管可以改变底层用户ID。 也就是说,如果要将有关用户标识的信息存储在持久性存储中,则应该使用此函数返回的字符串而不是原始用户标识。

Parameters
uid int: The user id for which you would like to retrieve a name.
Returns
String Returns a unique name for the given user id, or null if the user id is not currently assigned.

getPackageArchiveInfo

Added in API level 1
PackageInfo getPackageArchiveInfo (String archiveFilePath, 
                int flags)

检索关于在包归档文件中定义的应用程序包的整体信息

Parameters
archiveFilePath String: The path to the archive file
flags int: Additional option flags. Use any combination of GET_ACTIVITIES, GET_CONFIGURATIONS, GET_GIDS, GET_INSTRUMENTATION, GET_INTENT_FILTERS, GET_META_DATA, GET_PERMISSIONS, GET_PROVIDERS, GET_RECEIVERS, GET_SERVICES, GET_SHARED_LIBRARY_FILES, GET_SIGNATURES, GET_URI_PERMISSION_PATTERNS, GET_UNINSTALLED_PACKAGES, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
PackageInfo A PackageInfo object containing information about the package archive. If the package could not be parsed, returns null.

getPackageGids

Added in API level 1
int[] getPackageGids (String packageName)

返回已分配给给定包的所有POSIX辅助组ID的数组。

请注意,相同设备上的相同包可能在不同的 UserHandle下具有不同的GID。

Parameters
packageName String: The full name (i.e. com.google.apps.contacts) of the desired package.
Returns
int[] Returns an int array of the assigned GIDs, or null if there are none.
Throws
PackageManager.NameNotFoundException

getPackageGids

Added in API level 24
int[] getPackageGids (String packageName, 
                int flags)

返回已分配给给定包的所有POSIX辅助组ID的数组。

请注意,相同设备上的相同包可能在不同的 UserHandle下具有不同的GID。

Parameters
packageName String: The full name (i.e. com.google.apps.contacts) of the desired package.
flags int
Returns
int[] Returns an int array of the assigned gids, or null if there are none.
Throws
PackageManager.NameNotFoundException

getPackageInfo

Added in API level 1
PackageInfo getPackageInfo (String packageName, 
                int flags)

检索有关系统上安装的应用程序包的整体信息。

Parameters
packageName String: The full name (i.e. com.google.apps.contacts) of the desired package.
flags int: Additional option flags. Use any combination of GET_ACTIVITIES, GET_CONFIGURATIONS, GET_GIDS, GET_INSTRUMENTATION, GET_INTENT_FILTERS, GET_META_DATA, GET_PERMISSIONS, GET_PROVIDERS, GET_RECEIVERS, GET_SERVICES, GET_SHARED_LIBRARY_FILES, GET_SIGNATURES, GET_URI_PERMISSION_PATTERNS, GET_UNINSTALLED_PACKAGES, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
PackageInfo A PackageInfo object containing information about the package. If flag MATCH_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).
Throws
PackageManager.NameNotFoundException

getPackageUid

Added in API level 24
int getPackageUid (String packageName, 
                int flags)

返回与给定包名称关联的UID。

请注意,相同设备上的相同包将在不同的 UserHandle下具有不同的UID。

Parameters
packageName String: The full name (i.e. com.google.apps.contacts) of the desired package.
flags int
Returns
int Returns an integer UID who owns the given package name.
Throws
PackageManager.NameNotFoundException

getPackagesForUid

Added in API level 1
String[] getPackagesForUid (int uid)

检索与特定用户标识关联的所有软件包的名称。 在大多数情况下,这将是一个包名称,即已分配了该用户标识的包。 在有多个包通过“sharedUserId”机制共享相同用户ID的情况下,将返回具有该ID的所有包。

Parameters
uid int: The user id for which you would like to retrieve the associated packages.
Returns
String[] 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.

getPackagesHoldingPermissions

Added in API level 18
List<PackageInfo> getPackagesHoldingPermissions (String[] permissions, 
                int flags)

返回当前持有任何给定权限的所有已安装软件包的列表。

Parameters
permissions String
flags int: Additional option flags. Use any combination of GET_ACTIVITIES, GET_CONFIGURATIONS, GET_GIDS, GET_INSTRUMENTATION, GET_INTENT_FILTERS, GET_META_DATA, GET_PERMISSIONS, GET_PROVIDERS, GET_RECEIVERS, GET_SERVICES, GET_SHARED_LIBRARY_FILES, GET_SIGNATURES, GET_URI_PERMISSION_PATTERNS, GET_UNINSTALLED_PACKAGES, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
List<PackageInfo> A List of PackageInfo objects, one for each installed package that holds any of the permissions that were provided, containing information about the package. If no installed packages hold any of the permissions, an empty list is returned. If flag MATCH_UNINSTALLED_PACKAGES is set, 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).

getPermissionGroupInfo

Added in API level 1
PermissionGroupInfo getPermissionGroupInfo (String name, 
                int flags)

检索我们所了解的有关特定权限组的所有信息。

Parameters
name String: The fully qualified name (i.e. com.google.permission_group.APPS) of the permission you are interested in.
flags int: Additional option flags. Use GET_META_DATA to retrieve any meta-data associated with the permission group.
Returns
PermissionGroupInfo Returns a PermissionGroupInfo containing information about the permission.
Throws
PackageManager.NameNotFoundException

getPermissionInfo

Added in API level 1
PermissionInfo getPermissionInfo (String name, 
                int flags)

检索我们了解的特定权限的所有信息。

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

getPreferredActivities

Added in API level 1
int getPreferredActivities (List<IntentFilter> outFilters, 
                List<ComponentName> outActivities, 
                String packageName)

检索当前在系统中注册的所有首选活动,以前添加了 addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName)

Parameters
outFilters List: A required list in which to place the filters of all of the preferred activities.
outActivities List: A required list in which to place the component names of all of the preferred activities.
packageName String: An optional 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
int Returns the total number of registered preferred activities (the number of distinct IntentFilter records, not the number of unique activity components) that were found.

getPreferredPackages

Added in API level 1
List<PackageInfo> getPreferredPackages (int flags)

检索当前配置的所有首选软件包列表。 列表中的第一个包是最优选的,最后一个是最不优选的。

Parameters
flags int: Additional option flags. Use any combination of GET_ACTIVITIES, GET_CONFIGURATIONS, GET_GIDS, GET_INSTRUMENTATION, GET_INTENT_FILTERS, GET_META_DATA, GET_PERMISSIONS, GET_PROVIDERS, GET_RECEIVERS, GET_SERVICES, GET_SHARED_LIBRARY_FILES, GET_SIGNATURES, GET_URI_PERMISSION_PATTERNS, GET_UNINSTALLED_PACKAGES, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
List<PackageInfo> A List of PackageInfo objects, one for each preferred application, in order of preference.

getProviderInfo

Added in API level 9
ProviderInfo getProviderInfo (ComponentName className, 
                int flags)

检索我们了解的特定内容提供者类的所有信息。

Parameters
className ComponentName: The full component name (i.e. com.google.providers.media/com.google.providers.media. MediaProvider) of a ContentProvider class.
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DEFAULT_ONLY, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
ProviderInfo A ProviderInfo object containing information about the provider.
Throws
PackageManager.NameNotFoundException

getReceiverInfo

Added in API level 1
ActivityInfo getReceiverInfo (ComponentName className, 
                int flags)

检索我们所了解的关于特定接收器类的所有信息。

Parameters
className ComponentName: The full component name (i.e. com.google.apps.calendar/com.google.apps.calendar. CalendarAlarm) of a Receiver class.
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DEFAULT_ONLY, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
ActivityInfo An ActivityInfo containing information about the receiver.
Throws
PackageManager.NameNotFoundException

getResourcesForActivity

Added in API level 1
Resources getResourcesForActivity (ComponentName activityName)

检索与活动关联的资源。 给定活动的全名,检索关于它的信息并调用getResources()返回其应用程序的资源。 如果找不到该活动,则抛出NameNotFoundException。

Parameters
activityName ComponentName: Name of the activity whose resources are to be retrieved.
Returns
Resources Returns the application's Resources.
Throws
PackageManager.NameNotFoundException

getResourcesForApplication

Added in API level 1
Resources getResourcesForApplication (String appPackageName)

检索与应用程序关联的资源。 给定应用程序的完整软件包名称,检索关于它的信息并调用getResources()来返回其应用程序的资源。 如果找不到appPackageName,则引发NameNotFoundException。

Parameters
appPackageName String: Package name of the application whose resources are to be retrieved.
Returns
Resources Returns the application's Resources.
Throws
PackageManager.NameNotFoundException

getResourcesForApplication

Added in API level 1
Resources getResourcesForApplication (ApplicationInfo app)

检索应用程序的资源。 如果程序包不再安装,则抛出NameNotFoundException。

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

getServiceInfo

Added in API level 1
ServiceInfo getServiceInfo (ComponentName className, 
                int flags)

检索我们了解的特定服务类的所有信息。

Parameters
className ComponentName: The full component name (i.e. com.google.apps.media/com.google.apps.media. BackgroundPlayback) of a Service class.
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DEFAULT_ONLY, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
ServiceInfo A ServiceInfo object containing information about the service.
Throws
PackageManager.NameNotFoundException

getSystemAvailableFeatures

Added in API level 5
FeatureInfo[] getSystemAvailableFeatures ()

获取系统中可用功能的列表。

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

getSystemSharedLibraryNames

Added in API level 3
String[] getSystemSharedLibraryNames ()

获取系统上可用的共享库列表。

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

getText

Added in API level 1
CharSequence getText (String packageName, 
                int resid, 
                ApplicationInfo appInfo)

从包中检索文本。 这是各种包管理器信息结构(例如ComponentInfo用于实现其关联标签和其他文本检索的低级API。

Parameters
packageName String: The name of the package that this text is coming from. Cannot be null.
resid int: The resource identifier of the desired text. Cannot be 0.
appInfo ApplicationInfo: 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
CharSequence Returns a CharSequence holding the requested text. Returns null if the text could not be found for any reason.

getUserBadgedDrawableForDensity

Added in API level 21
Drawable getUserBadgedDrawableForDensity (Drawable drawable, 
                UserHandle user, 
                Rect badgeLocation, 
                int badgeDensity)

如果目标用户是主叫用户的托管配置文件,或者主叫方本身是托管配置文件,则会返回给定可绘制副本的标签副本,以便用户将其与原始可绘制区分开来。 来电者可以指定要在其中应用徽章的徽章的边界中的位置以及要使用的徽章的密度。

如果原始drawable是一个BitmapDrawable,并且支持位图可根据 isMutable() ,则会在适当位置执行徽章并返回原始drawable。

Parameters
drawable Drawable: The drawable to badge.
user UserHandle: The target user.
badgeLocation Rect: Where in the bounds of the badged drawable to place the badge. If it's null, the badge is applied on top of the entire drawable being badged.
badgeDensity int: The optional desired density for the badge as per densityDpi. If it's not positive, the density of the display is used.
Returns
Drawable A drawable that combines the original drawable and a badge as determined by the system.

getUserBadgedIcon

Added in API level 21
Drawable getUserBadgedIcon (Drawable icon, 
                UserHandle user)

如果目标用户是托管配置文件,则会返回给定图标的带有标记的副本,以便将其与原始图标区分开来。 用于标记任意可绘制的用途getUserBadgedDrawableForDensity(android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)

如果原始drawable是一个BitmapDrawable,并且支持位图可根据 isMutable() ,则会在适当位置执行徽章并返回原始drawable。

Parameters
icon Drawable: The icon to badge.
user UserHandle: The target user.
Returns
Drawable A drawable that combines the original icon and a badge as determined by the system.

getUserBadgedLabel

Added in API level 21
CharSequence getUserBadgedLabel (CharSequence label, 
                UserHandle user)

如果目标用户是主叫用户的托管配置文件,或者主叫方本身是托管配置文件,则会返回该标签的副本,并为可访问性服务(如对讲)制作徽章。 例如传入“电子邮件”,它可能会在工作资料中返回“工作电子邮件”电子邮件。

Parameters
label CharSequence: The label to change.
user UserHandle: The target user.
Returns
CharSequence A label that combines the original label and a badge as determined by the system.

getXml

Added in API level 1
XmlResourceParser getXml (String packageName, 
                int resid, 
                ApplicationInfo appInfo)

从包中检索XML文件。 这是一个用于检索XML元数据的低级API。

Parameters
packageName String: The name of the package that this xml is coming from. Cannot be null.
resid int: The resource identifier of the desired xml. Cannot be 0.
appInfo ApplicationInfo: 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
XmlResourceParser Returns an XmlPullParser allowing you to parse out the XML data. Returns null if the xml resource could not be found for any reason.

hasSystemFeature

Added in API level 5
boolean hasSystemFeature (String name)

检查给定的功能名称是否为getSystemAvailableFeatures()返回的可用功能getSystemAvailableFeatures() 这测试是否存在给定功能名称的任何版本; 使用hasSystemFeature(String, int)检查最低版本。

Parameters
name String
Returns
boolean Returns true if the devices supports the feature, else false.

hasSystemFeature

Added in API level 24
boolean hasSystemFeature (String name, 
                int version)

检查给定的功能名称和版本是否为getSystemAvailableFeatures()返回的可用功能getSystemAvailableFeatures() 由于功能被定义为始终向后兼容,如果可用功能版本大于或等于请求版本,则返回true。

Parameters
name String
version int
Returns
boolean Returns true if the devices supports the feature, else false.

isPermissionRevokedByPolicy

Added in API level 23
boolean isPermissionRevokedByPolicy (String permName, 
                String pkgName)

检查策略是否已为某个包撤销特定权限。 通常,设备所有者或配置文件所有者可以应用这样的策略。 用户不能授予策略撤销的权限,因此应用获得此类权限的唯一方法是通过策略更改。

Parameters
permName String: The name of the permission you are checking for.
pkgName String: The name of the package you are checking against.
Returns
boolean Whether the permission is restricted by policy.

isSafeMode

Added in API level 3
boolean isSafeMode ()

返回设备是否已启动进入安全模式。

Returns
boolean

queryBroadcastReceivers

Added in API level 1
List<ResolveInfo> queryBroadcastReceivers (Intent intent, 
                int flags)

检索所有可以处理给定意图广播的接收器。

Parameters
intent Intent: The desired intent as per resolveActivity().
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_RESOLVED_FILTER, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DEFAULT_ONLY, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY or MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
List<ResolveInfo> Returns a List of ResolveInfo objects containing one entry for each matching receiver, ordered from best to worst. If there are no matching receivers, an empty list or null is returned.

queryContentProviders

Added in API level 1
List<ProviderInfo> queryContentProviders (String processName, 
                int uid, 
                int flags)

检索内容提供商信息。

注意:与大多数其他方法不同,空结果集由空返回而不是空列表表示。

Parameters
processName String: 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 int: If processName is non-null, this is the required uid owning the requested content providers.
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DEFAULT_ONLY, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY or MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
List<ProviderInfo> A list of ProviderInfo objects containing one entry for each provider either matching processName or, if processName is null, all known content providers. If there are no matching providers, null is returned.

queryInstrumentation

Added in API level 1
List<InstrumentationInfo> queryInstrumentation (String targetPackage, 
                int flags)

检索有关可用检测代码的信息。 可以用来检索所有的检测代码,或者只检索针对特定软件包的代码。

Parameters
targetPackage String: If null, all instrumentation is returned; only the instrumentation targeting this package name is returned.
flags int: Additional option flags. Use any combination of GET_META_DATA to modify the data returned.
Returns
List<InstrumentationInfo> A list of InstrumentationInfo objects containing one entry for each matching instrumentation. If there are no instrumentation available, returns an empty list.

queryIntentActivities

Added in API level 1
List<ResolveInfo> queryIntentActivities (Intent intent, 
                int flags)

检索可以针对给定意图执行的所有活动。

Parameters
intent Intent: The desired intent as per resolveActivity().
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_RESOLVED_FILTER, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DEFAULT_ONLY, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY or MATCH_UNINSTALLED_PACKAGES to modify the data returned. The most important is MATCH_DEFAULT_ONLY, to limit the resolution to only those activities that support the CATEGORY_DEFAULT. Or, set MATCH_ALL to prevent any filtering of the results.
Returns
List<ResolveInfo> Returns a List of ResolveInfo objects containing one entry for each matching activity, ordered from best to worst. In other words, the first item is what would be returned by resolveActivity(Intent, int). If there are no matching activities, an empty list is returned.

queryIntentActivityOptions

Added in API level 1
List<ResolveInfo> queryIntentActivityOptions (ComponentName caller, 
                Intent[] specifics, 
                Intent intent, 
                int flags)

检索一组应该以类似选项呈现给用户的活动。 这就像queryIntentActivities(Intent, int) ,除了它还允许你提供一个你想要解析为特定选项的更明确的Intents列表,并根据这些输入按照合理的顺序返回最终的ResolveInfo列表,并且没有重复。

Parameters
caller ComponentName: The class name of the activity that is making the request. This activity will never appear in the output list. Can be null.
specifics Intent: An array of Intents that should be resolved to the first specific results. Can be null.
intent Intent: The desired intent as per resolveActivity().
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_RESOLVED_FILTER, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DEFAULT_ONLY, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY or MATCH_UNINSTALLED_PACKAGES to modify the data returned. The most important is MATCH_DEFAULT_ONLY, to limit the resolution to only those activities that support the CATEGORY_DEFAULT.
Returns
List<ResolveInfo> Returns a List of ResolveInfo objects containing one entry for each matching activity. The list is 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.

queryIntentContentProviders

Added in API level 19
List<ResolveInfo> queryIntentContentProviders (Intent intent, 
                int flags)

检索可以匹配给定意图的所有提供者。

Parameters
intent Intent: An intent containing all of the desired specification (action, data, type, category, and/or component).
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_RESOLVED_FILTER, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DEFAULT_ONLY, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY or MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
List<ResolveInfo> Returns a List of ResolveInfo objects containing one entry for each matching provider, ordered from best to worst. If there are no matching services, an empty list or null is returned.

queryIntentServices

Added in API level 1
List<ResolveInfo> queryIntentServices (Intent intent, 
                int flags)

检索可以匹配给定意图的所有服务。

Parameters
intent Intent: The desired intent as per resolveService().
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_RESOLVED_FILTER, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DEFAULT_ONLY, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY or MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
List<ResolveInfo> Returns a List of ResolveInfo objects containing one entry for each matching service, ordered from best to worst. In other words, the first item is what would be returned by resolveService(Intent, int). If there are no matching services, an empty list or null is returned.

queryPermissionsByGroup

Added in API level 1
List<PermissionInfo> queryPermissionsByGroup (String group, 
                int flags)

查询与特定组关联的所有权限。

Parameters
group String: 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 int: Additional option flags. Use GET_META_DATA to retrieve any meta-data associated with the permissions.
Returns
List<PermissionInfo> Returns a list of PermissionInfo containing information about all of the permissions in the given group.
Throws
PackageManager.NameNotFoundException

removePackageFromPreferred

Added in API level 1
void removePackageFromPreferred (String packageName)

此方法已弃用。
这个功能不再做任何事情; 这是一种管理偏好活动的旧方法,已被现代基于活动的偏好取代(并与之冲突)。

Parameters
packageName String

removePermission

Added in API level 1
void removePermission (String name)

删除以前添加的权限addPermission(PermissionInfo) 相同的所有权规则适用 - 您只能删除允许添加的权限。

Parameters
name String: The name of the permission to remove.

resolveActivity

Added in API level 1
ResolveInfo resolveActivity (Intent intent, 
                int flags)

确定针对给定意图执行的最佳操作。 这就是resolveActivity(PackageManager)如果没有明确指定类的情况下如何找到活动。

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 Intent: An intent containing all of the desired specification (action, data, type, category, and/or component).
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_RESOLVED_FILTER, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DEFAULT_ONLY, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY or MATCH_UNINSTALLED_PACKAGES to modify the data returned. The most important is MATCH_DEFAULT_ONLY, to limit the resolution to only those activities that support the CATEGORY_DEFAULT.
Returns
ResolveInfo Returns a ResolveInfo object 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 object containing something else, such as the activity resolver.

resolveContentProvider

Added in API level 1
ProviderInfo resolveContentProvider (String name, 
                int flags)

按其基本路径名称查找单个内容提供者。

Parameters
name String: The name of the provider to find.
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DEFAULT_ONLY, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY or MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
ProviderInfo A ProviderInfo object containing information about the provider. If a provider was not found, returns null.

resolveService

Added in API level 1
ResolveInfo resolveService (Intent intent, 
                int flags)

确定为给定意图处理的最佳服务。

Parameters
intent Intent: An intent containing all of the desired specification (action, data, type, category, and/or component).
flags int: Additional option flags. Use any combination of GET_META_DATA, GET_RESOLVED_FILTER, GET_SHARED_LIBRARY_FILES, MATCH_ALL, MATCH_DISABLED_COMPONENTS, MATCH_DISABLED_UNTIL_USED_COMPONENTS, MATCH_DEFAULT_ONLY, MATCH_DIRECT_BOOT_AWARE, MATCH_DIRECT_BOOT_UNAWARE, MATCH_SYSTEM_ONLY or MATCH_UNINSTALLED_PACKAGES to modify the data returned.
Returns
ResolveInfo Returns a ResolveInfo object containing the final service intent that was determined to be the best action. Returns null if no matching service was found.

setApplicationEnabledSetting

Added in API level 1
void setApplicationEnabledSetting (String packageName, 
                int newState, 
                int flags)

设置应用程序的启用设置此设置将覆盖应用程序在其清单中可能已设置的任何启用状态。 它还覆盖了清单中为应用程序的任何组件设置的启用状态。 它不会覆盖任何应用程序组件的任何由setComponentEnabledSetting(ComponentName, int, int)设置的启用状态。

Parameters
packageName String: The package name of the application to enable
newState int: 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 int: Optional behavior flags: DONT_KILL_APP or 0.

setComponentEnabledSetting

Added in API level 1
void setComponentEnabledSetting (ComponentName componentName, 
                int newState, 
                int flags)

为包组件(活动,接收者,服务,提供者)设置启用的设置。 该设置将覆盖组件在其清单中可能已设置的任何启用状态。

Parameters
componentName ComponentName: The component to enable
newState int: 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 int: Optional behavior flags: DONT_KILL_APP or 0.

setInstallerPackageName

Added in API level 11
void setInstallerPackageName (String targetPackage, 
                String installerPackageName)

更改与给定包关联的安装程序。 安装程序包的更改方式存在限制; 尤其是:

  • 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 String: The installed package whose installer will be changed.
installerPackageName String: The package name of the new installer. May be null to clear the association.

verifyPendingInstall

Added in API level 14
void verifyPendingInstall (int id, 
                int verificationCode)

允许收听package verification broadcast的包来响应包管理器。 响应必须包含verificationCode ,即VERIFICATION_ALLOWVERIFICATION_REJECT

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

Hooray!