harmony 鸿蒙@ohos.bundle.launcherBundleManager (launcherBundleManager模块)(系统接口)

  • 2025-06-12
  • 浏览 (4)

@ohos.bundle.launcherBundleManager (launcherBundleManager模块)(系统接口)

本模块支持launcher应用所需的查询能力,支持LauncherAbilityInfoShortcutInfo信息的查询。

说明:

本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

本模块为系统接口。

导入模块

import launcherBundleManager from '@ohos.bundle.launcherBundleManager';

launcherBundleManager.getLauncherAbilityInfo9+

getLauncherAbilityInfo(bundleName: string, userId: number, callback: AsyncCallback<Array<LauncherAbilityInfo>>) : void

查询指定bundleName及用户的LauncherAbilityInfo

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Launcher

参数:

参数名 类型 必填 说明
bundleName string 应用Bundle名称。
userId number 被查询的用户ID,可以通过getOsAccountLocalId接口获取。
callback AsyncCallback<Array<LauncherAbilityInfo>> callback形式返回bundle包含的LauncherAbilityInfo信息。

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID 错误信息
201 Verify permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not support.
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<Array<LauncherAbilityInfo>>

查询指定bundleName及用户的LauncherAbilityInfo

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Launcher

参数:

参数名 类型 必填 说明
bundleName string 应用Bundle名称。
userId number 被查询的用户ID,可以通过getOsAccountLocalId接口获取。

返回值:

类型 说明
Promise<Array<LauncherAbilityInfo>> Promise形式返回bundle包含的LauncherAbilityInfo信息。

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID 错误信息
201 Verify permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not support.
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.getAllLauncherAbilityInfo9+

getAllLauncherAbilityInfo(userId: number, callback: AsyncCallback<Array<LauncherAbilityInfo>>) : void

查询指定用户下所有应用的LauncherAbilityInfo

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Launcher

参数:

参数名 类型 必填 说明
userId number 被查询的用户ID,可以通过getOsAccountLocalId接口获取。
callback AsyncCallback<Array<LauncherAbilityInfo>> callback形式返回指定用户下所有应用的LauncherAbilityInfo

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID 错误信息
201 Verify permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not support.
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<Array<LauncherAbilityInfo>>

查询指定用户下所有应用的LauncherAbilityInfo

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Launcher

参数:

参数名 类型 必填 说明
userId number 被查询的用户ID,可以通过getOsAccountLocalId接口获取。

返回值:

类型 说明
Promise<Array<LauncherAbilityInfo>> Promise形式返回指定用户下所有应用的LauncherAbilityInfo

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID 错误信息
201 Verify permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not support.
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<Array<ShortcutInfo>>) : void

查询当前用户下指定应用的ShortcutInfo

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Launcher

参数:

参数名 类型 必填 说明
bundleName string 应用Bundle名称。
callback AsyncCallback<Array<ShortcutInfo>> callback形式返回当前用户下指定应用的ShortcutInfo

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID 错误信息
201 Verify permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not support.
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<Array<ShortcutInfo>>

查询当前用户下指定应用的ShortcutInfo

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Launcher

参数:

参数名 类型 必填 说明
bundleName string 应用Bundle名称。

返回值:

类型 说明
Promise<Array<ShortcutInfo>> Promise形式返回当前用户下指定应用的ShortcutInfo

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID 错误信息
201 Verify permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not support.
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 错误信息
201 Verify permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not support.
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}`);
}

launcherBundleManager.getShortcutInfoSync13+

getShortcutInfoSync(bundleName: string, userId: number) : Array<ShortcutInfo>

查询指定用户下指定应用的ShortcutInfo

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Launcher

参数:

参数名 类型 必填 说明
bundleName string 应用Bundle名称。
userId number 表示用户ID,可以通过getOsAccountLocalId接口获取。

返回值:

类型 说明
Array<ShortcutInfo> Array形式返回指定用户下指定应用的ShortcutInfo

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID 错误信息
201 Verify permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not support.
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.getShortcutInfoSync("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.startShortcut12+

startShortcut(shortcutInfo: ShortcutInfo, options?: StartOptions): Promise<void>;

拉起指定ShortcutInfo中的ability。

需要权限: ohos.permission.START_SHORTCUT

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Launcher

参数:

参数名 类型 必填 说明
shortcutInfo ShortcutInfo 应用的快捷方式信息。
options StartOptions 启动参数选项,用于指定任务切到前台时的窗口模式,设备ID等。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID 错误信息
201 Verify permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not support.
17700065 The ability specified by want in the ShortcutInfo struct cannot be started.

示例:

import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
import { BusinessError } from '@ohos.base';

try {
    let data : Array<launcherBundleManager.ShortcutInfo> = launcherBundleManager.getShortcutInfoSync("com.example.demo");
    console.log("data is " + JSON.stringify(data));
    if (data) {
        try {
            launcherBundleManager.startShortcut(data[0])
                .then(() => {
                console.log("startShortcut success");
            }).catch ((err: BusinessError) => {
                console.error(`errData is errCode:${err.code}  message:${err.message}`);
            });
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`error is errCode:${code}  message:${message}`);
        }
    }
} catch (errData) {
    let code = (errData as BusinessError).code;
    let message = (errData as BusinessError).message;
    console.error(`errData is errCode:${code}  message:${message}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit(程序框架服务)

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_base_common.h

harmony 鸿蒙ability_runtime_common.h

harmony 鸿蒙application_context.h

0  赞