在uni-app鸿蒙next中写检测是否安装高德地图的uts插件时遇到错误

在uni-app鸿蒙next中写检测是否安装高德地图的uts插件时遇到错误

示例代码:

export async function isGaodeMapInstalled(): Promise<boolean> {
    let exist: boolean = false;
    try {
        let link: string = 'amapuri://com.amap.hmapp/open';
        let data: boolean = bundleManager.canOpenLink(link);
        console.log(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(data));
        exist = data;
    } catch (err) {
        let message = (err as BusinessError).message;
        console.log(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message);
        exist = false;
    }
    return exist;
}

操作步骤:

制作uts插件时,调用isGaodeMapInstalled这个函数

预期结果:

安装了高德地图就返回true,反之返回false

实际结果:

报错[number] 0 testTag canOpenLink failed: %{public}s BusinessError 17700056: The scheme of the specified link is not in the querySchemes.

bug描述:

问题:bundleManager.canOpenLink(link),高德官方提供的此写法,本人在原生中也可以实现,但是在uniapp中制作插件时遇到了错误。

报错信息:

[number] 0 testTag canOpenLink failed: %{public}s BusinessError 17700056: The scheme of the specified link is not in the querySchemes.

此报错指出未在module.json5中添加"querySchemes": [“amapuri”],但是我已经加了。

项目 信息
产品分类 uniapp/App
PC开发环境操作系统 Windows
PC开发环境操作系统版本号 Windows 11 家庭中文版 23H2
HBuilderX类型 正式
HBuilderX版本号 4.64
手机系统 HarmonyOS NEXT
手机系统版本号 HarmonyOS NEXT Developer Beta2
手机厂商 华为
手机机型 nova 13
页面类型 vue
vue版本 vue3
打包方式 云端
项目创建方式 HBuilderX

更多关于在uni-app鸿蒙next中写检测是否安装高德地图的uts插件时遇到错误的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

如之前沟通,你测试下我给的工程和你的做对比,找一下差异。也核对相关文档看是否有区别。使用canOpenLink判断应用是否可访问

更多关于在uni-app鸿蒙next中写检测是否安装高德地图的uts插件时遇到错误的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


感谢大佬,问题已解决。

需要在项目下的harmony-configs/entry/src/main/module.json5文件里加上"querySchemes": [“amapuri”],清除缓存重新运行

这个错误是因为鸿蒙系统需要显式声明应用支持的scheme。在uni-app的uts插件中,除了在module.json5中添加querySchemes外,还需要在应用的manifest.json中进行配置。

解决方案:

  1. 在uts插件的module.json5中确保已添加:
{
  "abilities": [
    {
      "querySchemes": ["amapuri"]
    }
  ]
}
  1. 在uni-app项目的manifest.json中也需要添加:
"app-plus": {
  "distribute": {
    "android": {
      "schemes": ["amapuri"]
    }
  }
}
  1. 检查高德地图的scheme是否正确,最新版可能是"amapuri://“或者"androidamap://”

  2. 确保在调用canOpenLink前已申请ohos.permission.BUNDLE_ACTIVE_INFO权限

如果问题仍然存在,可以尝试改用以下方式检测:

export function isGaodeMapInstalled(): boolean {
    try {
        const context = getContext() as common.UIAbilityContext;
        const bundleInfo = bundleManager.getBundleInfoForSelf(0);
        const appInfos = bundleManager.getApplicationInfo(bundleInfo.name, 0);
        return appInfos.some(app => app.name === 'com.amap.hmapp');
    } catch(e) {
        return false;
    }
}
回到顶部