harmony 鸿蒙@ohos.bundle.launcherBundleManager (launcherBundleManager)

  • 2022-12-05
  • 浏览 (650)

@ohos.bundle.launcherBundleManager (launcherBundleManager)

The bundle.launcherBundleManager module providers APIs for the Home Screen application to obtain the launcher ability information and shortcut information.

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

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

launcherBundlemanager.getLauncherAbilityInfo9+

getLauncherAbilityInfo(bundleName: string, userId: number, callback: AsyncCallback>) : void;

Obtains the launcher ability information based on the given bundle name and user ID. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Launcher

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
userId number Yes User ID.

Return value

Type Description
AsyncCallback<Array<LauncherAbilityInfo>> Callback used to return the LauncherAbilityInfo object obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundle name is not found.
17700004 The specified user ID is not found.

Example

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>;

Obtains the launcher ability information based on the given bundle name and user ID. This API uses a promise to return the result.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Launcher

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
userId number Yes User ID.

Return value

Type Description
Promise<Array<LauncherAbilityInfo>> Promise used to return the LauncherAbilityInfo object obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundle name is not found.
17700004 The specified user ID is not found.

Example

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>;

Obtains the launcher ability information based on the given bundle name and user ID.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Launcher

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
userId number Yes User ID.

Return value

Type Description
Array<LauncherAbilityInfo> Array of the LauncherAbilityInfo objects obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundle name is not found.
17700004 The specified user ID is not found.

Example

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>) : void;

Obtains the launcher ability information of all applications based on the given user ID. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Launcher

Parameters

Name Type Mandatory Description
userId number Yes User ID.

Return value

Type Description
AsyncCallback<Array<LauncherAbilityInfo>> Callback used to return the array of LauncherAbilityInfo objects obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700004 The specified user ID is not found.

Example

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>;

Obtains the launcher ability information of all applications based on the given user ID. This API uses a promise to return the result.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Launcher

Parameters

Name Type Mandatory Description
userId number Yes User ID.

Return value

Type Description
Promise<Array<LauncherAbilityInfo>> Promise used to return the array of LauncherAbilityInfo objects obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700004 The specified user ID is not found.

Example

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>) : void;

Obtains the shortcut information of the current user based on the given bundle name. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Launcher

Name Type Mandatory Description
bundleName string Yes Bundle name.

Return value

Type Description
AsyncCallback<Array<ShortcutInfo>> Callback used to return the ShortcutInfo object obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundle name is not found.

Example

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>;

Obtains the shortcut information of the current user based on the given bundle name. This API uses a promise to return the result.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Launcher

Name Type Mandatory Description
bundleName string Yes Bundle name.

Return value

Type Description
Promise<Array<ShortcutInfo>> Promise used to return the ShortcutInfo object obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundle name is not found.

Example

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>;

Obtains the shortcut information of the current user based on the given bundle name.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Launcher

Name Type Mandatory Description
bundleName string Yes Bundle name.

Return value

Type Description
Array<ShortcutInfo> Array of the ShortcutInfo objects obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundle name is not found.

Example

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 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞