ITPub博客

首页 > 架构设计 > 操作系统 > 【FAQ】HarmonyOS SDK 闭源开放能力 — 公共模块

【FAQ】HarmonyOS SDK 闭源开放能力 — 公共模块

原创 操作系统 作者:HarmonyOS SDK 时间:2024-11-28 09:55:31 0 删除 编辑

1.问题描述:

文档哪里能找到所有的权限查看该权限是用户级的还是系统级的。

解决方案:

您好,可以看一下下方链接是否可以解决问题:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/permissions-for-all-V5

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/permissions-in-acl-V5

2.问题描述:

查阅文档发现isApplicationEnabled方法已被弃用,目前如何判断手机中某个应用是否已安装?

解决方案:

应用是否已安装?

目前判断应用是否在手机安装,在API 12之前并不支持。

在API 12之后,bundleManager支持canOpenLink接口,通过配置module.json5的querySchemes属性,在代码中可以通过一下代码确定对应应用是否安装:

参考链接: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-bundlemanager-V5#ZH-CN_TOPIC_0000001893370881__bundlemanagercanopenlink12

3.问题描述:

如何在代码中获取oh-package.json5中的信息,比如版本(version)或者描述(description)?

解决方案:

可以通过hvigor脚本实现。

hvigor自定义任务指导: https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V2/custom-hvigor-0000001650987753-V2

hvigor命令行指导: https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V2/ide-command-line-hvigor-0000001553317645-V2

Demo: 这里展示在har module的hvigorfile.ts文件下,编写脚本代码,实现: 1.获取并解析oh-package.json5中的内容 2.获取har产物的路径 3.修改har产物的名称

import { harTasks } from '@ohos/hvigor-ohos-plugin';
import fs from 'fs'
interface OhPackage {
    name: string;
    version: number;
    description: string;
    author: string;
}
export function renameHarTask(str?: string) {
    return {
        pluginId: 'RenameHarTaskID',
        apply(pluginContext) {
            pluginContext.registerTask({
                // 编写自定义任务
                name: 'renameHarTask',
                run: (taskContext) => {
                    //读取oh-package.json5,解析出version
                    const packageFile = taskContext.modulePath+'\oh-package.json5';
                    console.log('file: ', packageFile);
                    let fileContent = fs.readFileSync(packageFile, 'utf8');
                    console.log(fileContent);
                    const content: OhPackage = JSON.parse(fileContent);
                    const version = content.version;
                    const author = content.author;
                console.log('renameHarTask: ', taskContext.moduleName, taskContext.modulePath);
                const sourceFile = taskContext.modulePath + '\\build\\default\\outputs\\default\\' + taskContext.moduleName + '.har';
                const targetFile = taskContext.modulePath + '\\build\\default\\outputs\\default\\'
                    + taskContext.moduleName + '-' + version + '-' + author +'.har';
                console.log('renameHarTask: sourceFile: ', sourceFile);
                console.log('renameHarTask: targetFile: ', targetFile);
                // 修改产物名
                fs.rename(sourceFile, targetFile, (err)=> {
                    console.log('err: ' + err);
                });
            },
            // 确认自定义任务插入位置
            dependencies: ['default@PackageHar'],
            postDependencies: ['assembleHar']
        })
    }
}
}
export default {
    system: harTasks,
    plugins:[renameHarTask()]
}

实现效果 在Terminal窗口执行: ./hvigorw renameHarTask 查看build/default/outputs/default/下的har,可以看到,生成的har已经修改为了我们代码中指定的taskContext.moduleName + '-' + version + '-' + author +'.har'

4.问题描述:

编译报错:The default system capabilities of devices phone, tablet, 2in1 do not include SystemCapability.Communication.NFC.Tag. Configure the capabilities in syscap.json.

解决方案:

报错提示是:不包括SystemCapability.Communication.NFC.Tag,需要syscap.json中配置。

可参考链接: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/syscap-V5#ZH-CN_TOPIC_0000001904100062__pcid导入


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70003787/viewspace-3051423/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
HarmonyOS SDK技术团队。分享最新的技术干货,带来最全的能力应用场景,更新热门开发者圈子活动。与开发者一起,同成长,共精彩。

注册时间:2021-07-15

  • 博文量
    627
  • 访问量
    729888