LauncherApps
public
class
LauncherApps
extends Object
| java.lang.Object | |
| ↳ | android.content.pm.LauncherApps |
Class for retrieving a list of launchable activities for the current user and any associated managed profiles. This is mainly for use by launchers. Apps can be queried for each user profile. Since the PackageManager will not deliver package broadcasts for other profiles, you can register for package changes here.
To watch for managed profiles being added or removed, register for the following broadcasts:
ACTION_MANAGED_PROFILE_ADDED and ACTION_MANAGED_PROFILE_REMOVED.
You can retrieve the list of profiles associated with this user with
getUserProfiles().
Summary
Nested classes | |
|---|---|
class |
LauncherApps.Callback
Callbacks for package changes to this and related managed profiles. |
class |
LauncherApps.ShortcutQuery
Represents a query passed to |
Public methods | |
|---|---|
List<LauncherActivityInfo>
|
getActivityList(String packageName, UserHandle user)
Retrieves a list of launchable activities that match |
Drawable
|
getShortcutBadgedIconDrawable(ShortcutInfo shortcut, int density)
Returns the shortcut icon with badging appropriate for the profile. |
Drawable
|
getShortcutIconDrawable(ShortcutInfo shortcut, int density)
Returns the icon for this shortcut, without any badging for the profile. |
List<ShortcutInfo>
|
getShortcuts(LauncherApps.ShortcutQuery query, UserHandle user)
Returns |
boolean
|
hasShortcutHostPermission()
Returns whether the caller can access the shortcut information. |
boolean
|
isActivityEnabled(ComponentName component, UserHandle user)
Checks if the activity exists and it enabled for a profile. |
boolean
|
isPackageEnabled(String packageName, UserHandle user)
Checks if the package is installed and enabled for a profile. |
void
|
pinShortcuts(String packageName, List<String> shortcutIds, UserHandle user)
Pin shortcuts on a package. |
void
|
registerCallback(LauncherApps.Callback callback, Handler handler)
Registers a callback for changes to packages in current and managed profiles. |
void
|
registerCallback(LauncherApps.Callback callback)
Registers a callback for changes to packages in current and managed profiles. |
LauncherActivityInfo
|
resolveActivity(Intent intent, UserHandle user)
Returns the activity info for a given intent and user handle, if it resolves. |
void
|
startAppDetailsActivity(ComponentName component, UserHandle user, Rect sourceBounds, Bundle opts)
Starts the settings activity to show the application details for a package in the specified profile. |
void
|
startMainActivity(ComponentName component, UserHandle user, Rect sourceBounds, Bundle opts)
Starts a Main activity in the specified profile. |
void
|
startShortcut(String packageName, String shortcutId, Rect sourceBounds, Bundle startActivityOptions, UserHandle user)
Starts a shortcut. |
void
|
startShortcut(ShortcutInfo shortcut, Rect sourceBounds, Bundle startActivityOptions)
Launches a shortcut. |
void
|
unregisterCallback(LauncherApps.Callback callback)
Unregisters a callback that was previously registered. |
Inherited methods | |
|---|---|
java.lang.Object
| |
Public methods
getActivityList
List<LauncherActivityInfo> getActivityList (String packageName, UserHandle user)
Retrieves a list of launchable activities that match ACTION_MAIN and
CATEGORY_LAUNCHER, for a specified user.
| Parameters | |
|---|---|
packageName |
String:
The specific package to query. If null, it checks all installed packages
in the profile. |
user |
UserHandle:
The UserHandle of the profile. |
| Returns | |
|---|---|
List<LauncherActivityInfo> |
List of launchable activities. Can be an empty list but will not be null. |
getShortcutBadgedIconDrawable
Drawable getShortcutBadgedIconDrawable (ShortcutInfo shortcut, int density)
Returns the shortcut icon with badging appropriate for the profile.
The calling launcher application must be allowed to access the shortcut information,
as defined in hasShortcutHostPermission().
| Parameters | |
|---|---|
shortcut |
ShortcutInfo
|
density |
int:
Optional density for the icon, or 0 to use the default density. Use |
| Returns | |
|---|---|
Drawable |
A badged icon for the shortcut. |
| Throws | |
|---|---|
IllegalStateException |
when the user is locked, or when the user user
is locked or not running. |
getShortcutIconDrawable
Drawable getShortcutIconDrawable (ShortcutInfo shortcut, int density)
Returns the icon for this shortcut, without any badging for the profile.
The calling launcher application must be allowed to access the shortcut information,
as defined in hasShortcutHostPermission().
| Parameters | |
|---|---|
shortcut |
ShortcutInfo
|
density |
int:
The preferred density of the icon, zero for default density. Use
density DPI values from DisplayMetrics. |
| Returns | |
|---|---|
Drawable |
The drawable associated with the shortcut. |
| Throws | |
|---|---|
IllegalStateException |
when the user is locked, or when the user user
is locked or not running. |
getShortcuts
List<ShortcutInfo> getShortcuts (LauncherApps.ShortcutQuery query, UserHandle user)
Returns ShortcutInfos that match query.
Callers must be allowed to access the shortcut information, as defined in hasShortcutHostPermission().
| Parameters | |
|---|---|
query |
LauncherApps.ShortcutQuery:
result includes shortcuts matching this query. |
user |
UserHandle:
The UserHandle of the profile. |
| Returns | |
|---|---|
List<ShortcutInfo> |
the IDs of ShortcutInfos that match the query. |
| Throws | |
|---|---|
IllegalStateException |
when the user is locked, or when the user user
is locked or not running. |
See also:
hasShortcutHostPermission
boolean hasShortcutHostPermission ()
Returns whether the caller can access the shortcut information.
Only the default launcher can access the shortcut information.
Note when this method returns false, it may be a temporary situation because
the user is trying a new launcher application. The user may decide to change the default
launcher back to the calling application again, so even if a launcher application loses
this permission, it does not have to purge pinned shortcut information.
If the calling launcher application contains pinned shortcuts, they will still work,
even though the caller no longer has the shortcut host permission.
| Returns | |
|---|---|
boolean |
|
| Throws | |
|---|---|
IllegalStateException |
when the user is locked. |
See also:
isActivityEnabled
boolean isActivityEnabled (ComponentName component, UserHandle user)
Checks if the activity exists and it enabled for a profile.
| Parameters | |
|---|---|
component |
ComponentName:
The activity to check. |
user |
UserHandle:
The UserHandle of the profile. |
| Returns | |
|---|---|
boolean |
true if the activity exists and is enabled. |
isPackageEnabled
boolean isPackageEnabled (String packageName, UserHandle user)
Checks if the package is installed and enabled for a profile.
| Parameters | |
|---|---|
packageName |
String:
The package to check. |
user |
UserHandle:
The UserHandle of the profile. |
| Returns | |
|---|---|
boolean |
true if the package exists and is enabled. |
pinShortcuts
void pinShortcuts (String packageName, List<String> shortcutIds, UserHandle user)
Pin shortcuts on a package.
This API is NOT cumulative; this will replace all pinned shortcuts for the package. However, different launchers may have different set of pinned shortcuts.
The calling launcher application must be allowed to access the shortcut information,
as defined in hasShortcutHostPermission().
| Parameters | |
|---|---|
packageName |
String:
The target package name. |
shortcutIds |
List:
The IDs of the shortcut to be pinned. |
user |
UserHandle:
The UserHandle of the profile. |
| Throws | |
|---|---|
IllegalStateException |
when the user is locked, or when the user user
is locked or not running. |
See also:
registerCallback
void registerCallback (LauncherApps.Callback callback, Handler handler)
Registers a callback for changes to packages in current and managed profiles.
| Parameters | |
|---|---|
callback |
LauncherApps.Callback:
The callback to register. |
handler |
Handler:
that should be used to post callbacks on, may be null.
|
registerCallback
void registerCallback (LauncherApps.Callback callback)
Registers a callback for changes to packages in current and managed profiles.
| Parameters | |
|---|---|
callback |
LauncherApps.Callback:
The callback to register.
|
resolveActivity
LauncherActivityInfo resolveActivity (Intent intent, UserHandle user)
Returns the activity info for a given intent and user handle, if it resolves. Otherwise it returns null.
| Parameters | |
|---|---|
intent |
Intent:
The intent to find a match for. |
user |
UserHandle:
The profile to look in for a match. |
| Returns | |
|---|---|
LauncherActivityInfo |
An activity info object if there is a match. |
startAppDetailsActivity
void startAppDetailsActivity (ComponentName component, UserHandle user, Rect sourceBounds, Bundle opts)
Starts the settings activity to show the application details for a package in the specified profile.
| Parameters | |
|---|---|
component |
ComponentName:
The ComponentName of the package to launch settings for. |
user |
UserHandle:
The UserHandle of the profile |
sourceBounds |
Rect:
The Rect containing the source bounds of the clicked icon |
opts |
Bundle:
Options to pass to startActivity
|
startMainActivity
void startMainActivity (ComponentName component, UserHandle user, Rect sourceBounds, Bundle opts)
Starts a Main activity in the specified profile.
| Parameters | |
|---|---|
component |
ComponentName:
The ComponentName of the activity to launch |
user |
UserHandle:
The UserHandle of the profile |
sourceBounds |
Rect:
The Rect containing the source bounds of the clicked icon |
opts |
Bundle:
Options to pass to startActivity
|
startShortcut
void startShortcut (String packageName, String shortcutId, Rect sourceBounds, Bundle startActivityOptions, UserHandle user)
Starts a shortcut.
The calling launcher application must be allowed to access the shortcut information,
as defined in hasShortcutHostPermission().
| Parameters | |
|---|---|
packageName |
String:
The target shortcut package name. |
shortcutId |
String:
The target shortcut ID. |
sourceBounds |
Rect:
The Rect containing the source bounds of the clicked icon. |
startActivityOptions |
Bundle:
Options to pass to startActivity. |
user |
UserHandle:
The UserHandle of the profile. |
| Throws | |
|---|---|
IllegalStateException |
when the user is locked, or when the user user
is locked or not running. |
ActivityNotFoundException |
failed to start shortcut. (e.g. the shortcut no longer exists, is disabled, the intent receiver activity doesn't exist, etc) |
startShortcut
void startShortcut (ShortcutInfo shortcut, Rect sourceBounds, Bundle startActivityOptions)
Launches a shortcut.
The calling launcher application must be allowed to access the shortcut information,
as defined in hasShortcutHostPermission().
| Parameters | |
|---|---|
shortcut |
ShortcutInfo:
The target shortcut. |
sourceBounds |
Rect:
The Rect containing the source bounds of the clicked icon. |
startActivityOptions |
Bundle:
Options to pass to startActivity. |
| Throws | |
|---|---|
IllegalStateException |
when the user is locked, or when the user user
is locked or not running. |
ActivityNotFoundException |
failed to start shortcut. (e.g. the shortcut no longer exists, is disabled, the intent receiver activity doesn't exist, etc) |
unregisterCallback
void unregisterCallback (LauncherApps.Callback callback)
Unregisters a callback that was previously registered.
| Parameters | |
|---|---|
callback |
LauncherApps.Callback:
The callback to unregister. |
See also:
Classes
- ActivityInfo
- ActivityInfo.WindowLayout
- ApplicationInfo
- ApplicationInfo.DisplayNameComparator
- ComponentInfo
- ConfigurationInfo
- FeatureGroupInfo
- FeatureInfo
- InstrumentationInfo
- LabeledIntent
- LauncherActivityInfo
- LauncherApps
- LauncherApps.Callback
- LauncherApps.ShortcutQuery
- PackageInfo
- PackageInstaller
- PackageInstaller.Session
- PackageInstaller.SessionCallback
- PackageInstaller.SessionInfo
- PackageInstaller.SessionParams
- PackageItemInfo
- PackageItemInfo.DisplayNameComparator
- PackageManager
- PackageStats
- PathPermission
- PermissionGroupInfo
- PermissionInfo
- ProviderInfo
- ResolveInfo
- ResolveInfo.DisplayNameComparator
- ServiceInfo
- ShortcutInfo
- ShortcutInfo.Builder
- ShortcutManager
- Signature
Exceptions

