public class LauncherService extends Object
You can use this class to register a callback method for observing bundle status changes.
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
LauncherService.BundleStatusCallback |
Provides callback methods that are called after a bundle is installed, uninstalled, or updated.
|
| 构造器 | 说明 |
|---|---|
LauncherService(Context context) |
A constructor used to create a
LauncherService instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
Optional<LauncherAbilityInfo> |
getAbilityInfo(Intent intent,
int userId) |
|
Optional<List<LauncherAbilityInfo>> |
getAbilityList(String bundleName,
int userId) |
Obtains launcher abilities based on the
Intent that contains
Intent.ACTION_HOME and Intent.ENTITY_HOME. |
Optional<ApplicationInfo> |
getApplicationInfo(String bundleName,
int flags,
int userId) |
Obtains information about an application based on the given bundle name, flag, and user ID.
|
Optional<List<LauncherShortcutInfo>> |
getShortcutInfos(String bundleName) |
Obtains information about the shortcuts of the application.
|
boolean |
isAbilityEnabled(AbilityInfo abilityInfo) |
Checks whether an ability exists and is enabled.
|
boolean |
isBundleEnabled(String bundleName) |
Checks whether a bundle exists and is enabled.
|
void |
registerCallback(LauncherService.BundleStatusCallback callback) |
Registers a callback method for monitoring bundle installation, uninstallation, and update events.
|
void |
startShortcut(String shortcutId,
String bundleName) |
Starts a shortcut based on the given shortcut ID and bundle name.
|
void |
unRegisterCallback() |
Unregisters the callback method for monitoring bundle installation, uninstallation, and update events.
|
public LauncherService(Context context)
LauncherService instance.
You can use this instance to register callback methods for monitoring bundle installation, uninstallation, and update events.
context - Indicates the Context object of the current ability.public void registerCallback(LauncherService.BundleStatusCallback callback)
To use this method, you need to request the ohos.permission.LISTEN_BUNDLE_CHANGE
permission from the system. The ohos.permission.LISTEN_BUNDLE_CHANGE permission is of the
signature|privileged level.
callback - Indicates the callback method to be called.public void unRegisterCallback()
public Optional<List<LauncherAbilityInfo>> getAbilityList(String bundleName, int userId)
Intent that contains
Intent.ACTION_HOME and Intent.ENTITY_HOME.
If a bundle name is specified, information about launcher abilities matching the specified bundle is
returned. Otherwise, information about all launcher abilities that match the
Intent is returned.
bundleName - Indicates the bundle name.userId - Indicates the user ID.LauncherAbilityInfo objects.Intent.ACTION_HOME,
Intent.ENTITY_HOMEpublic Optional<LauncherAbilityInfo> getAbilityInfo(Intent intent, int userId)
intent - Indicates the Intent containing the application bundle name to
be queried.userId - Indicates the user ID.LauncherAbilityInfo object.public Optional<ApplicationInfo> getApplicationInfo(String bundleName, int flags, int userId)
bundleName - Indicates the bundle name to be queried.flags - Indicates the flag used to specify information contained in the ApplicationInfo objects that
will be returned.userId - Indicates the user ID.ApplicationInfo object.IBundleManager.GET_APPLICATION_INFO_WITH_PERMISSION,
IBundleManager.GET_BUNDLE_DEFAULTpublic boolean isBundleEnabled(String bundleName)
bundleName - Indicates the bundle name.true if the bundle is enabled; returns false otherwise.public boolean isAbilityEnabled(AbilityInfo abilityInfo)
abilityInfo - Indicates information about the ability to check.true if the ability exists and is enabled; returns false otherwise.public Optional<List<LauncherShortcutInfo>> getShortcutInfos(String bundleName)
To use this method, you need to request the ohos.permission.MANAGE_SHORTCUTS permission from
the system. The ohos.permission.MANAGE_SHORTCUTS permission is of the signature level.
bundleName - Indicates the bundle name of the application.LauncherShortcutInfo objects containing shortcut information about the
application.public void startShortcut(String shortcutId, String bundleName)
To use this method, you need to request the ohos.permission.MANAGE_SHORTCUTS permission from the
system. The ohos.permission.MANAGE_SHORTCUTS permission is of the signature level.
shortcutId - Indicates the ID of the shortcut to start.bundleName - BundleName Indicates the bundle name of the application to which the shortcut belongs.