鸿蒙OS开发文档 鸿蒙OS LauncherService

2024-02-25 开发教程 鸿蒙OS开发文档 匿名 2

LauncherService

java.lang.Object
|---ohos.bundle.LauncherService

public class LauncherService
extends Object

查询车辆的启动器ability和应用信息。

你可以使用这个类来注册一个回调方法来观察bundle状态的变化。

嵌套类摘要

修饰符和类型描述
static classLauncherService.BundleStatusCallback提供在安装、卸载或更新捆绑包后调用的回调方法。

构造函数摘要

构造函数描述
LauncherService(Context context)用于创建 LauncherService 实例的构造函数。

方法总结

修饰符和类型方法描述
OptionalLauncherAbilityInfogetAbilityInfo(Intent intent, int userId)根据给定 Intent 中指定的 ElementName 和 userId 获取启动器ability。
OptionalListLauncherAbilityInfogetAbilityList(String bundleName, int userId)根据包含 Intent.ACTION_HOME 和 Intent.ENTITY_HOME 的 Intent 获取启动器ability。
OptionalApplicationInfogetApplicationInfo(String bundleName, int flags, int userId)根据给定的包名称、标志和用户 ID 获取有关应用程序的信息。
OptionalListLauncherShortcutInfogetShortcutInfos(String bundleName)获取有关应用程序快捷方式的信息。
booleanisAbilityEnabled(AbilityInfo abilityInfo)检查ability是否存在并启用。
booleanisBundleEnabled(String bundleName)检查捆绑包是否存在并已启用。
voidregisterCallback(LauncherService.BundleStatusCallback callback)注册一个回调方法,用于监控包安装、卸载和更新事件。
voidstartShortcut(String shortcutId, String bundleName)根据给定的快捷方式 ID 和包名称启动快捷方式。
voidunRegisterCallback()取消注册用于监视捆绑安装、卸载和更新事件的回调方法。
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

构造函数详细信息

LauncherService

public LauncherService(Context context)

用于创建 LauncherService 实例的构造函数。

您可以使用此实例注册回调方法以监视捆绑包安装、卸载和更新事件。

参数:

参数名称参数描述
context表示当前ability的上下文对象。

方法详情

registerCallback

public void registerCallback(LauncherService.BundleStatusCallback callback)

注册一个回调方法,用于监控包安装、卸载和更新事件。

要使用此方法,您需要向系统请求 ohos.permission.LISTEN_BUNDLE_CHANGE 权限。 ohos.permission.LISTEN_BUNDLE_CHANGE 权限属于签名|特权级别。

参数:

参数名称参数描述
callback表示要调用的回调方法。

unRegisterCallback

public void unRegisterCallback()

取消注册用于监视捆绑安装、卸载和更新事件的回调方法。

getAbilityList

public OptionalListLauncherAbilityInfo getAbilityList(String bundleName, int userId)

根据包含 Intent.ACTION_HOME 和 Intent.ENTITY_HOME 的 Intent 获取启动器ability。

如果指定了包名称,则返回有关与指定包匹配的启动器ability的信息。 否则,将返回有关与 Intent 匹配的所有启动器ability的信息。

参数:

参数名称参数描述
bundleName指示捆绑包名称。
userId表示用户标识。

返回:

返回 LauncherAbilityInfo 对象的列表。

getAbilityInfo

public OptionalLauncherAbilityInfo getAbilityInfo(Intent intent, int userId)

根据给定 Intent 中指定的 ElementName 和 userId 获取启动器ability。

参数:

参数名称参数描述
intent指示包含要查询的应用程序包名称的 Intent。
userId表示用户标识。

返回:

返回一个 LauncherAbilityInfo 对象。

getApplicationInfo

public OptionalApplicationInfo getApplicationInfo(String bundleName, int flags, int userId)

根据给定的包名称、标志和用户 ID 获取有关应用程序的信息。

参数:

参数名称参数描述
bundleName表示要查询的bundle名称。
flags指示用于指定将返回的 ApplicationInfo 对象中包含的信息的标志。
userId表示用户标识。

返回:

返回一个 ApplicationInfo 对象。

isBundleEnabled

public boolean isBundleEnabled(String bundleName)

检查捆绑包是否存在并已启用。

参数:

参数名称参数描述
bundleName指示捆绑包名称。

返回:

如果启用了捆绑包,则返回 true; 否则返回 false。

isAbilityEnabled

public boolean isAbilityEnabled(AbilityInfo abilityInfo)

检查ability是否存在并启用。

参数:

参数名称参数描述
abilityInfo表示有关检查ability的信息。

返回:

如果该ability存在且已启用,则返回 true; 否则返回 false。

getShortcutInfos

public OptionalListLauncherShortcutInfo getShortcutInfos(String bundleName)

获取有关应用程序快捷方式的信息。

要使用此方法,您需要向系统请求 ohos.permission.MANAGE_SHORTCUTS 权限。 ohos.permission.MANAGE_SHORTCUTS 权限属于签名级别。

参数:

参数名称参数描述
bundleName指示应用程序的捆绑包名称。

返回:

返回包含有关应用程序的快捷方式信息的 LauncherShortcutInfo 对象列表。

startShortcut

public void startShortcut(String shortcutId, String bundleName)

根据给定的快捷方式 ID 和包名称启动快捷方式。

要使用此方法,您需要向系统请求 ohos.permission.MANAGE_SHORTCUTS 权限。 ohos.permission.MANAGE_SHORTCUTS 权限属于签名级别。

参数:

参数名称参数描述
shortcutId指示要启动的快捷方式的 ID。
bundleNameBundleName 表示快捷方式所属的应用程序的包名。