public class LauncherApps extends Object
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
.
You can retrieve the list of profiles associated with this user with
UserManager.getUserProfiles()
.
Modifier and Type | Class and Description |
---|---|
static class |
LauncherApps.Callback
Callbacks for package changes to this and related managed profiles.
|
static class |
LauncherApps.ShortcutQuery
Represents a query passed to
getShortcuts(ShortcutQuery, UserHandle) . |
Constructor and Description |
---|
LauncherApps(Context context) |
LauncherApps(Context context,
ILauncherApps service) |
Modifier and Type | Method and Description |
---|---|
List<LauncherActivityInfo> |
getActivityList(String packageName,
UserHandle user)
Retrieves a list of launchable activities that match
Intent.ACTION_MAIN and
Intent.CATEGORY_LAUNCHER , for a specified user. |
ApplicationInfo |
getApplicationInfo(String packageName,
int flags,
UserHandle user)
Retrieve all of the information we know about a particular package / application.
|
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.
|
ParcelFileDescriptor |
getShortcutIconFd(ShortcutInfo shortcut) |
ParcelFileDescriptor |
getShortcutIconFd(String packageName,
String shortcutId,
UserHandle user) |
int |
getShortcutIconResId(ShortcutInfo shortcut)
Deprecated.
|
int |
getShortcutIconResId(String packageName,
String shortcutId,
UserHandle user)
Deprecated.
|
List<ShortcutInfo> |
getShortcutInfo(String packageName,
List<String> ids,
UserHandle user)
Deprecated.
|
List<ShortcutInfo> |
getShortcuts(LauncherApps.ShortcutQuery query,
UserHandle user)
Returns
ShortcutInfo s that match query . |
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 current and managed profiles.
|
void |
registerCallback(LauncherApps.Callback callback,
Handler handler)
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(ShortcutInfo shortcut,
Rect sourceBounds,
Bundle startActivityOptions)
Launches a shortcut.
|
void |
startShortcut(String packageName,
String shortcutId,
Rect sourceBounds,
Bundle startActivityOptions,
UserHandle user)
Starts a shortcut.
|
void |
unregisterCallback(LauncherApps.Callback callback)
Unregisters a callback that was previously registered.
|
public LauncherApps(Context context, ILauncherApps service)
public LauncherApps(Context context)
public List<LauncherActivityInfo> getActivityList(String packageName, UserHandle user)
Intent.ACTION_MAIN
and
Intent.CATEGORY_LAUNCHER
, for a specified user.packageName
- The specific package to query. If null, it checks all installed packages
in the profile.user
- The UserHandle of the profile.public LauncherActivityInfo resolveActivity(Intent intent, UserHandle user)
intent
- The intent to find a match for.user
- The profile to look in for a match.public void startMainActivity(ComponentName component, UserHandle user, Rect sourceBounds, Bundle opts)
component
- The ComponentName of the activity to launchuser
- The UserHandle of the profilesourceBounds
- The Rect containing the source bounds of the clicked iconopts
- Options to pass to startActivitypublic void startAppDetailsActivity(ComponentName component, UserHandle user, Rect sourceBounds, Bundle opts)
component
- The ComponentName of the package to launch settings for.user
- The UserHandle of the profilesourceBounds
- The Rect containing the source bounds of the clicked iconopts
- Options to pass to startActivitypublic boolean isPackageEnabled(String packageName, UserHandle user)
packageName
- The package to check.user
- The UserHandle of the profile.public ApplicationInfo getApplicationInfo(String packageName, int flags, UserHandle user)
packageName
- The package of the applicationflags
- Additional option flags PackageManager.getApplicationInfo(java.lang.String, int)
user
- The UserHandle of the profile.ApplicationInfo
containing information about the package or
null of the package isn't found.public boolean isActivityEnabled(ComponentName component, UserHandle user)
component
- The activity to check.user
- The UserHandle of the profile.public boolean hasShortcutHostPermission()
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.
IllegalStateException
- when the user is locked.ShortcutManager
public List<ShortcutInfo> getShortcuts(LauncherApps.ShortcutQuery query, UserHandle user)
ShortcutInfo
s that match query
.
Callers must be allowed to access the shortcut information, as defined in hasShortcutHostPermission()
.
query
- result includes shortcuts matching this query.user
- The UserHandle of the profile.ShortcutInfo
s that match the query.IllegalStateException
- when the user is locked, or when the user
user
is locked or not running.ShortcutManager
@Deprecated public List<ShortcutInfo> getShortcutInfo(String packageName, List<String> ids, UserHandle user)
public void pinShortcuts(String packageName, List<String> shortcutIds, UserHandle user)
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()
.
packageName
- The target package name.shortcutIds
- The IDs of the shortcut to be pinned.user
- The UserHandle of the profile.IllegalStateException
- when the user is locked, or when the user
user
is locked or not running.ShortcutManager
@Deprecated public int getShortcutIconResId(ShortcutInfo shortcut)
@Deprecated public int getShortcutIconResId(String packageName, String shortcutId, UserHandle user)
public ParcelFileDescriptor getShortcutIconFd(ShortcutInfo shortcut)
public ParcelFileDescriptor getShortcutIconFd(String packageName, String shortcutId, UserHandle user)
public Drawable getShortcutIconDrawable(ShortcutInfo shortcut, int density)
The calling launcher application must be allowed to access the shortcut information,
as defined in hasShortcutHostPermission()
.
density
- The preferred density of the icon, zero for default density. Use
density DPI values from DisplayMetrics
.IllegalStateException
- when the user is locked, or when the user
user
is locked or not running.ShortcutManager
,
getShortcutBadgedIconDrawable(ShortcutInfo, int)
,
DisplayMetrics
public Drawable getShortcutBadgedIconDrawable(ShortcutInfo shortcut, int density)
The calling launcher application must be allowed to access the shortcut information,
as defined in hasShortcutHostPermission()
.
density
- Optional density for the icon, or 0 to use the default density. UseIllegalStateException
- when the user is locked, or when the user
user
is locked or not running.ShortcutManager
,
getShortcutIconDrawable(ShortcutInfo, int)
,
DisplayMetrics
public void startShortcut(String packageName, String shortcutId, Rect sourceBounds, Bundle startActivityOptions, UserHandle user)
The calling launcher application must be allowed to access the shortcut information,
as defined in hasShortcutHostPermission()
.
packageName
- The target shortcut package name.shortcutId
- The target shortcut ID.sourceBounds
- The Rect containing the source bounds of the clicked icon.startActivityOptions
- Options to pass to startActivity.user
- The UserHandle of the profile.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)public void startShortcut(ShortcutInfo shortcut, Rect sourceBounds, Bundle startActivityOptions)
The calling launcher application must be allowed to access the shortcut information,
as defined in hasShortcutHostPermission()
.
shortcut
- The target shortcut.sourceBounds
- The Rect containing the source bounds of the clicked icon.startActivityOptions
- Options to pass to startActivity.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)public void registerCallback(LauncherApps.Callback callback)
callback
- The callback to register.public void registerCallback(LauncherApps.Callback callback, Handler handler)
callback
- The callback to register.handler
- that should be used to post callbacks on, may be null.public void unregisterCallback(LauncherApps.Callback callback)
callback
- The callback to unregister.registerCallback(Callback)