harmony 鸿蒙@ohos.bundle.launcherBundleManager (launcherBundleManager模块)
@ohos.bundle.launcherBundleManager (launcherBundleManager模块)
本模块支持launcher应用所需的查询能力,支持LauncherAbilityInfo、ShortcutInfo信息的查询。
说明:
本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
导入模块
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
launcherBundlemanager.getLauncherAbilityInfo9+
getLauncherAbilityInfo(bundleName: string, userId: number, callback: AsyncCallback
查询指定bundleName及用户的LauncherAbilityInfo。
需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
系统接口: 此接口为系统接口
系统能力: SystemCapability.BundleManager.BundleFramework.Launcher
参数:
| 参数名 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| bundleName | string | 是 | 应用Bundle名称。 | 
| userId | number | 是 | 被查询的用户id。 | 
返回值:
| 类型 | 说明 | 
|---|---|
| AsyncCallback<Array<LauncherAbilityInfo>> | callback形式返回bundle包含的LauncherAbilityInfo信息。 | 
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
| 错误码ID | 错误信息 | 
|---|---|
| 17700001 | The specified bundle name is not found. | 
| 17700004 | The specified user ID is not found. | 
示例:
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
import { BusinessError } from '@ohos.base';
try {
    launcherBundleManager.getLauncherAbilityInfo('com.example.demo', 100,
        (errData: BusinessError, data: launcherBundleManager.LauncherAbilityInfo[]) => {
        if (errData !== null) {
            console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
        } else {
            console.log("data is " + JSON.stringify(data));
        }
    })
} catch (errData) {
    let code = (errData as BusinessError).code;
    let message = (errData as BusinessError).message;
    console.error(`errData is errCode:${code}  message:${message}`);
}
launcherBundlemanager.getLauncherAbilityInfo9+
getLauncherAbilityInfo(bundleName: string, userId: number) : Promise
查询指定bundleName及用户的LauncherAbilityInfo。
需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
系统接口: 此接口为系统接口
系统能力: SystemCapability.BundleManager.BundleFramework.Launcher
参数:
| 参数名 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| bundleName | string | 是 | 应用Bundle名称。 | 
| userId | number | 是 | 被查询的用户id。 | 
返回值:
| 类型 | 说明 | 
|---|---|
| Promise<Array<LauncherAbilityInfo>> | Promise形式返回bundle包含的LauncherAbilityInfo信息。 | 
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
| 错误码ID | 错误信息 | 
|---|---|
| 17700001 | The specified bundle name is not found. | 
| 17700004 | The specified user ID is not found. | 
示例:
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
import { BusinessError } from '@ohos.base';
try {
    launcherBundleManager.getLauncherAbilityInfo("com.example.demo", 100)
        .then((data: launcherBundleManager.LauncherAbilityInfo[]) => {
        console.log("data is " + JSON.stringify(data));
    }).catch ((errData: BusinessError) => {
        console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
    })
} catch (errData) {
    let code = (errData as BusinessError).code;
    let message = (errData as BusinessError).message;
    console.error(`errData is errCode:${code}  message:${message}`);
}
launcherBundlemanager.getLauncherAbilityInfoSync10+
getLauncherAbilityInfoSync(bundleName: string, userId: number) : Array<LauncherAbilityInfo>;
查询指定bundleName及用户的LauncherAbilityInfo。
需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
系统接口: 此接口为系统接口
系统能力: SystemCapability.BundleManager.BundleFramework.Launcher
参数:
| 参数名 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| bundleName | string | 是 | 应用Bundle名称。 | 
| userId | number | 是 | 被查询的用户id。 | 
返回值:
| 类型 | 说明 | 
|---|---|
| Array<LauncherAbilityInfo> | Array形式返回bundle包含的LauncherAbilityInfo信息。 | 
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
| 错误码ID | 错误信息 | 
|---|---|
| 17700001 | The specified bundle name is not found. | 
| 17700004 | The specified user ID is not found. | 
示例:
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
import { BusinessError } from '@ohos.base';
try {
    let data = launcherBundleManager.getLauncherAbilityInfoSync("com.example.demo", 100);
    console.log("data is " + JSON.stringify(data));
} catch (errData) {
    let code = (errData as BusinessError).code;
    let message = (errData as BusinessError).message;
    console.error(`errData is errCode:${code}  message:${message}`);
}
launcherBundlemanager.getAllLauncherAbilityInfo9+
getAllLauncherAbilityInfo(userId: number, callback: AsyncCallback
查询指定用户下所有应用的LauncherAbilityInfo
需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
系统接口: 此接口为系统接口
系统能力: SystemCapability.BundleManager.BundleFramework.Launcher
参数:
| 参数名 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| userId | number | 是 | 被查询的用户id。 | 
返回值:
| 类型 | 说明 | 
|---|---|
| AsyncCallback<Array<LauncherAbilityInfo>> | callback形式返回指定用户下所有应用的LauncherAbilityInfo。 | 
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
| 错误码ID | 错误信息 | 
|---|---|
| 17700004 | The specified user ID is not found. | 
示例:
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
import { BusinessError } from '@ohos.base';
try {
    launcherBundleManager.getAllLauncherAbilityInfo(100,
        (errData: BusinessError, data: launcherBundleManager.LauncherAbilityInfo[]) => {
        if (errData !== null) {
            console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
        } else {
            console.log("data is " + JSON.stringify(data));
        }
    });
} catch (errData) {
    let code = (errData as BusinessError).code;
    let message = (errData as BusinessError).message;
    console.error(`errData is errCode:${code}  message:${message}`);
}
launcherBundlemanager.getAllLauncherAbilityInfo9+
getAllLauncherAbilityInfo(userId: number) : Promise
查询指定用户下所有应用的LauncherAbilityInfo
需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
系统接口: 此接口为系统接口
系统能力: SystemCapability.BundleManager.BundleFramework.Launcher
参数:
| 参数名 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| userId | number | 是 | 被查询的用户id。 | 
返回值:
| 类型 | 说明 | 
|---|---|
| Promise<Array<LauncherAbilityInfo>> | Promise形式返回指定用户下所有应用的LauncherAbilityInfo。 | 
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
| 错误码ID | 错误信息 | 
|---|---|
| 17700004 | The specified user ID is not found. | 
示例:
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
import { BusinessError } from '@ohos.base';
try {
    launcherBundleManager.getAllLauncherAbilityInfo(100)
        .then((data: launcherBundleManager.LauncherAbilityInfo[]) => {
        console.log("data is " + JSON.stringify(data));
    }).catch ((errData: BusinessError) => {
        console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
    });
} catch (errData) {
    let code = (errData as BusinessError).code;
    let message = (errData as BusinessError).message;
    console.error(`errData is errCode:${code}  message:${message}`);
}
launcherBundlemanager.getShortcutInfo9+
getShortcutInfo(bundleName :string, callback: AsyncCallback
查询当前用户下指定应用的ShortcutInfo。
需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
系统接口: 此接口为系统接口
系统能力: SystemCapability.BundleManager.BundleFramework.Launcher
| 参数名 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| bundleName | string | 是 | 应用Bundle名称。 | 
返回值:
| 类型 | 说明 | 
|---|---|
| AsyncCallback<Array<ShortcutInfo>> | callback形式返回当前用户下指定应用的ShortcutInfo。 | 
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
| 错误码ID | 错误信息 | 
|---|---|
| 17700001 | The specified bundle name is not found. | 
示例:
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
import { BusinessError } from '@ohos.base';
try {
    launcherBundleManager.getShortcutInfo("com.example.demo",
        (errData: BusinessError, data: launcherBundleManager.ShortcutInfo[]) => {
        if (errData !== null) {
            console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
        } else {
            console.log("data is " + JSON.stringify(data));
        }
    });
} catch (errData) {
    let code = (errData as BusinessError).code;
    let message = (errData as BusinessError).message;
    console.error(`errData is errCode:${code}  message:${message}`);
}
launcherBundlemanager.getShortcutInfo9+
getShortcutInfo(bundleName : string) : Promise
查询当前用户下指定应用的ShortcutInfo。
需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
系统接口: 此接口为系统接口
系统能力: SystemCapability.BundleManager.BundleFramework.Launcher
| 参数名 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| bundleName | string | 是 | 应用Bundle名称。 | 
返回值:
| 类型 | 说明 | 
|---|---|
| Promise<Array<ShortcutInfo>> | Promise形式返回当前用户下指定应用的ShortcutInfo。 | 
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
| 错误码ID | 错误信息 | 
|---|---|
| 17700001 | The specified bundle name is not found. | 
示例:
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
import { BusinessError } from '@ohos.base';
try {
    launcherBundleManager.getShortcutInfo("com.example.demo")
        .then((data: launcherBundleManager.ShortcutInfo[]) => {
        console.log("data is " + JSON.stringify(data));
    }).catch ((errData: BusinessError) => {
        console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
    });
} catch (errData) {
    let code = (errData as BusinessError).code;
    let message = (errData as BusinessError).message;
    console.error(`errData is errCode:${code}  message:${message}`);
}
launcherBundlemanager.getShortcutInfoSync10+
getShortcutInfoSync(bundleName : string) : Array<ShortcutInfo>;
查询当前用户下指定应用的ShortcutInfo。
需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
系统接口: 此接口为系统接口
系统能力: SystemCapability.BundleManager.BundleFramework.Launcher
| 参数名 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| bundleName | string | 是 | 应用Bundle名称。 | 
返回值:
| 类型 | 说明 | 
|---|---|
| Array<ShortcutInfo> | Array形式返回当前用户下指定应用的ShortcutInfo。 | 
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
| 错误码ID | 错误信息 | 
|---|---|
| 17700001 | The specified bundle name is not found. | 
示例:
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
import { BusinessError } from '@ohos.base';
try {
    let data = launcherBundleManager.getShortcutInfoSync("com.example.demo");
    console.log("data is " + JSON.stringify(data));
} catch (errData) {
    let code = (errData as BusinessError).code;
    let message = (errData as BusinessError).message;
    console.error(`errData is errCode:${code}  message:${message}`);
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙BundleStatusCallback
harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager模块)
harmony 鸿蒙@ohos.distributedBundle (分布式包管理)
harmony 鸿蒙@ohos.bundle (Bundle模块)
harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (企业设备管理扩展能力)
- 所属分类: 后端技术
- 本文标签:
热门推荐
- 
                        2、 - 优质文章
- 
                        3、 gate.io
- 
                        8、 openharmony
- 
                        9、 golang