鴻蒙OS LauncherService

2022-04-25 16:45 更新

LauncherService

java.lang.Object

|---ohos.bundle.LauncherService

public class LauncherService
extends Object

查詢車(chē)輛的啟動(dòng)器ability和應(yīng)用信息。

你可以使用這個(gè)類(lèi)來(lái)注冊(cè)一個(gè)回調(diào)方法來(lái)觀察bundle狀態(tài)的變化。

嵌套類(lèi)摘要

修飾符和類(lèi)型 類(lèi) 描述
static class LauncherService.BundleStatusCallback 提供在安裝、卸載或更新捆綁包后調(diào)用的回調(diào)方法。

構(gòu)造函數(shù)摘要

構(gòu)造函數(shù) 描述
LauncherService(Context context) 用于創(chuàng)建 LauncherService 實(shí)例的構(gòu)造函數(shù)。

方法總結(jié)

修飾符和類(lèi)型 方法 描述
OptionalLauncherAbilityInfo getAbilityInfo(Intent intent, int userId) 根據(jù)給定 Intent 中指定的 ElementName 和 userId 獲取啟動(dòng)器ability。
OptionalListLauncherAbilityInfo getAbilityList(String bundleName, int userId) 根據(jù)包含 Intent.ACTION_HOME 和 Intent.ENTITY_HOME 的 Intent 獲取啟動(dòng)器ability。
OptionalApplicationInfo getApplicationInfo(String bundleName, int flags, int userId) 根據(jù)給定的包名稱(chēng)、標(biāo)志和用戶 ID 獲取有關(guān)應(yīng)用程序的信息。
OptionalListLauncherShortcutInfo getShortcutInfos(String bundleName) 獲取有關(guān)應(yīng)用程序快捷方式的信息。
boolean isAbilityEnabled(AbilityInfo abilityInfo) 檢查ability是否存在并啟用。
boolean isBundleEnabled(String bundleName) 檢查捆綁包是否存在并已啟用。
void registerCallback(LauncherService.BundleStatusCallback callback) 注冊(cè)一個(gè)回調(diào)方法,用于監(jiān)控包安裝、卸載和更新事件。
void startShortcut(String shortcutId, String bundleName) 根據(jù)給定的快捷方式 ID 和包名稱(chēng)啟動(dòng)快捷方式。
void unRegisterCallback() 取消注冊(cè)用于監(jiān)視捆綁安裝、卸載和更新事件的回調(diào)方法。
從類(lèi) java.lang.Object 繼承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

構(gòu)造函數(shù)詳細(xì)信息

LauncherService

public LauncherService(Context context)

用于創(chuàng)建 LauncherService 實(shí)例的構(gòu)造函數(shù)。

您可以使用此實(shí)例注冊(cè)回調(diào)方法以監(jiān)視捆綁包安裝、卸載和更新事件。

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
context 表示當(dāng)前ability的上下文對(duì)象。

方法詳情

registerCallback

public void registerCallback(LauncherService.BundleStatusCallback callback)

注冊(cè)一個(gè)回調(diào)方法,用于監(jiān)控包安裝、卸載和更新事件。

要使用此方法,您需要向系統(tǒng)請(qǐng)求 ohos.permission.LISTEN_BUNDLE_CHANGE 權(quán)限。 ohos.permission.LISTEN_BUNDLE_CHANGE 權(quán)限屬于簽名|特權(quán)級(jí)別。

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
callback 表示要調(diào)用的回調(diào)方法。

unRegisterCallback

public void unRegisterCallback()

取消注冊(cè)用于監(jiān)視捆綁安裝、卸載和更新事件的回調(diào)方法。

getAbilityList

public OptionalListLauncherAbilityInfo getAbilityList(String bundleName, int userId)

根據(jù)包含 Intent.ACTION_HOME 和 Intent.ENTITY_HOME 的 Intent 獲取啟動(dòng)器ability。

如果指定了包名稱(chēng),則返回有關(guān)與指定包匹配的啟動(dòng)器ability的信息。 否則,將返回有關(guān)與 Intent 匹配的所有啟動(dòng)器ability的信息。

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
bundleName 指示捆綁包名稱(chēng)。
userId 表示用戶標(biāo)識(shí)。

返回:

返回 LauncherAbilityInfo 對(duì)象的列表。

getAbilityInfo

public OptionalLauncherAbilityInfo getAbilityInfo(Intent intent, int userId)

根據(jù)給定 Intent 中指定的 ElementName 和 userId 獲取啟動(dòng)器ability。

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
intent 指示包含要查詢的應(yīng)用程序包名稱(chēng)的 Intent。
userId 表示用戶標(biāo)識(shí)。

返回:

返回一個(gè) LauncherAbilityInfo 對(duì)象。

getApplicationInfo

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

根據(jù)給定的包名稱(chēng)、標(biāo)志和用戶 ID 獲取有關(guān)應(yīng)用程序的信息。

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
bundleName 表示要查詢的bundle名稱(chēng)。
flags 指示用于指定將返回的 ApplicationInfo 對(duì)象中包含的信息的標(biāo)志。
userId 表示用戶標(biāo)識(shí)。

返回:

返回一個(gè) ApplicationInfo 對(duì)象。

isBundleEnabled

public boolean isBundleEnabled(String bundleName)

檢查捆綁包是否存在并已啟用。

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
bundleName 指示捆綁包名稱(chēng)。

返回:

如果啟用了捆綁包,則返回 true; 否則返回 false。

isAbilityEnabled

public boolean isAbilityEnabled(AbilityInfo abilityInfo)

檢查ability是否存在并啟用。

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
abilityInfo 表示有關(guān)檢查ability的信息。

返回:

如果該ability存在且已啟用,則返回 true; 否則返回 false。

getShortcutInfos

public OptionalListLauncherShortcutInfo getShortcutInfos(String bundleName)

獲取有關(guān)應(yīng)用程序快捷方式的信息。

要使用此方法,您需要向系統(tǒng)請(qǐng)求 ohos.permission.MANAGE_SHORTCUTS 權(quán)限。 ohos.permission.MANAGE_SHORTCUTS 權(quán)限屬于簽名級(jí)別。

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
bundleName 指示應(yīng)用程序的捆綁包名稱(chēng)。

返回:

返回包含有關(guān)應(yīng)用程序的快捷方式信息的 LauncherShortcutInfo 對(duì)象列表。

startShortcut

public void startShortcut(String shortcutId, String bundleName)

根據(jù)給定的快捷方式 ID 和包名稱(chēng)啟動(dòng)快捷方式。

要使用此方法,您需要向系統(tǒng)請(qǐng)求 ohos.permission.MANAGE_SHORTCUTS 權(quán)限。 ohos.permission.MANAGE_SHORTCUTS 權(quán)限屬于簽名級(jí)別。

參數(shù):

參數(shù)名稱(chēng) 參數(shù)描述
shortcutId 指示要啟動(dòng)的快捷方式的 ID。
bundleName BundleName 表示快捷方式所屬的應(yīng)用程序的包名。
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)