bundleManager.canOpenLink 12+
canOpenLink(link: string): boolean
查询给定的链接是否可以打开。指定链接的scheme需要在module.json文件的querySchemes字段下配置。
元服务API: 从API version 12开始,该接口支持在元服务中使用。
系统能力: SystemCapability.BundleManager.BundleFramework.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
link | string | 是 | 表示需要查询的链接。 |
返回值:
类型 | 说明 |
---|---|
boolean | 返回true表示给定的链接可以打开,返回false表示给定的链接不能打开。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
17700055 | The specified link is invalid. |
17700056 | The scheme of the specified link is not in the querySchemes. |
示例:
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
try {
let link = 'welink://';
let data = bundleManager.canOpenLink(link);
hilog.info(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(data));
} catch (err) {
let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message);
}