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 that are visible to the current user, which can be retrieved with
 getProfiles(). 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:
 Intent.ACTION_MANAGED_PROFILE_ADDED and Intent.ACTION_MANAGED_PROFILE_REMOVED.
 
 Note as of Android O, apps on a managed profile are no longer allowed to access apps on the
 main profile.  Apps can only access profiles returned by getProfiles().
Summary
| Nested classes | |
|---|---|
| 
        
        
        
        
        class | LauncherApps.ArchiveCompatibilityParamsUsed to enable Archiving compatibility options with  | 
| 
        
        
        
        
        class | LauncherApps.CallbackCallbacks for package changes to this and related managed profiles. | 
| 
        
        
        
        
        class | LauncherApps.PinItemRequestRepresents a "pin shortcut" or a "pin appwidget" request made by an app, which is sent with
 an  | 
| 
        
        
        
        
        class | LauncherApps.ShortcutQueryRepresents a query passed to  | 
| Constants | |
|---|---|
| String | ACTION_CONFIRM_PIN_APPWIDGETActivity Action: For the default launcher to show the confirmation dialog to create a pinned app widget. | 
| String | ACTION_CONFIRM_PIN_SHORTCUTActivity Action: For the default launcher to show the confirmation dialog to create a pinned shortcut. | 
| String | EXTRA_PIN_ITEM_REQUESTAn extra for  | 
| Public methods | |
|---|---|
| 
        
        
        
        
        
        List<LauncherActivityInfo> | 
      getActivityList(String packageName, UserHandle user)
      Retrieves a list of activities that specify  | 
| 
        
        
        
        
        
        List<PackageInstaller.SessionInfo> | 
      getAllPackageInstallerSessions()
      Return list of all known install sessions in this user and managed profiles, regardless of the installer. | 
| 
        
        
        
        
        
        IntentSender | 
      getAppMarketActivityIntent(String packageName, UserHandle user)
      Returns an intent sender which can be used to start the App Market activity (Installer Activity). | 
| 
        
        
        
        
        
        ApplicationInfo | 
      getApplicationInfo(String packageName, int flags, UserHandle user)
      Returns  | 
| 
        
        
        
        final
        
        LauncherUserInfo | 
      getLauncherUserInfo(UserHandle userHandle)
      Returns information related to a user which is useful for displaying UI elements to distinguish it from other users (eg, badges). | 
| 
        
        
        
        
        
        LauncherApps.PinItemRequest | 
      getPinItemRequest(Intent intent)
      A helper method to extract a  | 
| 
        
        
        
        
        
        List<String> | 
      getPreInstalledSystemPackages(UserHandle userHandle)
      Returns the list of the system packages that are installed at user creation. | 
| 
        
        
        
        
        
        IntentSender | 
      getPrivateSpaceSettingsIntent()
      Returns  | 
| 
        
        
        
        
        
        List<UserHandle> | 
      getProfiles()
      Return a list of profiles that the caller can access via the  | 
| 
        
        
        
        
        
        Drawable | 
      getShortcutBadgedIconDrawable(ShortcutInfo shortcut, int density)
      Returns the shortcut icon with badging appropriate for the profile. | 
| 
        
        
        
        
        
        IntentSender | 
      getShortcutConfigActivityIntent(LauncherActivityInfo info)
      Returns an intent sender which can be used to start the configure activity for creating custom shortcuts. | 
| 
        
        
        
        
        
        List<LauncherActivityInfo> | 
      getShortcutConfigActivityList(String packageName, UserHandle user)
      Retrieves a list of config activities for creating  | 
| 
        
        
        
        
        
        Drawable | 
      getShortcutIconDrawable(ShortcutInfo shortcut, int density)
      Returns the icon for this shortcut, without any badging for the profile. | 
| 
        
        
        
        
        
        PendingIntent | 
      getShortcutIntent(String packageName, String shortcutId, Bundle opts, UserHandle user)
      Returns PendingIntent associated with specified shortcut. | 
| 
        
        
        
        
        
        List<ShortcutInfo> | 
      getShortcuts(LauncherApps.ShortcutQuery query, UserHandle user)
      Returns  | 
| 
        
        
        
        
        
        Bundle | 
      getSuspendedPackageLauncherExtras(String packageName, UserHandle user)
      Gets the launcher extras supplied to the system when the given package was suspended via
  | 
| 
        
        
        
        
        
        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)
      Registers a callback for changes to packages in this user and managed profiles. | 
| 
        
        
        
        
        
        void | 
      registerCallback(LauncherApps.Callback callback, Handler handler)
      Registers a callback for changes to packages in this user and managed profiles. | 
| 
        
        
        
        
        
        void | 
      registerPackageInstallerSessionCallback(Executor executor, PackageInstaller.SessionCallback callback)
      Register a callback to watch for session lifecycle events in this user and managed profiles. | 
| 
        
        
        
        
        
        LauncherActivityInfo | 
      resolveActivity(Intent intent, UserHandle user)
      Returns the activity info for a given intent and user handle, if it resolves. | 
| 
        
        
        
        
        
        void | 
      setArchiveCompatibility(LauncherApps.ArchiveCompatibilityParams params)
      Disable different archive compatibility options of the launcher for the caller of this method. | 
| 
        
        
        
        
        
        boolean | 
      shouldHideFromSuggestions(String packageName, UserHandle user)
      Returns whether a package should be hidden from suggestions to the user. | 
| 
        
        
        
        
        
        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 | 
      startPackageInstallerSessionDetailsActivity(PackageInstaller.SessionInfo sessionInfo, Rect sourceBounds, Bundle opts)
      Starts an activity to show the details of the specified session. | 
| 
        
        
        
        
        
        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. | 
| 
        
        
        
        
        
        void | 
      unregisterPackageInstallerSessionCallback(PackageInstaller.SessionCallback callback)
      Unregisters a callback that was previously registered. | 
| Inherited methods | |
|---|---|
Constants
ACTION_CONFIRM_PIN_APPWIDGET
public static final String ACTION_CONFIRM_PIN_APPWIDGET
Activity Action: For the default launcher to show the confirmation dialog to create a pinned app widget.
See the AppWidgetManager.requestPinAppWidget(ComponentName, Bundle, PendingIntent) javadoc for
 details.
 
 Use getPinItemRequest(android.content.Intent) to get a PinItemRequest object,
 and call PinItemRequest.accept(Bundle)
 if the user accepts.  If the user doesn't accept, no further action is required.
See also:
Constant Value: "android.content.pm.action.CONFIRM_PIN_APPWIDGET"
ACTION_CONFIRM_PIN_SHORTCUT
public static final String ACTION_CONFIRM_PIN_SHORTCUT
Activity Action: For the default launcher to show the confirmation dialog to create a pinned shortcut.
See the ShortcutManager javadoc for details.
 
 Use getPinItemRequest(android.content.Intent) to get a PinItemRequest object,
 and call PinItemRequest.accept(Bundle)
 if the user accepts.  If the user doesn't accept, no further action is required.
See also:
Constant Value: "android.content.pm.action.CONFIRM_PIN_SHORTCUT"
EXTRA_PIN_ITEM_REQUEST
public static final String EXTRA_PIN_ITEM_REQUEST
An extra for ACTION_CONFIRM_PIN_SHORTCUT & ACTION_CONFIRM_PIN_APPWIDGET
 containing a PinItemRequest of appropriate type asked to pin.
 
A helper function getPinItemRequest(android.content.Intent) can be used
 instead of using this constant directly.
Constant Value: "android.content.pm.extra.PIN_ITEM_REQUEST"
Public methods
getActivityList
public List<LauncherActivityInfo> getActivityList (String packageName, UserHandle user)
Retrieves a list of activities that specify Intent.ACTION_MAIN and
 Intent.CATEGORY_LAUNCHER, across all apps, for a specified user. If an app doesn't
 have any activities that specify ACTION_MAIN or CATEGORY_LAUNCHER,
 the system adds a synthesized activity to the list. This synthesized activity represents the
 app's details page within system settings.
 
Note: It's possible for system apps, such as app stores, to prevent the system from adding synthesized activities to the returned list.
As of Android Q, at least one of the app's activities or synthesized activities appears in the returned list unless the app satisfies at least one of the following conditions:
- The app is a system app.
- The app doesn't request any permissions.
- The app doesn't have a launcher activity that is enabled by default. A launcher
 activity has an intent containing the ACTION_MAINaction and theCATEGORY_LAUNCHERcategory.
Additionally, the system hides synthesized activities for some or all apps in the following enterprise-related cases:
- If the device is a fully managed device, no synthesized activities for any app appear in the returned list.
- If the current user has a work profile, no synthesized activities for the user's work apps appear in the returned list.
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| 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. | 
getAllPackageInstallerSessions
public List<PackageInstaller.SessionInfo> getAllPackageInstallerSessions ()
Return list of all known install sessions in this user and managed profiles, regardless of the installer. Callers need to either declare <queries> element with the specific package name in the app's manifest, have the android.permission.QUERY_ALL_PACKAGES, or be the session owner to retrieve these details.
To receive callbacks for hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| Returns | |
|---|---|
| List<PackageInstaller.SessionInfo> | This value cannot be null. | 
See also:
getAppMarketActivityIntent
public IntentSender getAppMarketActivityIntent (String packageName, UserHandle user)
Returns an intent sender which can be used to start the App Market activity (Installer Activity). This method is primarily used to get an intent sender which starts App Market activity for another profile, if the caller is not otherwise allowed to start activity in that profile.
When packageName is set, intent sender to start the App Market Activity which installed the package in calling user will be returned, but for the profile passed.
When packageName is not set, intent sender to launch the default App Market Activity for the profile will be returned. In case there are multiple App Market Activities available for the profile, IntentPicker will be started, allowing user to choose the preferred activity.
The method will fall back to the behaviour of not having the packageName set, in case:
- No activity for the packageName is found in calling user-space.
- The App Market Activity which installed the package in calling user-space is not present.
- The App Market Activity which installed the package in calling user-space is not present in the profile passed.
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| Parameters | |
|---|---|
| packageName | String: the package for which intent sender to launch App Market Activity is
                    required.
 This value may benull. | 
| user | UserHandle: the profile for which intent sender to launch App Market Activity is required.
 This value cannot benull. | 
| Returns | |
|---|---|
| IntentSender | IntentSenderobject which launches the App Market Activity, null in case
         there is no such activity. | 
getApplicationInfo
public ApplicationInfo getApplicationInfo (String packageName, int flags, UserHandle user)
Returns ApplicationInfo about an application installed for a specific user profile.
 
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| Parameters | |
|---|---|
| packageName | String: The package name of the application
 This value cannot benull. | 
| flags | int: Additional option flagsPackageManager.getApplicationInfoValue is either0or a combination ofPackageManager.GET_META_DATA,PackageManager.GET_SHARED_LIBRARY_FILES,PackageManager.MATCH_UNINSTALLED_PACKAGES,PackageManager.MATCH_SYSTEM_ONLY, android.content.pm.PackageManager.MATCH_DEBUG_TRIAGED_MISSING,PackageManager.MATCH_DISABLED_COMPONENTS,PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS, android.content.pm.PackageManager.MATCH_INSTANT, android.content.pm.PackageManager.MATCH_STATIC_SHARED_AND_SDK_LIBRARIES,PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,PackageManager.GET_UNINSTALLED_PACKAGES, android.content.pm.PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS,PackageManager.MATCH_APEX, andPackageManager.MATCH_ARCHIVED_PACKAGES | 
| user | UserHandle: The UserHandle of the profile.
 This value cannot benull. | 
| Returns | |
|---|---|
| ApplicationInfo | ApplicationInfocontaining information about the package. Returnsnullif the package isn't installed for the given profile, or the profile
         isn't enabled. | 
| Throws | |
|---|---|
| PackageManager.NameNotFoundException | |
getLauncherUserInfo
public final LauncherUserInfo getLauncherUserInfo (UserHandle userHandle)
Returns information related to a user which is useful for displaying UI elements to distinguish it from other users (eg, badges).
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| Parameters | |
|---|---|
| userHandle | UserHandle: user handle of the user for which LauncherUserInfo is requested.
 This value cannot benull. | 
| Returns | |
|---|---|
| LauncherUserInfo | the LauncherUserInfoobject related to the user specified, null in case
 the user is inaccessible. | 
getPinItemRequest
public LauncherApps.PinItemRequest getPinItemRequest (Intent intent)
A helper method to extract a PinItemRequest set to
 the EXTRA_PIN_ITEM_REQUEST extra.
| Parameters | |
|---|---|
| intent | Intent | 
| Returns | |
|---|---|
| LauncherApps.PinItemRequest | |
getPreInstalledSystemPackages
public List<String> getPreInstalledSystemPackages (UserHandle userHandle)
Returns the list of the system packages that are installed at user creation.
An empty list denotes that all system packages should be treated as pre-installed for that user at creation.
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| Parameters | |
|---|---|
| userHandle | UserHandle: the user for which installed system packages are required.
 This value cannot benull. | 
| Returns | |
|---|---|
| List<String> | ListofString, representing the package name of the installed
        package. Can be empty but not null. | 
getPrivateSpaceSettingsIntent
public IntentSender getPrivateSpaceSettingsIntent ()
Returns IntentSender which can be used to start the Private Space Settings Activity.
 
 Caller should have RoleManager.ROLE_HOME and either of the
 permissions required.
| Returns | |
|---|---|
| IntentSender | IntentSenderobject which launches the Private Space Settings Activity, if
 successful, null otherwise. | 
getProfiles
public List<UserHandle> getProfiles ()
Return a list of profiles that the caller can access via the LauncherApps APIs.
 
If the caller is running on a managed profile, it'll return only the current profile.
 Otherwise it'll return the same list as UserManager.getUserProfiles() would.
 
To get hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| Returns | |
|---|---|
| List<UserHandle> | |
getShortcutBadgedIconDrawable
public 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 useruser
 is locked or not running. | 
getShortcutConfigActivityIntent
public IntentSender getShortcutConfigActivityIntent (LauncherActivityInfo info)
Returns an intent sender which can be used to start the configure activity for creating custom shortcuts. Use this method if the provider is in another profile as you are not allowed to start an activity in another profile.
The caller should receive PinItemRequest in onActivityResult on
 Activity.RESULT_OK.
 
Callers must be allowed to access the shortcut information, as defined in hasShortcutHostPermission().
| Parameters | |
|---|---|
| info | LauncherActivityInfo: a configuration activity returned bygetShortcutConfigActivityList(String, UserHandle)This value cannot benull. | 
| Returns | |
|---|---|
| IntentSender | This value may be null. | 
| Throws | |
|---|---|
| IllegalStateException | when the user is locked or not running. | 
| SecurityException | if hasShortcutHostPermission()is false. | 
getShortcutConfigActivityList
public List<LauncherActivityInfo> getShortcutConfigActivityList (String packageName, UserHandle user)
Retrieves a list of config activities for creating ShortcutInfo.
| 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.
 This value cannot benull. | 
| Returns | |
|---|---|
| List<LauncherActivityInfo> | List of config activities. Can be an empty list but will not be null. Empty list will be returned for user-profiles that have items restricted on home screen. | 
getShortcutIconDrawable
public 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: This value cannot benull. | 
| density | int: The preferred density of the icon, zero for default density. Use
 density DPI values fromDisplayMetrics. | 
| Returns | |
|---|---|
| Drawable | The drawable associated with the shortcut. | 
| Throws | |
|---|---|
| IllegalStateException | when the user is locked, or when the useruser
 is locked or not running. | 
getShortcutIntent
public PendingIntent getShortcutIntent (String packageName, String shortcutId, Bundle opts, UserHandle user)
Returns PendingIntent associated with specified shortcut.
| Parameters | |
|---|---|
| packageName | String: The packageName of the shortcut
 This value cannot benull. | 
| shortcutId | String: The id of the shortcut
 This value cannot benull. | 
| opts | Bundle: This parameter is no longer supported
 This value may benull. | 
| user | UserHandle: The UserHandle of the profile
 This value cannot benull. | 
| Returns | |
|---|---|
| PendingIntent | This value may be null. | 
getShortcuts
public 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.
 This value cannot benull. | 
| user | UserHandle: The UserHandle of the profile.
 This value cannot benull. | 
| Returns | |
|---|---|
| List<ShortcutInfo> | the IDs of ShortcutInfos that match the query.
 This value may benull. | 
| Throws | |
|---|---|
| IllegalStateException | when the user is locked, or when the useruser
 is locked or not running. | 
See also:
getSuspendedPackageLauncherExtras
public Bundle getSuspendedPackageLauncherExtras (String packageName, UserHandle user)
Gets the launcher extras supplied to the system when the given package was suspended via
 PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
 PersistableBundle, String).
 
The contents of this Bundle are supposed to be a contract between the suspending
 app and the launcher.
 
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
 
Note: This just returns whatever extras were provided to the system, which might
 even be null.
| Parameters | |
|---|---|
| packageName | String: The package for which to fetch the launcher extras. | 
| user | UserHandle: TheUserHandleof the profile. | 
| Returns | |
|---|---|
| Bundle | A Bundleof launcher extras. Ornullif the package is not currently
         suspended. | 
hasShortcutHostPermission
public boolean hasShortcutHostPermission ()
Returns whether the caller can access the shortcut information. Access is currently available to:
- The current launcher (or default launcher if there is no set current launcher).
- The currently active voice interaction service.
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
public boolean isActivityEnabled (ComponentName component, UserHandle user)
Checks if the activity exists and it enabled for a profile.
The activity may still not be exported, in which case startMainActivity(ComponentName, UserHandle, Rect, Bundle) will
 throw a SecurityException unless the caller has the same UID as the target app's.
 
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| 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
public boolean isPackageEnabled (String packageName, UserHandle user)
Checks if the package is installed and enabled for a profile.
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| 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
public 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().
 
For user-profiles with items restricted on home screen, caller must have the required permission.
| Parameters | |
|---|---|
| packageName | String: The target package name.
 This value cannot benull. | 
| shortcutIds | List: The IDs of the shortcut to be pinned.
 This value cannot benull. | 
| user | UserHandle: The UserHandle of the profile.
 This value cannot benull. | 
| Throws | |
|---|---|
| IllegalStateException | when the user is locked, or when the useruser
 is locked or not running. | 
See also:
registerCallback
public void registerCallback (LauncherApps.Callback callback)
Registers a callback for changes to packages in this user and managed profiles.
To receive callbacks for hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
 
This callback will also receive changes to the LauncherUserInfo.getUserConfig(),
 allowing clients to monitor updates to the user-specific configuration.
| Parameters | |
|---|---|
| callback | LauncherApps.Callback: The callback to register. | 
registerCallback
public void registerCallback (LauncherApps.Callback callback, Handler handler)
Registers a callback for changes to packages in this user and managed profiles.
To receive callbacks for hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
 
This callback will also receive changes to the LauncherUserInfo.getUserConfig(),
 allowing clients to monitor updates to the user-specific configuration.
| Parameters | |
|---|---|
| callback | LauncherApps.Callback: The callback to register. | 
| handler | Handler: that should be used to post callbacks on, may be null. | 
registerPackageInstallerSessionCallback
public void registerPackageInstallerSessionCallback (Executor executor, PackageInstaller.SessionCallback callback)
Register a callback to watch for session lifecycle events in this user and managed profiles. Callers need to either declare <queries> element with the specific package name in the app's manifest, have the android.permission.QUERY_ALL_PACKAGES, or be the session owner to watch for these events.
Session callbacks are not sent for user-profiles that have items restricted on home screen.
| Parameters | |
|---|---|
| executor | Executor:Executorto handle the callbacks, cannot be null.
 Callback and listener events are dispatched through thisExecutor, providing an easy way to control which thread is
 used. To dispatch events through the main thread of your
 application, you can useContext.getMainExecutor().
 Otherwise, provide anExecutorthat dispatches to an appropriate thread. | 
| callback | PackageInstaller.SessionCallback: The callback to register.
 This value cannot benull. | 
resolveActivity
public LauncherActivityInfo resolveActivity (Intent intent, UserHandle user)
Returns the activity info for a given intent and user handle, if it resolves. Otherwise it returns null.
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| 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. | 
setArchiveCompatibility
public void setArchiveCompatibility (LauncherApps.ArchiveCompatibilityParams params)
Disable different archive compatibility options of the launcher for the caller of this method.
| Parameters | |
|---|---|
| params | LauncherApps.ArchiveCompatibilityParams: This value cannot benull. | 
See also:
shouldHideFromSuggestions
public boolean shouldHideFromSuggestions (String packageName, UserHandle user)
Returns whether a package should be hidden from suggestions to the user. Currently, this
 could be done because the package was marked as distracting to the user via
 PackageManager.setDistractingPackageRestrictions(String[], int).
 
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| Parameters | |
|---|---|
| packageName | String: The package for which to check.
 This value cannot benull. | 
| user | UserHandle: theUserHandleof the profile.
 This value cannot benull. | 
| Returns | |
|---|---|
| boolean | |
startAppDetailsActivity
public 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.
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| 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
public void startMainActivity (ComponentName component, UserHandle user, Rect sourceBounds, Bundle opts)
Starts a Main activity in the specified profile.
If the user in question is a hidden profile UserManager.USER_TYPE_PROFILE_PRIVATE,
 caller should have normal Manifest.permission.ACCESS_HIDDEN_PROFILES
 permission and the RoleManager.ROLE_HOME role.
| 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 | 
startPackageInstallerSessionDetailsActivity
public void startPackageInstallerSessionDetailsActivity (PackageInstaller.SessionInfo sessionInfo, Rect sourceBounds, Bundle opts)
Starts an activity to show the details of the specified session.
| Parameters | |
|---|---|
| sessionInfo | PackageInstaller.SessionInfo: The SessionInfo of the session
 This value cannot benull. | 
| sourceBounds | Rect: The Rect containing the source bounds of the clicked icon
 This value may benull. | 
| opts | Bundle: Options to pass to startActivity
 This value may benull. | 
startShortcut
public 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.
 This value cannot benull. | 
| shortcutId | String: The target shortcut ID.
 This value cannot benull. | 
| sourceBounds | Rect: The Rect containing the source bounds of the clicked icon.
 This value may benull. | 
| startActivityOptions | Bundle: Options to pass to startActivity.
 This value may benull. | 
| user | UserHandle: The UserHandle of the profile.
 This value cannot benull. | 
| Throws | |
|---|---|
| IllegalStateException | when the user is locked, or when the useruser
 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
public 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.
 This value cannot benull. | 
| sourceBounds | Rect: The Rect containing the source bounds of the clicked icon.
 This value may benull. | 
| startActivityOptions | Bundle: Options to pass to startActivity.
 This value may benull. | 
| Throws | |
|---|---|
| IllegalStateException | when the user is locked, or when the useruser
 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
public void unregisterCallback (LauncherApps.Callback callback)
Unregisters a callback that was previously registered.
| Parameters | |
|---|---|
| callback | LauncherApps.Callback: The callback to unregister. | 
See also:
unregisterPackageInstallerSessionCallback
public void unregisterPackageInstallerSessionCallback (PackageInstaller.SessionCallback callback)
Unregisters a callback that was previously registered.
| Parameters | |
|---|---|
| callback | PackageInstaller.SessionCallback: The callback to unregister.
 This value cannot benull. | 
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-03-13 UTC.
