HarmonyOS 鸿蒙Next Applinking配置后未生效
HarmonyOS 鸿蒙Next Applinking配置后未生效
配置如下
“skills”: [
{
“entities”: [
// entities必须包含"entity.system.browsable"
“entity.system.browsable”,
“entity.system.home”
// “entity.system.browsable”
],
“actions”: [
// actions必须包含"ohos.want.action.viewData"
“ohos.want.action.viewData”,
“action.system.home”
// “ohos.want.action.viewData”
],
// “uris”: [
// {
// “scheme”: “http”,
// “host”: “",
// “port”: "”,
// // prefix matching
// “pathStartWith”: “*”
// }
// ]
“domainVerify”: true
},
{
“uris”: [
{
// scheme须配置为https
“scheme”: “https”,
// host须配置为关联的域名
“host”: “test01-h5.hpplay.com.cn”
},
{
// scheme须配置为https
“scheme”: “https”,
// host须配置为关联的域名
“host”: “h5.hpplay.com.cn”
}
]
}
],
此时调用applinking未生效,怎么样既可以满足applinking,也可以满足startBackgroundRunning不报错
参考长时任务配置:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/continuous-task-V5
将尝试任务的skill和applinking的skill分为2个,applinking的skill不使用entities的home和actions的home选项即可。
鸿蒙比较重视声明式开发,关键在于声明和申请,可以试下:
module.json5配置:
{
"module": {
"skills": [
{
"entities": [
"entity.system.browsable",
"entity.system.home"
],
"actions": [
"ohos.want.action.viewData",
"action.system.home"
],
"uris": [
{
"scheme": "https",
"host": "test01-h5.hpplay.com.cn",
"port": "*",
"pathStartWith": "*"
},
{
"scheme": "https",
"host": "h5.hpplay.com.cn",
"port": "*",
"pathStartWith": "*"
}
],
"domainVerify": true
}
]
}
}
权限配置(app.json5):
{
"permissions": [
{
"name": "ohos.permission.KEEP_BACKGROUND_RUNNING",
"reason": "需要后台运行权限"
},
{
"name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND",
"reason": "从后台启动能力"
}
]
}
代码中申请后台运行权限:
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import featureAbility from '@ohos.ability.featureAbility';
async function requestBackgroundRunning() {
try {
// 申请后台运行权限
let wantParam = {
bundleName: “your.package.name”,
abilityName: “MainAbility”
};
<span class="hljs-comment"><span class="hljs-comment">// 请求持续后台运行 </span></span>
backgroundTaskManager.startBackgroundRunning(
featureAbility.getContext(),
backgroundTaskManager.BackgroundMode.BACKGROUND_TYPE_DATA_TRANSFER,
wantParam
).then(() => {
console.log(<span class="hljs-string"><span class="hljs-string">'Background running request successful'</span></span>);
}).catch((err) => {
console.error(<span class="hljs-string"><span class="hljs-string">'Background running request failed'</span></span>, err);
});
} catch (error) {
console.error(‘Request background running error’, error);
}
}
完整的AppleLinking处理:
import Want from ‘@ohos.app.ability.Want’;
import AbilityConstant from ‘@ohos.app.ability.AbilityConstant’;
function handleAppleLinking(want: Want) {
// 检查Want的uri和参数
if (want && want.uri) {
// 解析并处理AppleLinking
let uri = want.uri;
let params = want.parameters;
<span class="hljs-comment"><span class="hljs-comment">// 根据uri和参数执行相应逻辑 </span></span>
<span class="hljs-keyword"><span class="hljs-keyword">if</span></span> (uri.startsWith(<span class="hljs-string"><span class="hljs-string">'https://test01-h5.hpplay.com.cn'</span></span>) ||
uri.startsWith(<span class="hljs-string"><span class="hljs-string">'https://h5.hpplay.com.cn'</span></span>)) {
<span class="hljs-comment"><span class="hljs-comment">// 处理AppleLinking跳转逻辑 </span></span>
console.log(<span class="hljs-string"><span class="hljs-string">'AppleLinking received'</span></span>, uri);
}
}
}
有帮助的话点个关注哈
针对HarmonyOS 鸿蒙Next AppLinking配置后未生效的问题,以下是一些可能的解决方案:
- 检查配置信息:确保在AppGallery Connect中正确配置了AppLinking,包括Url前缀、深层链接等。同时,检查应用的module.json5配置文件中是否已正确声明应用关联的域名地址,并开启了域名校验开关。
- 验证域名配置:确认在开发者的网站上已正确创建了applinking.json文件,并将其放置在域名服务器的固定目录下。该文件应包含正确的应用标识符等信息。
- 代码实现:在应用的Ability中添加处理传入链接的代码,确保能够正确解析并响应AppLinking链接。
- 重启与测试:重启DevEco Studio和HarmonyOS设备,确保所有配置已生效。然后进行测试,验证AppLinking功能是否正常工作。
如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html 。